How to add multiple browsers to Codeception for Browser Stack - codeception

I am trying to configure my acceptance.suite.yml in Codeception to allow me to run the test in various browsers on Browser Stack.
class_name: WebGuy
modules:
enabled:
- WebDriver
config:
WebDriver:
url: 'http://www.heyday.co.nz'
host: 'hub.browserstack.com'
port: 80
browsers: firefox
capabilities:
How would I add say, IE8 and Safari for example? Your help appreciated.

Use Environments.
That chapter describes your use case, but I will copy some details to avoid giving a link only answer.
For cases where you need to run tests with different configurations you can define different config environments.
acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
config:
WebDriver:
url: 'http://127.0.0.1:8000/'
browser: 'firefox'
env:
phantom:
modules:
config:
WebDriver:
browser: 'phantomjs'
chrome:
modules:
config:
WebDriver:
browser: 'chrome'
firefox:
# nothing changed
You can easily switch between those configs by running tests with --env option. To run tests only for PhantomJS you need to pass --env phantom option:
php codecept.phar run acceptance --env phantom
To run tests in all 3 browsers, just list all the environments:
php codecept.phar run acceptance --env phantom --env chrome --env firefox

Related

Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: failed to write prefs file. selenium grid

I'm attempting to run Selenium grid with google chrome extensions in docker, but my code ran into an error.
code runs perfectly localy but when i try to start it via docker i got an error.
chrome_options = Options()
chrome_options.add_argument("user-data-dir=/dev/shm/sale")
unpacked_extension_path = '/dev/shm/sale/Default/Extensions/nkbihfbeogaeaoehlefnkodbefgpgknn/10.16.1_0'
chrome_options.add_argument('--load-extension={}'.format(unpacked_extension_path))
driver = webdriver.Remote(command_executor='http://x.x.x.x:4444/wd/hub', options=chrome_options)
here is my docker-compose file
sale_selenium:
container_name: sale_selenium
image: selenium/standalone-chrome:103.0.5060.53
volumes:
- ../mounts/Extensions:/dev/shm/sale/Default/Extensions
networks:
- sale_network
expose:
- 4444
deploy:
resources:
limits:
cpus: '0.40'
memory: '2500M'

How to set Timeouts in Selenium/standalone-chrome in gitlab-ci.yml file

How can be setted timeouts (-timeout -browserTimeout) in gitlab-ci.yml for selenium server if I use selenium/standalone-chrome image?
Selenium Timeout Documentation
Below piece of my gitlab-ci.yml
marked_test:
image: $CONTAINER_TEST_IMAGE
allow_failure: true
stage: test
services:
- name: selenium/standalone-chrome:latest
alias: chrome
- name: selenium/standalone-firefox:latest
alias: firefox
only:
refs:
- main
variables:
- $TAG_RUN == "marked"
tags:
- run01_docker
script:
- $PYRUN -m $TAG_MARK --env="$TEST_ENV" --mode="server" --browser=$TEST_BROWSER --alluredir=$ALLURE_RESULTS_FOLDER
fi
timeout: 2h
I searched the Internet for a solution to this kind of problem, I tried to solve it with what I found but nothing could help
For example:
services:
- name: selenium/standalone-chrome:latest
alias: chrome
environment:
SE_OPTS: "-timeout 86400 -browserTimeout 86400"
I use circleci and also met the issue, the problem is - selenium node is terminating in default 300 seconds, to extend this time I used this and it helped me: (f.e. 11k seconds)
image: selenium/standalone-chrome:latest
environment:
SE_NODE_SESSION_TIMEOUT: 11000

docker-compose using cached file with pytest

I've configured IntelliJ to use python via a stack I've defined in docker-compose. I'm configured my project to execute my pytest via docker-compose so that I can use the debugger. However, I've discovered that after the initial run, when I change my code and re-run my tests, pytest is not seeing my changes, but rather executing a cached version of the code.
The only way I've discovered to get around this is to invoke the File menu option Invalidate Caches and Restart. This is annoying.
This my compose file:
networks:
app: {}
services:
item-set-definitions:
build:
context: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: build
command:
- /bin/bash
image: item-sets:test
networks:
app: {}
volumes:
- source: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: /project
type: bind
version: '3.9'
In the pytest Run configuration I've tried adding -force-recreate option in the docker-compose Command and options field but IntelliJ won't recognize it.
Does anyone know how I can configure IntelliJ to not cache any of my source file so that pytest will see my changed code?
Thank you

Issue connection Selenoid GGR (Go Grid Router)

I am trying to run nightwatchjs test using selenoid ggr (Go Grid router) but I am getting the below error:
- Connecting to un:pwd#ip_add on port 4444...
POST http://un:pwd#ip_add:4444 /wd/hub/session - EAI_FAIL
Error: getaddrinfo EAI_FAIL un:pwd#ip_add
‼ Error connecting to un:pwd#ip_add on port 4444.
Below are the various container that's running on my Linux machine (IP_add)
Could you please support in identifying the issue?
Also, I am unable to navigate to ggr-ui
I was now able to run the test using GGR.
Following command were run to start selenoid, ggr, ggr-ui and selenoid UI:
./cm selenoid start --vnc --port 4445
docker run -d --name ggr -v /etc/grid-router/:/etc/grid-router:ro --net host aerokube/ggr:latest-release
docker run -d --name ggr-ui -p 8888:8888 -v /etc/grid-router/quota/:/etc/grid-router/quota:ro aerokube/ggr-ui:latest-release
docker run -d --name selenoid-ui --link ggr-ui -p 8080:8080 aerokube/selenoid-ui --selenoid-uri=http://ggr-ui:8888
To navigate to ggr dashboard:
http://'ip address':8080/
In nightwatch config use following selenoum config:
host: '192.168.5.241',
port: 4444,
'username': "test",
'access_key': "test-password",
start_process: false,
This way I was able to run the test
Well, to run tests on GGR for me was enough official documentations
https://aerokube.com/ggr/latest/
I configured 2 machines
On machine №1 (where was configure ggr + ggr(ui))
You can see my list of configured containers
list of containers screen
On machine №2
Was configured Selenoid and Selenoid UI
Also do not forget to configure quota file(see official documentation)
See common screen of configuration:
screen of common configuration

Getting WebDriver working with Firefox

Using Laravel 5+ with Vagrant.
I have selenium running using:
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.firefox.bin="/usr/bin/firefox"
using a headless display:
sudo Xvfb :10 -ac
However when i run codeception:
./vendor/bin/codecept run selenium --steps
I get the following error:
[Facebook\WebDriver\Exception\UnknownServerException] Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: GDK_BACKEND does not match available displays
I am confused with server and ports that i should be using.
Currently i access site through http://localhost:8000
however that is outside vagrant.
I observe $url = 'http://localhost:4444/wd/hub', inside api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php
As the error outputs :
127.0.0.1 on port 7055.
Actually you should download latest geckodriver from here and set property Dwebdriver.gecko.driver with downloaded geckodriver path from your system when you run the selenium-server-standalone.jar as below :
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.firefox.bin="/usr/bin/firefox" -Dwebdriver.gecko.driver = "path/to/downloaded geckodriver
Note : Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable geckodriver that will run alongside with the latest firefox browser. For more information you should follow this link.
Now you need to set capability with marionette to true during initialisation of RemoteWebDriver inside api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php as :
$capabilities->setCapability('marionette', true);
Full example code :
$host = 'http://localhost:4444/wd/hub';
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability('marionette', true);
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
Switched to chrome web driver, was less complicated, more compatible and works fine for me.
Download chrome webdriver or composer require
Setup environment
nohup sudo Xvfb :10 -ac &
export DISPLAY=:10
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.chrome.bin="/usr/bin/google-chrome" -Dwebdriver.chrome.driver="vendor/bin/chromedriver"