为什么Docker在我的Selenium项目中看不到驱动程序可执行文件?抛出驱动程序可执行文件不存在

时间:2019-05-29 09:39:23

标签: ubuntu selenium-webdriver docker-compose containers

See the stackrace:

[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
...
... TestNG 6.14.3 by C?dric Beust (cedric@beust.com)
...


Local Operating System: LINUX
Local Architecture: amd64
Selected Browser: FIREFOX
Disable AI based Visual Testing: true
Headless Mode: true
Connecting to Selenium Grid: false


Local Operating System: LINUX
Local Architecture: amd64
Selected Browser: FIREFOX
Disable AI based Visual Testing: true
Headless Mode: true
Connecting to Selenium Grid: false

Unable to capture screenshot: null

Local Operating System: LINUX
Local Architecture: amd64
Selected Browser: FIREFOX
Disable AI based Visual Testing: true
Headless Mode: true
Connecting to Selenium Grid: false

Unable to clear cookies: null
Test Execution Time: 0 minutes, 0 seconds
java.lang.NullPointerException
    at com.netsol.configs.AutomationFactory.closeEyes(AutomationFactory.java:151)
    at com.netsol.base.SeleniumBase.closeAutomationObjects(SeleniumBase.java:101)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:425)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:283)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
[ERROR] Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.615 s <<< FAILURE! - in TestSuite
[ERROR] searchSomethingInGoogle(com.package.tests.features.frontend.TEST_GoogleSearch)  Time elapsed: 0.108 s  <<< FAILURE!
java.lang.IllegalStateException: The driver executable does not exist: /home/automation/myproject
    at com.package.tests.features.frontend.TEST_GoogleSearch.searchSomethingInGoogle(TEST_GoogleSearch.java:25)

[ERROR] closeAutomationObjects(com.package.tests.features.frontend.TEST_Demo)  Time elapsed: 0.175 s  <<< FAILURE!
java.lang.NullPointerException

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   TEST_Demo>SeleniumBase.closeAutomationObjects:101 ? NullPointer
[ERROR]   TEST_GoogleSearch.searchSomethingInGoogle:25->SeleniumBase.getDriver:62 ? IllegalState
[INFO] 
[ERROR] Tests run: 2, Failures: 2, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  23.142 s
[INFO] Finished at: 2019-05-29T09:21:51Z

我需要在Docker容器中执行Selenium测试。我知道Selenium提供了集线器和节点容器,但是我必须编写自己的Dockerfile来构建一个容器,该容器将在没有网格配置的情况下执行测试。基本上,由于某种原因我不能使用网格。我已经写了一个Dockerfile。它在构建阶段通过。但是,当我运行容器时,它不会实例化浏览器并引发java.lang.IllegalStateException异常:驱动程序可执行文件不存在:/ home / automation / myproject

另外,请注意,我需要以无头模式执行测试,因此myproject中已经存在用于以无头模式运行浏览器的配置。

我尝试将+ rwx权限授予我下载和解压缩文件的位置。

在下面查看我的Dockerfile:

FROM ubuntu:latest
LABEL name="myproject" \
            author="TAFSEER HAIDER" \
            version="1.0" \
            description="Execute backend and frontend tests using myproject in containers"

# Install Java JDK8, Maven, and Wget
RUN apt-get update \
    && apt-get install firefox  -y \
    && apt-get -y install openjdk-8-jdk \
    && apt-get install -y maven \
    && apt-get install -y wget \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/ /tmp/* /var/tmp/*

# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

# Add a user for running applications.
RUN apt-get update && apt-get install sudo -y \
    && adduser --disabled-password --gecos '' automation \
    && adduser automation sudo \
    && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/ /tmp/* /var/tmp/* 

# Copy myproject project to the specified directory in containerized Ubuntu Linux
COPY --chown=automation . /home/automation/myproject/


# Set working directory
WORKDIR /home/automation/myproject/

RUN chown -R automation:automation /home/automation/myproject/src/test/resources/webdrivers/selenium_standalone_binaries/linux/marionette/64bit \
    && chmod 755 /home/automation/myproject/src/test/resources/webdrivers/selenium_standalone_binaries/linux/marionette/64bit \
    && chmod +rwx /home/automation/myproject/src/test/resources/webdrivers/selenium_standalone_binaries/linux/marionette/64bit



USER automation

# Clean & compile myproject
RUN cd /home/automation/myproject/ && mvn clean test-compile

# Execute tests on microservices and fronted GUI by specifying the required test suite file
CMD ["mvn", "failsafe:integration-test", "-DtestSuite=frontend.xml"]

1 个答案:

答案 0 :(得分:0)

您的代码似乎期望在/home/automation/myproject上找到geckodriver和chromedriver。

查看您的Dockerfile,您尚未在任何地方安装CromeDriver,而Geckodriver位于/home/automation/myproject/src/test/resources/webdrivers/selenium_standalone_binaries/linux/marionette/64bit

如果您打印出ENV变量的值,这将很有用:

  • webdriver.chrome.driver
  • webdriver.gecko.driver

然后我们可以100%确定您的代码期望在哪里找到驱动程序二进制文件,然后可以检查它们实际在那里存在。