当前位置: 首页 > 知识库问答 >
问题:

加载共享库时出错:libnss3.so:无法打开共享对象文件:使用带有docker的Selenium Gitlab管道没有这样的文件或目录

汪玮
2023-03-14

docker和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文件

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
    

测试脚本中的远程url

ChromeOptions options = new ChromeOptions();
            options.setCapability("se:recordVideo", true);
            driver = new RemoteWebDriver((new URL("http://docker:4444/wd/hub")), options);

执行阶段:测试时出现管道错误

/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

有人能帮我解决这个Gitlab管道问题吗?

我已经使用docker compose yml文件将Gitlab pipeline设置为使用网格设置运行selenium测试,但似乎remoteWebdriver url连接无法使用网格设置

本地工作正常,当我有docker运行,docker组成,然后运行testng xml文件

解决方案:

更新gitlab yml文件

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
  

然后对于不能创建新的会话错误,我不得不在浏览器初始化文件中提供对组织特定远程网址的引用

共有1个答案

顾学真
2023-03-14

此错误消息。。。

/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

...表示加载共享库libnss3时出错。所以它可能已经过时或者根本没有安装。

安装libnss如下:

sudo apt-get install
apt install libnss
apt install libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev

作为替代方案,您还可以:

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

搜索软件包:

apt-cache search libnss
apt-file search  libnss3.so

链接到软件包:软件包搜索结果

[BUG]浏览器进程启动失败:加载共享库时出错:libnss3.so:无法打开共享对象文件

 类似资料: