当浏览器用户界面不可用时,不会识别帧(测试作为服务运行)

时间:2015-09-03 05:04:34

标签: selenium selenium-webdriver selenium-chromedriver frames

场景: 将selenium maven测试与Jenkins / Teamcity集成,以便在一周内安排一次这些测试。 这些测试用于自动化包含许多帧和子帧的网站。因此,为了在每次需要在帧之间切换时识别元素。

代码段:

String Username = s.getCell(0,row).getContents();
String Password = s.getCell(1,row).getContents();
Login(Username,Password);
Thread.sleep(5000);
driver.switchTo().frame(0);

问题: 当测试通过命令行或eclipse运行时,它们会通过。 通过Jenkins / Teamcity运行测试时出现问题。 原因可能是这两个工具(Jenkins / Teamcity)不对真实浏览器执行测试。相反,测试是从后端运行的。因此,不识别帧并抛出异常。 注意:即使在切换到帧之前放置等待条件,也会抛出异常。

预期产量: 应该识别帧并成功切换。

实际输出:

Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Windows\TEMP\scoped_dir2716_17285}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=44.0.2403.157, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 5f43812bb3037e1d67f35126d19bc50d
    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:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:869)
    at testproject.Browser.ExportTestCase(Browser.java:120)
    at testproject.testclass.Login(testclass.java:16)


Results :

Failed tests: 
  testclass.Login:16->Browser.ExportTestCase:120 » NoSuchFrame no such frame
  (...

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[ERROR] There are test failures.

Please refer to D:\svn_workspace\TestlinkBackup\target\surefire-reports for the individual test results.
[JENKINS] Recording test results
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 minutes 22 seconds
[INFO] Finished at: Tue Sep 01 10:43:51 IST 2015
[INFO] Final Memory: 42M/234M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving D:\svn_workspace\TestlinkBackup\pom.xml to TestlinkBackup/TestlinkBackup/0.0.1-SNAPSHOT/TestlinkBackup-0.0.1-SNAPSHOT.pom
channel stopped
Finished: UNSTABLE

请为此提供解决方案。

0 个答案:

没有答案