Skip to content

Commit d812402

Browse files
author
DavertMik
committed
fixed webdriver
1 parent 720ec42 commit d812402

File tree

8 files changed

+90
-42
lines changed

8 files changed

+90
-42
lines changed

.github/workflows/webdriver.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
node-version: [20.x]
2323

2424
steps:
25-
- run: docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome:4.27
25+
- run: docker run --net=host -d --shm-size=2g selenium/standalone-chrome:4.27
2626
- uses: actions/checkout@v4
2727
- name: Use Node.js ${{ matrix.node-version }}
2828
uses: actions/setup-node@v4

Dockerfile

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Download Playwright and its dependencies
2-
FROM mcr.microsoft.com/playwright:v1.48.1-noble
3-
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
2+
FROM mcr.microsoft.com/playwright:v1.55.0-noble
43

54
RUN apt-get update --allow-releaseinfo-change
65

@@ -19,29 +18,14 @@ RUN apt-get update && apt-get install -y gnupg wget && \
1918
apt-get install -y google-chrome-stable --no-install-recommends && \
2019
rm -rf /var/lib/apt/lists/*
2120

22-
23-
# Add pptr user.
24-
RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
25-
&& mkdir -p /home/pptruser/Downloads \
26-
&& chown -R pptruser:pptruser /home/pptruser \
27-
&& chown -R pptruser:pptruser /home/pptruser
28-
29-
#RUN mkdir /home/codecept
30-
3121
COPY . /codecept
32-
33-
RUN chown -R pptruser:pptruser /codecept
34-
RUN runuser -l pptruser -c 'npm i --loglevel=warn --prefix /codecept'
22+
WORKDIR /codecept
23+
RUN npm install
3524

3625
RUN ln -s /codecept/bin/codecept.js /usr/local/bin/codeceptjs
3726
RUN mkdir /tests
3827
WORKDIR /tests
39-
# Install puppeteer so it's available in the container.
40-
RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
41-
RUN google-chrome --version
42-
43-
# Install playwright browsers
44-
RUN npx playwright install
28+
RUN npm init -y && npm pkg set type=module
4529

4630
# Allow to pass argument to codecept run via env variable
4731
ENV CODECEPT_ARGS=""
@@ -50,9 +34,7 @@ ENV NO_OF_WORKERS=""
5034

5135
# Set HOST ENV variable for Selenium Server
5236
ENV HOST=selenium
53-
54-
# Run user as non privileged.
55-
# USER pptruser
37+
ENV CODECEPT_DOCKER=1
5638

5739
# Set the entrypoint
5840
ENTRYPOINT ["/codecept/docker/entrypoint"]

docker/entrypoint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
# Set up module resolution - NODE_PATH is all we need
5+
export NODE_PATH=/codecept/lib:$NODE_PATH
6+
47
xvfb-run -a --server-args="-screen 0 1024x768x24" "$@"

docker/run.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,74 @@ source /codecept/docker/help.sh
66
if [[ -d "/tests/" ]]; then
77
echo "CodeceptJS directory has been found."
88

9+
# Set up module resolution
10+
export NODE_PATH=/codecept/lib:$NODE_PATH
11+
12+
# Ensure ESM package.json exists in test directory
13+
ensure_esm_package() {
14+
local dir="$1"
15+
if [ ! -f "$dir/package.json" ]; then
16+
echo "Creating package.json with ESM in $dir"
17+
cat > "$dir/package.json" << EOF
18+
{
19+
"type": "module"
20+
}
21+
EOF
22+
elif ! grep -q '"type".*"module"' "$dir/package.json"; then
23+
echo "Warning: $dir/package.json exists but may not have type: module"
24+
fi
25+
}
26+
27+
# Setup node_modules with ESM-compatible codeceptjs
28+
setup_node_modules() {
29+
local dir="$1"
30+
local node_modules="$dir/node_modules"
31+
local codecept_module="$node_modules/codeceptjs"
32+
33+
mkdir -p "$codecept_module"
34+
35+
cat > "$codecept_module/package.json" << 'EOF'
36+
{
37+
"name": "codeceptjs",
38+
"type": "module",
39+
"exports": {
40+
".": "./index.js",
41+
"./effects": "./effects.js"
42+
},
43+
"main": "./index.js"
44+
}
45+
EOF
46+
47+
ln -sf /codecept/lib/index.js "$codecept_module/index.js"
48+
ln -sf /codecept/lib/effects.js "$codecept_module/effects.js"
49+
50+
for dep_dir in /codecept/node_modules/*; do
51+
dep_name=$(basename "$dep_dir")
52+
if [ "$dep_name" != "codeceptjs" ] && [ ! -e "$node_modules/$dep_name" ]; then
53+
ln -sf "$dep_dir" "$node_modules/$dep_name" 2>/dev/null || true
54+
fi
55+
done
56+
}
57+
58+
# Find codecept config in current directory
59+
config_file=$(find . -maxdepth 2 -name "codecept.conf.*" -type f | head -1)
60+
61+
if [ -n "$config_file" ]; then
62+
config_dir=$(dirname "$config_file")
63+
ensure_esm_package "$config_dir"
64+
setup_node_modules "$config_dir"
65+
else
66+
ensure_esm_package "$(pwd)"
67+
setup_node_modules "$(pwd)"
68+
fi
69+
70+
# Also setup node_modules in any subdirectories that might contain test files
71+
for test_dir in acceptance test tests; do
72+
if [ -d "$test_dir" ]; then
73+
setup_node_modules "$test_dir"
74+
fi
75+
done
76+
977
# Run the tests
1078
cd /tests/ || exit
1179
if [ "$RUN_MULTIPLE" = true ]; then

lib/command/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default async function (path, options) {
2121

2222
try {
2323
await codecept.bootstrap()
24+
await Container.started()
2425

2526
if (options.verbose) output.level(3)
2627

@@ -53,7 +54,6 @@ export default async function (path, options) {
5354
}
5455
}
5556
pause()
56-
// recorder.catchWithoutStop((err) => console.log(err.stack));
5757
recorder.add(() => event.emit(event.test.after, {}))
5858
recorder.add(() => event.emit(event.suite.after, {}))
5959
recorder.add(() => event.emit(event.all.result, {}))

lib/helper/WebDriver.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { includes as stringIncludes } from '../assert/include.js'
88
import { urlEquals, equals } from '../assert/equal.js'
99
import store from '../store.js'
1010
import output from '../output.js'
11+
const { debug } = output
1112
import { empty } from '../assert/empty.js'
1213
import { truth } from '../assert/truth.js'
1314
import { xpathLocator, fileExists, decodeUrl, chunkArray, convertCssPropertiesToCamelCase, screenshotOutputFolder, getNormalizedKeyAttributeValue, modifierKeys } from '../utils.js'

test/acceptance/session_test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import assert from 'assert'
22
import { devices } from 'playwright'
3-
import { within } from '../../lib/effects.js'
4-
import event from '../../lib/event.js'
3+
4+
import { within } from 'codeceptjs/effects';
5+
import { event } from 'codeceptjs'
56

67
const output_dir = global.output_dir || './output'
78

test/docker-compose.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,36 @@ services:
77
env_file: .env
88
volumes:
99
- ..:/codecept
10-
- node_modules:/codecept/node_modules
1110
command: test/rest
1211
depends_on:
1312
- json_server
1413

1514
test-acceptance.webdriverio:
1615
build: ..
1716
env_file: .env
17+
working_dir: /tests
1818
environment:
19-
- CODECEPT_ARGS=-c codecept.WebDriver.js --grep @WebDriverIO --debug
19+
- CODECEPT_ARGS=-c acceptance/codecept.WebDriver.js --grep @WebDriverIO --debug
20+
- NODE_PATH=/codecept/lib
2021
depends_on:
2122
- php
2223
- selenium.chrome
2324
volumes:
24-
- ./acceptance:/tests
25-
- ./data:/data
26-
- ./support:/support
27-
- node_modules:/node_modules
25+
- .:/tests
2826

2927
test-acceptance.puppeteer:
3028
build: ..
3129
env_file: .env
30+
working_dir: /tests
3231
environment:
33-
- CODECEPT_ARGS=-c codecept.Puppeteer.js --grep @Puppeteer
32+
- CODECEPT_ARGS=-c acceptance/codecept.Puppeteer.js --grep @Puppeteer
3433
- PPT_VERSION=$PPT_VERSION
34+
- NODE_PATH=/codecept/lib
3535
depends_on:
3636
- php
3737
- puppeteer-image
3838
volumes:
39-
- ./acceptance:/tests
40-
- ./data:/data
41-
- ./support:/support
42-
- node_modules:/node_modules
39+
- .:/tests
4340

4441
test-bdd.faker:
4542
build: ..
@@ -50,7 +47,6 @@ services:
5047
- ./bdd:/tests
5148
- ./data:/data
5249
- ./support:/support
53-
- node_modules:/node_modules
5450

5551
selenium.chrome:
5652
image: selenium/standalone-chrome:4.26
@@ -76,6 +72,3 @@ services:
7672

7773
puppeteer-image:
7874
image: ghcr.io/puppeteer/puppeteer:22.4.1
79-
80-
volumes:
81-
node_modules:

0 commit comments

Comments
 (0)