Detox UI Testing - Tests time out when running on CI - react-native

I'm running react-native android integration tests headlessly using the detox framework on Ubuntu 18.04.
The line that I use to run my test suite as a whole is:
detox test -c android.emu.ci --headless --cleanup --take-screenshots failing --detectOpenHandles. This runs 7 tests.
When I run the tests like this the first test runs successfully, and then the second test fails, as it seems like the emulator is offline.
If I run the tests individually with a 15 second gap between them eg:
- detox test post.spec.js -c android.emu.ci --headless --cleanup --take-screenshots failing --detectOpenHandles
- sleep 15s
- detox test post.report.spec.js -c android.emu.ci --headless --cleanup --take-screenshots failing --detectOpenHandles
- sleep 15s
They all complete without failing, so the tests are not the culprit.
I have tried adding a sleep in the afterEach for each test, and as the last action in each test, but neither of these have been successful.
I'm looking for suggestions/direction on what to do to get the tests to wait for the emulator to be ready before executing.

Related

How to silently kill wiremock after Cypress test are executed?

I have an all-in-one npm script that:
Starts a React application
Starts Wiremock server in playback mode
Executes Cypress tests silently
For that I'm using concurrently:
"cypress:runner:one-shot": "concurrently npm:wiremock:playback npm:start:mock npm:cypress:execution:recorded",
After tests are executed I have to shut down the application and WireMock server.
For that, I added the following parameters to concurrently command:
--kill-others --success !command-0,!command-1
I need the all-in-one command to finish with an exit code 0.
For some reason is still finishing with a 1 (given that WireMock server is killed)
Is there any way to ignore the exit codes of any of those commands?
Just in case:
wiremock:playback is something like
"wiremock:playback": "npx wiremock --proxy-all '...' --verbose --port 3001 --enable-stub-cors --root-dir wiremock",
You can shut down WireMock by making a POST request to /__admin/shutdown (on the main host/port you configured WireMock to run on).

Selenium side runner + chromedriver tests with docker not running

I am trying to get selenium side runner to run some tests using docker, to include in our CI.
I am able to run the tests locally in my machine by running:
selenium-side-runner C:\path-to-tests\tests-selenium.side
This is windows host.
I am trying to do the same using docker locally, so afterwards I will migrate this to our Teamcity.
First I am running the selenium server container:
docker run -d -p 4444:4444 --name chromedriver selenium/standalone-chrome:3.4.0
Afterwards I run the selenium side runner container:
docker run -v C:\path-to-tests:/sides --link chromedriver:chromedriver nixel2007/docker-selenium-side-runner
I have to link the containers otherwise I get an error saying that the container can't connect to chromedriver:4444
I also have to mount the volume where my tests are.
When I do this and run, I get the following error:
Test suite failed to run
WebDriverError: Unable to parse new session response
What am I missing here?
UPDATE:
I also tried different versions of the selenium/standalone-chrome container, selenium/standalone-chrome:3.4.0, selenium/standalone-chrome:3.141.59-xenon and selenium/standalone-chrome:latest
All fail with different errors.
SECOND UPDATE:
I have been able to get the tests to run, both locally and in teamcity. One of the issues that I am facing right now is that docker-compose seems to hang. Not sure if this is container related, or docker-compose related.
When I run the tests, the selenium side runner container exits with code 1 and I do not get back to the host console prompt, it stays forever waiting for something to happen.
The error is this:
selenium_selenium-side-runner_1 exited with code 1
I have gotten the docker-compose file from here:
https://github.com/nixel2007/docker-selenium-side-runner/blob/master/docker-compose.yml
Any clues on what I might be missing?

Mocha tests take 20 seconds to get started in docker?

I'm testing frontend-only-code with mocha, docker-compose and node. The following is run in docker using docker-compose run.
NODE_ENV=test env NODE_PATH=$NODE_PATH:$PWD/src mocha $(find . -name 'test_*.js') --compilers js:babel-core/register -r jsdom-global/register --require babel-polyfill
It takes about 15-20 seconds until the first (!) test starts running.
I thought the docker container would boot fast because after 2 or 3 seconds my shell command (see above) is shown on the console. (Which I assumed, would mean the container is up). But after the command is shown it takes 15 - 20 seconds to run the first test.
What's wrong?
Edit: I'm on a Macbook Pro with macOS

How to break Travis CI build if Appium/Mocha tests fail?

I have a Travis CI project which builds an iOS app then starts Appium and runs tests with Appium/Mocha.
The problem is that even though the Mocha tests fail and throw exception, the shell script which runs them via Gulp still exits with 0 and the build is deemed passing.
How can I make the build break/fail when the Mocha tests fail?
Here is how I managed to make this work:
Instead of running the Mocha tests via Gulp, run them directly from the shell script
Save the output to mocha.log besides displaying on stdout
./node_modules/.bin/mocha --reporter spec "appium/hybrid/*uat.js" 2>&1 | tee mocha.log
Check mocha.log for the string " failing" and exit with 1 if found
.
if grep -q " failing" mocha.log; then
exit 1
fi
The exit 1 will make the Travis build fail.

Codeception auto start and auto shutdown selenium server?

I'm using Codeception and I want to do Selenium tests.
Obviously, I need Selenium server running and I can spin it up with:
java -jar ./path/to/selenium/binary
However, I've used another testing framework in past which allowed me to specify this path in config file. Then, whenever I did something like codecept run, the framework automatically started selenium server and also shutted it down after all tests were completed.
Can I do this with Codeception? I tried to put exec() in _bootstrap file but it didn't work..
I'm using phantomjs - headless alternative to selenium. This extension starts phantomjs automatically with codecept run. Also phantomjs is faster than selenium.
You can write your own extension for running selenium - have a look at this file.
I start my tests with a bash script and then start and stop selenium via screen:
#!/usr/bin/env bash
# Start selenium in detached screen
screen -d -m -S "selenium" java -Dwebdriver.chrome.driver=./path/to/chromedriver -jar ./path/to/selenium/binary || true
./vendor/bin/codecept run -c codeception.yml --fail-fast --coverage --steps --coverage-html --html || error=true
# quit selenium
screen -S selenium -X quit || true
This might not fit the use-case but I can execute my code in my bash on Windows and Ubuntu as well as via my jenkins build process.