Cannot get label item (UI item) when running cypress headless in docker - docker

When running cypress with command
npx cypress open and npx cypress run (headless), it works fine.
But when I run cypress with docker (headless using cypress run), it hangs when trying to get label item.
cy.get('#label-page-id').then(($elPageId) => {
cy.log('page id', elPageId);
});
I dont know why it does not work. Do I have to set something more so that docker knows.

Related

Cypress Docker Screenshot - Mochawesome

We are trying to run Cypress using Docker. We can embed the screenshots on failed tests when we run Cypress locally. Is there a way to show the Screenshots taken or failed test using their included Docker image?

Getting issue while trying to run the protractor in centos docker image: chrome failed to start

I am trying to run the selenium test cases in a docker container with Centos using a protractor. I am getting an error. Even I have the latest version of the xvfb package.

Jenkins Docker pipeline plugin with docker run

I have a Jenkins pipeline with the Docker Pipeline plugin installed.
I would like to run a docker container with the plugin using the following command:
docker.image("$uri/$name:$tag").run("-it --name myWebApp -v /myData:/mywebapp/data")
However, however, Jenkins'log console shows me nothing. I use -it to show the log and the process until it is finished, however it seems not to work.
Looking at the official documentation, it seems to use -d, in detached mode. I have seen that type withRun and I have tried the following command:
docker.image("$uri/$name:$tag").run("-it --name myWebApp -v /myData:/mywebapp/data") { c->
sh "docker logs ${c.id}"
}
However it stops after a few seconds showing this:
docker logs 897sdfhdv87sdXX
How do I start a docker container normally? By showing the logs and synchronously? It ends in exit 0 type when the container ends successfully
Hi I know this probably is no longer needed, but I believe this is achievable by doing something like:
docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw"') { c ->
sh "docker logs ${c.id}"
}
This example was adapted from https://www.jenkins.io/doc/book/pipeline/docker/

How to run testcafe from local on chrome docker image

I don't want to install chrome to run testcafe and want to use a chrome docker image.
Step1:
docker run -d -p 4444:4444 selenium/standalone-chrome
Step2:
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3487d6a08310 selenium/standalone-chrome "/opt/bin/entry_poin…" About an hour ago Up About an hour 0.0.0.0:4444->4444/tcp charming_proskuriakova
Step3: This code works for python2.7
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver=webdriver.Remote(
command_executor='http://0.0.0.0:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME)
driver.get("https://www.google.com/")
print driver.title
driver.close()
I am looking to use same functionality for testcafe. Base code(test1.js):
import { Selector } from 'testcafe';
fixture `Getting Started`
.page `http://devexpress.github.io/testcafe/example`;
test('My first test', async t => {
// Test code
});
Execution on local Chrome:
testcafe chrome test1.js
I am looking for method to replace chrome with docker image. I know, chrome is inbuilt with testcafe, you can consider "safari" or any other browser in place of chrome. IDea is learn to use docker image in testcafe.
PS: I dont want to use testcafe/testcafe image since my issue is not running testcafe in docker , but only browser in docker.
Could you please clarify why don't you want to use the testcafe docker image?  It seems that selenium/standalone-chrome image also contains selenium related code which listen api requests and runs test on a browser installed inside the container.
Note: testcafe doesn't have built-in browsers, it runs locally installed browsers.
An alternate way to run a browser inside a docker image is to use the remote browser functionality (https://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#remote-browsers). You will need to run tescafe with a 'remote' browser alias  and then run a browser inside a container via the 'docker run' command and pass it the 'http:///browser/connect' link

Cypress could not verify that the server set as your 'baseUrl' is running:

I can reach from my computer with web browser to xxxx.com:8089 which is running on a container too but different remote machine. Everything is fine. My cypress.json
"baseUrl": "http://xxxx.com:8089" is this.
I am trying to run docker container to run tests with Cypress :
docker run --rm --name burak --ipc="host" -w /hede -v /Users/kurhanb/Desktop/nameoftheProject:/hede' cypress /bin/bash -c cypress run --browser chrome && chmod -R 777 . --reporter mochawesome --reporter-options --reportDir=Users/kurhanb/Desktop/CypressTest overwrite=false
It gives me :
Cypress could not verify that the server set as your 'baseUrl' is running:
http://xxxx.com
Your tests likely make requests to this 'baseUrl' and these tests will fail if you don't boot your server.
So basically, I can reach from my computer but container can not ?
Cypress is giving you that error because at the time that Cypress starts, your application is not yet ready to start responding to requests.
Let's say your application takes 10 seconds to set up and start responding to requests. If you start your application and Cypress at the exact same time, Cypress will not be able to reach your application for the first ten seconds. Rather then wait indefinitely for the app to come online, Cypress will exit and tell you that your app is not yet online.
The way to fix this problem is to make sure that your web server is serving before Cypress ever turns on. The Cypress docs have some examples of how you can make this happen: https://docs.cypress.io/guides/guides/continuous-integration.html#Boot-your-server
I got the "Cypress failed to verify that your server is running" problem despite being able to access the site through a browser. The problem was that my
/etc/hosts
file did not include a line:
127.0.0.1 localhost
In your CICD pipeline, make sure your application is up and running before Cypress.
Using Vue.js app as example, use following commands in CICD pipeline scripts:
npm install -g wait-on
npm run serve & wait-on http://localhost:8080
cypress run
If you are trying to run your test on a preview/staging environment and you can reach it manually, the problem can be your proxy settings. Try to add the domain to / IP address to NO_PROXY:
set NO_PROXY="your_company_domain.com"
If you navigate to the Proxy Settings in the test runner, you should see the Proxy Server and a Proxy Bypass List, with the NO_PROXY values.
I hope it helps somebody. Happy coding.
I faced the same issue when i was working on a react application with gitlab ci and docker image. React application have default port as 3000, but some how docker image was assigning default port 5000. So i used cross-env to change default port of react app to 5000: -
Steps
download cross-env package
in package.json file under script change 'start': 'react-scripts start' to 'start': 'cross-env PORT=5000 react-scripts start'
Also, if working with docker, you need to make sure that your front-end and back-end are working. Cypress doesn't automatically starts your front-end server.
Steps should be
npm start
npm start < back-end>
npx cypress run or npx cypress open
I faced the same issue. I tried the suggestions above. I think this is a docker issue. Restarting docker fixed it for me.

Resources