Closed marcinlesek closed 5 years ago
Thank you for your inquiry. As far as I know, TestCafe should work the same way if you start your container from the Jenkins job. Don't try to disable BrowserStack Local, because BrowserStack cloud browsers can't connect to your machine without a tunnel created by BrowserStack Local. Try to add --hostname 127.0.0.1 --ports 9000,9001
to TestCafe parameters. To ensure that this issue is caused by TestCafe, please modify your Jenkins job to run the container from the following repository: https://github.com/AndreyBelym/browserstack-docker-example. It should produce the following build log if your Docker and Jenkins configuration is correct:
> browserstack-docker-example@1.0.0 test /app
> ./test.js
Starting tunnel...
Is Running true
Started
Hello World
Thanks for fast response @AndreyBelym!
Firstly, we modify our Jenkins job to run container you linked, and it's worked correctly. Below is log:
After that, I changed hostname to 127.0.0.1
and TC ports to 9000
and 9001
and below are results:
✅ executed test run on own host machine (MacBook Pro),
✅ executed test run on BrowserStack cloud from own host machine (MacBook Pro),
⛔️ executed test run on BrowserStack cloud from Jenkins job (still),
but! Now connection gone well but http authorization stopped work (my page has basic auth and I'm using .httpAuth(authCredentials)
on fixture
declaration) and get 401 Unauthorized
in browser (from my local machine works for both cases - local and BrowserStack). What was also interesting, when BrowserStack failed and stopped execution, Jenkins still waits for response (for more than 30 minutes, after that I killed it).
So it looks like some trouble now with getting response back and http authorization. Any ideas? 🤔
It seems I forgot to push my changes to the repository. I apologize for the inconvenience, but could you please pull my changes from https://github.com/AndreyBelym/browserstack-docker-example try my example again? The SHA1 checksum of the last commit must be 3688cd7c and the last commit message must be Modify example
.
Hello @AndreyBelym, no problem. I re run job on Jenkins with new changes, and as I check your code and status, it hang out on closing local tunnel. I terminated job after 12 minutes. Below is log:
In this case, it means error is on browserstack
node library? 🤔
Thank you, I see that my example works in your environment with Browserstack Local enabled. Now I've disabled it in my repository. Could you please pull the changes and run my code again?
Hey @AndreyBelym,
I think you forgot to remove local
from https://github.com/AndreyBelym/browserstack-docker-example/blob/master/test.js#L5 and https://github.com/AndreyBelym/browserstack-docker-example/blob/master/test.js#L37 😉
> browserstack-docker-example@1.0.0 test /app
> ./test.js
/app/test.js:5
const local = new browserstack.Local()
^
ReferenceError: browserstack is not defined
at Object.<anonymous> (/app/test.js:5:15)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! Test failed. See above for more details.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
@marcinlesek
Hello,
Yes, you are completely right. @AndreyBelym made your changes. Could you please pull the changes and run the code again?
Hello @Farfurix,
thanks for info and @AndreyBelym for update, now we'd got error from selenium-webdriver
, check it below:
> browserstack-docker-example@1.0.0 test /app
> ./test.js
Starting tunnel...
Started
/app/node_modules/selenium-webdriver/lib/promise.js:2634
throw error;
^
WebDriverError: [browserstack.local] is set to true but local testing through BrowserStack is not connected.
at Object.checkLegacyResponse (/app/node_modules/selenium-webdriver/lib/error.js:517:15)
at parseHttpResponse (/app/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/app/node_modules/selenium-webdriver/lib/http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: WebDriver.createSession()
at Function.createSession (/app/node_modules/selenium-webdriver/lib/webdriver.js:777:24)
at Function.createSession (/app/node_modules/selenium-webdriver/chrome.js:719:29)
at createDriver (/app/node_modules/selenium-webdriver/index.js:167:33)
at Builder.build (/app/node_modules/selenium-webdriver/index.js:623:16)
at Server.http.createServer.listen (/app/test.js:30:123)
at Object.onceWrapper (events.js:286:20)
at Server.emit (events.js:198:13)
at emitListeningNT (net.js:1313:10)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
npm ERR! Test failed. See above for more details.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
@marcinlesek
We set the browserstack.local
option to false
. Please try it again.
Yea @Farfurix , now executed correctly, but still job hangs out. BrowserStack passed successfully, but couldn't load page that our server serves.
After 10 minutes, I terminated Jenkins job:
> browserstack-docker-example@1.0.0 test /app
> ./test.js
Starting tunnel...
Started
127.0.0.1
Stopped
Build was aborted
Aborted by Marcin Lesek
Finished: ABORTED
Any ideas guys - @AndreyBelym @Farfurix @miherlosev? I'm not hiding that it's critical for us and could depend on decision to migrate from TestCafe, unfortunately. 💔
It's difficult to determine the cause of the issue without access to your infrastructure. I can only suggest you try connecting a browser from your machine to TestCafe as a remote browser when running tests with Docker and Jenkins. Likely you will need to pass the -p 9000,9001
argument to TestCafe and expose the 9000
and 9001
ports in Docker - https://docs.docker.com/docker-for-mac/networking/. If it doesn't work, you can try to start a VPN server in the container - https://medium.com/@gurayy/set-up-a-vpn-server-with-docker-in-5-minutes-a66184882c45.
@AndreyBelym Solved, I managed to execute TestCafe now. Thanks for helping guys 👏
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.
What is your Test Scenario?
Execute tests on BrowserStack cloud, started from Jenkins job and build on Docker container. Attached configs & files below in
details
section.What is the Current behavior?
When I'm starting Jenkins job, which builds Docker container which contain tests code and all dependencies and executing tests run on BrowserStack cloud - job & BS execution hangs on initial TestCafe proxy URL (page can't be found - 404), e.g.
Every another example works fine: ✅ executed test run on own host machine (MacBook Pro), ✅ executed test run on own host machine (MacBook Pro) in Docker container, ✅ executed test run on BrowserStack cloud from own host machine (MacBook Pro), ✅ executed test run on BrowserStack cloud from own host machine (MacBook Pro) in Docker container,
Executing another frameworks (e.g. WebdriverIO) in BrowserStack from Jenkins in Docker container works fine, so I assume something with TestCafe configuration must don't be properly configured? 🤔
What is the Expected behavior?
We're able to execute TestCafe test run on BrowserStack cloud from Jenkins job in Docker container.
What is your web application and your TestCafe test code?
I couldn't provide URL, but for this case, it's doesn't matter - because it couldn't connect to TestCafe.
We're using
testcafe-browser-provider-browserstack
to handle connection with BS.Global envs variables
```dotenv # Browserstack BROWSERSTACK_USERNAME=... BROWSERSTACK_ACCESS_KEY=... BROWSERSTACK_USE_AUTOMATE=1 BROWSERSTACK_DISPLAY_RESOLUTION=1920x1080 BROWSERSTACK_DEBUG=true # only for this case purpose BROWSERSTACK_NETWORK_LOGS=true # only for this case purpose BROWSERSTACK_CHROME_ARGS="--no-sandbox" ```.testcaferc.json
```json { "browsers": [ "chrome" ], "remoteChromeVersion": "74", "src": "scenarios", "reporter": [ { "name": "spec" }, { "name": "allure", "output": "reports/allure.log" }, { "name": "slack", "output": "reports/slack.log", "options": { "loggingLevel": "SUMMARY", "quietMode": true } } ], "screenshotPath": "screenshots", "takeScreenshotsOnFails": true, "screenshotPathPattern": "${DATE}_${TIME}/${TEST}/${USERAGENT}/${FILE_INDEX}.png" } ```Tests execution script
This script is used to execute test run. ```js // scripts/execute.js const createTestCafe = require('testcafe'); const args = require('commander'); const testCafeConfig = require('../.testcaferc.json'); const { browsers, remoteChromeVersion } = testCafeConfig; args .option('-b, --browserstack') .option('-s, --srcpackage.json scripts
```json { "scripts": { "test": "node scripts/execute.js", "test:bs": "node scripts/execute.js --browserstack", "test:ci": "yarn test:bs" } } ```Dockerfile
```dockerfile FROM node:10 ARG JENKINS_UID=1001 # default value, set up with build command ARG JENKINS_GID=1001 # default value, set up with build command RUN groupadd -g $JENKINS_GID jenkins && useradd -m -u $JENKINS_UID -g $JENKINS_GID jenkins ADD . /www/ RUN chown -R jenkins:jenkins /www/ ENV HOME=/home/jenkins USER jenkins WORKDIR /www RUN yarn CMD yarn test:ci ```Execution report from Jenkins
``` [BrowserStack] BROWSERSTACK_BUILD=jenkins-tests-150 [BrowserStack] BROWSERSTACK_LOCAL=false [BrowserStack] BROWSERSTACK_BUILD=jenkins-tests-150 [BrowserStack] BROWSERSTACK_LOCAL=false [tests] $ /bin/bash -ex /tmp/jenkins5074929632456794166.sh ++ id -u ++ id -g + docker build -t tests --build-arg JENKINS_UID=107 --build-arg JENKINS_GID=112 . Sending build context to Docker daemon 3.624MB Step 1/11 : FROM node:10 ---> 5a401340b79f Step 2/11 : ARG JENKINS_UID=1000 ---> Using cache ---> 8ac3b30f4a56 Step 3/11 : ARG JENKINS_GID=1000 ---> Using cache ---> 5277c8cca05e Step 4/11 : RUN groupadd -g $JENKINS_GID jenkins && useradd -m -u $JENKINS_UID -g $JENKINS_GID jenkins ---> Using cache ---> 355985b56c83 Step 5/11 : ADD . /www/ ---> fba228938267 Step 6/11 : RUN chown -R jenkins:jenkins /www/ ---> Running in 09aa7c5dec10 Removing intermediate container 09aa7c5dec10 ---> a23d5c7991c1 Step 7/11 : ENV HOME=/home/jenkins ---> Running in 378edb74f2d9 Removing intermediate container 378edb74f2d9 ---> f30103f08dab Step 8/11 : USER jenkins ---> Running in b361ff25288b Removing intermediate container b361ff25288b ---> bd171760eaf2 Step 9/11 : WORKDIR /www ---> Running in 6531270408b4 Removing intermediate container 6531270408b4 ---> 3a4f15336e2a Step 10/11 : RUN yarn ---> Running in 3d33f74f1e6e yarn install v1.13.0 warning package.json: No license field info No lockfile found. warning package.json@1.0.0: No license field [1/4] Resolving packages... warning testcafe-browser-provider-browserstack > browserstack-local > sinon > formatio@1.1.1: This package is unmaintained. Use @sinonjs/formatio instead warning testcafe-browser-provider-browserstack > browserstack-local > sinon > samsam@1.1.2: This package has been deprecated in favour of @sinonjs/samsam warning testcafe-browser-provider-browserstack > browserstack-local > sinon > formatio > samsam@1.1.3: This package has been deprecated in favour of @sinonjs/samsam warning eslint > file-entry-cache > flat-cache > circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor. warning testcafe > testcafe-browser-tools > babel-runtime > core-js@1.2.7: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2. [2/4] Fetching packages... [3/4] Linking dependencies... warning " > eslint-import-resolver-babel-plugin-root-import@1.1.1" has unmet peer dependency "babel-plugin-root-import@^5.1.0". [4/4] Building fresh packages... success Saved lockfile. Done in 14.65s. Removing intermediate container 3d33f74f1e6e ---> ed9667f47c20 Step 11/11 : CMD yarn test:ci ---> Running in 7d04b5c2a977 Removing intermediate container 7d04b5c2a977 ---> 631ab81fa50a Successfully built 631ab81fa50a Successfully tagged tests:latest + docker run -i --rm -v /var/lib/jenkins/workspace/tests/reports:/www/reports -v /var/lib/jenkins/workspace/tests/screenshots:/www/screenshots -e BROWSERSTACK_USERNAME=**** -e BROWSERSTACK_ACCESS_KEY=**** -e BROWSERSTACK_USE_AUTOMATE=1 -e BROWSERSTACK_DISPLAY_RESOLUTION=1920x1080 -e BROWSERSTACK_DEBUG=true -e BROWSERSTACK_NETWORK_LOGS=true -e BROWSERSTACK_CHROME_ARGS=--no-sandbox tests:latest yarn run v1.13.0 warning package.json: No license field $ yarn test:bs warning package.json: No license field $ node scripts/execute.js --browserstack The "browsers" options from the configuration file will be ignored. Running tests in: - Chrome 74.0.3729 / Mac OS X 10.14.0 (https://automate.browserstack.com/builds/xxxx/sessions/xxxx) Allure reporter started... My first fixture Build was aborted # After some time, I manually aborted the build ```BrowserStack network logs
We're achieving a lot of `404 Not Found` on basic TestCafe proxy url, BrowserStack is trying to retry this connection but without any success. ```js { pageref: "Page 0", startedDateTime: "2019-05-28T10:04:17.272-04:00", request: { method: "GET", url: "http://localhost:34165/browser/connect/dxvlU6b", httpVersion: "HTTP/1.1", cookies: [], headers: [{ name: "Host", value: "localhost:34165" }, { name: "Proxy-Connection", value: "keep-alive" }, { name: "Upgrade-Insecure-Requests", value: "1" }, { name: "User-Agent", value: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" }, { name: "Accept", value: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" }, { name: "Accept-Encoding", value: "gzip, deflate, br" }, { name: "Accept-Language", value: "en-US,en;q=0.9" } ], queryString: [], headersSize: 480, bodySize: 0, comment: "" }, response: { status: 404, statusText: "Not Found", httpVersion: "HTTP/1.1", cookies: [], headers: [{ name: "cache-control", value: "no-cache, no-store, must-revalidate" }, { name: "pragma", value: "no-cache" }, { name: "Date", value: "Tue, 28 May 2019 14:04:17 GMT" }, { name: "Connection", value: "keep-alive" }, { name: "Content-Length", value: "0" }, { name: "Proxy-Connection", value: "keep-alive" } ], content: { size: 0, mimeType: "", comment: "" }, redirectURL: "", headersSize: 208, bodySize: 0, comment: "" }, cache: {}, timings: { comment: "", send: 3, ssl: -1, wait: 311, dns: -1, connect: 1, receive: 0, blocked: -1 }, comment: "", time: 317 } ```Steps to Reproduce:
Your Environment details:
1.1.4
1.8.0
v10
execute.js
attached aboveChrome 74
OS X Mojave
Does anyone experienced anything like this? I was looking for answers, trying to add
"hostname": "localhost"
to my.testcaferc.json
, disablingBrowserStack Local
etc. but without success. The most curious thing is that starting everything from my local machine, everything works.Best regards, Marcin