Selenium 版本 3.141.59 破坏现有测试用例导致构建失败

Selenium version 3.141.59 breaks existing testcases causes build failure

我正在尝试在我的项目中添加新的 UI 集成测试用例(使用 webdriver )。 我的项目最初有 selenium v​​er 2.42.0。我尝试将版本更新到 3.141.59 并观察到 ​​Maven 测试失败。

运行 mvn install 后出错,测试用例失败导致构建失败:

    -------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@7a31ca20
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
        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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.testng.TestNGException: 
Cannot instantiate class com.symantec.epmp.scsem.web.management.controllers.SepUpgradeControllerTest
        at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38)
        at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:380)
        at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:293)
        at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:115)
        at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:200)
        at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
        at org.testng.TestRunner.initMethods(TestRunner.java:409)
        at org.testng.TestRunner.init(TestRunner.java:235)
        at org.testng.TestRunner.init(TestRunner.java:205)
        at org.testng.TestRunner.<init>(TestRunner.java:153)
        at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:536)
        at org.testng.SuiteRunner.init(SuiteRunner.java:159)
        at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)
        at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)
        at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:159)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
        ... 9 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

这里是我的pom文件测试相关的依赖设置:

2.42.0

     <dependency>
        <groupId>org.jmockit</groupId>
        <artifactId>jmockit</artifactId>
        <version>1.16</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.21</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
    </dependency>
         <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.webdriver</groupId>
            <artifactId>webdriver-selenium</artifactId>
            <version>0.9.7376</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>2.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-ie-driver</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-safari-driver</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>

我怀疑的一件事是您对 selenium 的依赖不匹配。

删除除 selenium-java 依赖项之外的所有 selenium 相关依赖项。其他是冗余依赖项,可能会或可能不会干扰 运行。 selenium-java 包括 运行 selenium 测试所需的所有子模块。

   <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
        <exclusions>
            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

如果您需要自动管理驱动程序服务器可执行文件(例如:chromedriver.exe、gechodriver.exe),请查看 https://github.com/bonigarcia/webdrivermanager,它非常有用。

编辑 1

timed out receiving message from renderer 问题似乎是 chrome 驱动程序本身的问题。 https://bugs.chromium.org/p/chromedriver/issues/detail?id=3332 计划在 chrome 驱动程序 v83 中修复。

不过,似乎有一些解决方法。

  1. 降级为chrome驱动程序 79
  2. 在创建 chrome 驱动程序时在 chrome 选项中添加页面加载策略 NONE

ChromeOptions options = new ChromeOptions(); options.setPageLoadStrategy(PageLoadStrategy.NONE);