docker-compose yml
version: "3"
services:
chrome:
image: selenium/node-chrome:4.1.3-20220327
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
edge:
image: selenium/node-edge:4.1.3-20220327
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
firefox:
image: selenium/node-firefox:4.1.3-20220327
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
selenium-hub:
image: selenium/hub:4.1.3-20220327
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
gitlab yml file
variables:
MAVEN_OPTS: -Dmaven.repo.local=.m2/repository
.base:
except:
- tags
.base_test:
extends: .base
tags:
- docker-in-docker
image: docker/compose:latest
services:
- name: docker:dind
before_script:
- docker-compose up
stages:
- build
- test
cache:
paths:
- .m2/repository
- target
build:
image: maven:latest
stage: build
script:
- mvn clean
tags:
- docker-in-docker
test:
image: maven:latest
stage: test
script:
- mvn test
tags:
- docker-in-docker
artifacts:
paths:
- ./TestReport/*
expire_in: 7 days
Remote url in test script
ChromeOptions options = new ChromeOptions();
options.setCapability("se:recordVideo", true);
driver = new RemoteWebDriver((new URL("http://docker:4444/wd/hub")), options);
Pipeline error when executing the stage : test
/root/.cache/selenium/chromedriver/linux64/100.0.4896.60/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
selectTemplateTest2 started!
selectTemplateTest2 skipped!
Extent Reports Version 3 Test Suite is ending!
[ERROR] Tests run: 3, Failures: 2, Errors: 0, Skipped: 1, Time elapsed: 1.7 s <<< FAILURE! - in TestSuite
[ERROR] init(templateTest.TemplateSelectorTest2) Time elapsed: 1.473 s <<< FAILURE!
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Caused by: org.openqa.selenium.WebDriverException:
Driver server process died prematurely.
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'runner-5ahk-ct-project-4846-concurrent-0', ip: '172.18.0.12', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-105-generic', java.version: '17.0.2'
Driver info: driver.version: ChromeDriver
[ERROR] tearDown(templateTest.TemplateSelectorTest2) Time elapsed: 0.006 s <<< FAILURE!
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.quit()" because "this.driver" is null
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] TemplateSelectorTest2>WorkspaceAppTestBase.init:43->TestBase.initialize:42 » SessionNotCreated
[ERROR] TemplateSelectorTest2>WorkspaceAppTestBase.tearDown:57->TestBase.browserTearDown:57 » NullPointer
Can someone please help me fix this Gitlab pipeline issue?
I have set Gitlab pipeline to run selenium tests with grid setup using docker-compose yml file but it seems remoteWebdriver url connection is not working with grid setup
Locally it works fine when i have docker running , docker compose up and then run the testng xml file
Solution:
Update gitlab yml file
variables:
MAVEN_OPTS: -Dmaven.repo.local=.m2/repository
stages:
- build
- test
cache:
paths:
- .m2/repository
- target
build:
image: docker/compose:latest
stage: build
services:
- name: docker:dind
script:
- docker-compose up -d
tags:
- docker-in-docker
test:
image: maven:latest
stage: test
script:
- mvn test
tags:
- docker-in-docker
artifacts:
paths:
- ./TestReport/*
expire_in: 7 days
Then to resolve the cannot create new session error, i had to provide reference to organization specific remote url in browser initialization file
This error message...
/root/.cache/selenium/chromedriver/linux64/100.0.4896.60/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
...implies that there was an error loading the shared library libnss3.so and possibly it is outdated or wasn't installed at all.
Install libnss
as follows:
sudo apt-get install
apt install libnss
apt install libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev
As an alternative you can also:
sudo apt install libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev
Search for the packages:
apt-cache search libnss
apt-file search libnss3.so
Link to Packages: Package Search Results
[BUG] Failed to launch the browser process: error while loading shared libraries: libnss3.so: cannot open shared object file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With