Wait.until在Java AND Gradle中使用Selenium返回NoSuchMethod异常

时间:2018-11-21 17:10:31

标签: java selenium selenium-webdriver gradle

我在这方面经历了很糟糕的时间,在我使用Java而不是我最熟悉的.NET的情况下,我提前致歉。

我在测试自动化套件中有一个FluentWait,它正在识别要发送的页面对象,以作为等待页面加载的一种方式。几天前,突然开始返回NoSuchMethod错误。这以前发生过,我在gradle中将google guava依赖项分级。我将Selenium服务器升级到seleniumhq(3.141.59)上的最新版本,并将gradle构建脚本中的番石榴依赖项更新到了最新版本(27.0-jre)。我去了WebDriverWait,而不是FluentWait。到目前为止没有任何进展

我的测试套件包含两个项目,一个包含测试脚本和特定于项目的帮助器功能,一个核心项目具有基本功能,该基本功能可在所有使用自动化的项目中使用。这是等待功能所在的地方

作为一个有趣的旁注,我还发现FluentWait和WebDriverWait代码中有几处已弃用的东西,例如设置轮询间隔和超时的方式。如果我使用Duration.of(xx)而不是(xx,TimeUnit。)设置轮询间隔和超时,则会在顶层项目中出现错误,并且执行将被暂停,但内核编译不会出现问题。这使我相信依赖项中可能还会发生其他事情,这也是我对Java和gradle的经验不足无济于事的地方。

Core Project Error

这是WebDriverWait代码,未使用工期

public static void WaitForPageLoad(WebDriver localDriver, By by)
  {
    localDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    WebDriverWait wait = new WebDriverWait(localDriver, 30);
    wait.pollingEvery(500, TimeUnit.MILLISECONDS);
    wait.withTimeout(30, TimeUnit.SECONDS);
    wait.ignoring(NoSuchElementException.class);
    Function<WebDriver, Boolean> objPes = new Function<WebDriver, Boolean>()
    {
      public Boolean apply(WebDriver localDriver)
      {
        return localDriver.findElement(by).isEnabled();
      }
    };
    wait.until(objPes);
    localDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Sleep(500);
  }

这是我的进口声明

dependencies {

compile('com.ameritas.webcoe.testing:testing-core:1.0.62-SNAPSHOT')
compile('org.springframework.boot:spring-boot-configuration-processor')
compile('org.springframework.boot:spring-boot-starter')
compile('com.google.guava:guava:27.0-jre')
compileOnly('org.projectlombok:lombok:1.16.18')
testCompile 'commons-io:commons-io:2.6'
testCompile 'org.json:json:20170516'
testCompile 'org.apache.poi:poi:3.16'
testCompile 'org.apache.poi:poi-ooxml:3.16'
testCompile 'com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8'
testCompile 'io.rest-assured:json-path:3.0.7'
testCompile 'org.mongodb:mongo-java-driver:3.7.1'
testCompile 'net.sourceforge.jtds:jtds:1.3.1'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile "org.seleniumhq.selenium:selenium-java:${seleniumVersion}"
testCompile "org.seleniumhq.selenium:selenium-support:${seleniumVersion}"
testCompile "org.seleniumhq.selenium:selenium-api:${seleniumVersion}"
drivers.each { driver ->
    testCompile "org.seleniumhq.selenium:selenium-${driver}-driver:${seleniumVersion}"
}

}

最后,这是异常的堆栈跟踪

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.WebDriverWait.until(Ljava/util/function/Function;)Ljava/lang/Object;

at com.ameritas.webcoe.testing.common.WaitOps.WaitForPageLoad(WaitOps.java:59)
at com.ameritas.webcoe.scripts.testing.frontend.pw.pageobjects.login.LoginPage.<init>(LoginPage.java:29)
at com.ameritas.webcoe.scripts.testing.frontend.pw.scripts.PW_Frontend_SmokeTest.accountRecoveryFlowSmokeTest(PW_Frontend_SmokeTest.java:102)
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:104)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:205)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:175)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:217)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:641)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

0 个答案:

没有答案