【发布时间】:2018-07-31 23:00:49
【问题描述】:
我有一个在 Jenkins 中运行时总是失败的测试。
我的项目包括 Selenium webdriver、JAVA、Maven、TestNG、Jenkins、Allure(报告)。 我有一些包含 100 多个测试用例的测试套件,我通过 3 个不同的浏览器对它们进行迭代(测试使用 TestNG 并行运行)。它们都运行(使用 maven 命令行)并传入我的开发笔记本电脑,并在使用命令行时在测试服务器上传递。
我有 2 个关于 Jenkins 的问题并将它们分成 2 个问题 - 其中一个在这个问题中描述,另一个(IE11 问题)在这里。
在测试服务器的 Jenkins 中运行时,问题就开始了! 移动模拟器(Chrome 浏览器)中的测试失败 - 在测试中,我单击一个链接以验证是否使用正确的 url 打开了一个新窗口。 我尝试了 3 种类型的点击(Selenium click、Actions、JS)并且都返回了一个空句柄。
代码:
这里我创建主窗口句柄并点击链接:
String mwh = driver.getWindowHandle();
WebElement poweredBy = (new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(Consts.POWERED_BY_XPATH_1000))));
poweredBy.click();
这是获取句柄并验证新窗口的方法的一部分:
public boolean closePopupWindow(String mwh, String mTitle, String layoutNumber) {
// For IE11- make sure popup blocker is turned off in the options. else it will have only one window handle and fail
boolean isOpenedWindowCorrect = false;
String newWindow = null;
Set<String> handlers = driver.getWindowHandles();
for (String window : handlers) {
if (!window.equals(mwh)) {
newWindow = window;
}
}
// the focus is on the main page. need to switchTo new page and close it
driver.switchTo().window(newWindow);
System.out.println("The focus now is on the NEW window");
String newTitle = driver.getTitle();
System.out.println(newTitle);
这是我得到的错误:
java.lang.NullPointerException:条目中的 null 值:handle=null 在 com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:34) 在 com.google.common.collect.SingletonImmutableBiMap.(SingletonImmutableBiMap.java:42) 在 com.google.common.collect.ImmutableBiMap.of(ImmutableBiMap.java:73) 在 com.google.common.collect.ImmutableMap.of(ImmutableMap.java:123) 在 org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:995) 在 il.carambola.pages.Page.closePopupWindow(Page.java:786)
您认为 Jenkins 不会在浏览器中打开新窗口存在安全问题吗?打开窗户很慢吗? 不使用移动模拟器时,相同的测试通过。 (我在 Chrome 和 Firefox 中进行过同样的测试,点击成功,通过验证)。
JDK 1.8.0_162
詹金斯 V 2.121.1
服务器 - AWS t2.large - 8GB RAM,Windows server 2016 数据中心,64 位
【问题讨论】:
标签: java jenkins selenium-webdriver testng selenium-chromedriver