繁体   English   中英

移动模拟器Selenium测试在Jenkins中失败,但在cmd中未失败

[英]Mobile emulator Selenium tests fail in Jenkins but not in cmd

我有一个在Jenkins中运行时始终失败的测试。

我的项目包括Selenium Webdriver,JAVA,Maven,TestNG,Jenkins,Allure(报告)。 我有几套包含100多个测试用例的测试,并通过3种不同的浏览器进行了迭代(测试使用TestNG并行运行)。 它们都运行(使用maven命令行)并通过我的开发笔记本电脑以及使用命令行时在测试服务器上传递。

关于詹金斯,我有2个问题,并将它们分为2个问题-其中一个在此问题中进行了描述,另一个(IE11问题)在此处。

当在测试服务器的Jenkins中运行时,问题开始! 在移动模拟器(Chrome浏览器)中,测试失败-在测试中,我单击链接以验证是否使用正确的URL打开了新窗口。 我尝试了3种类型的点击(Selenium点击,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:条目中的空值:com.google.common.collect.SingletonImmutableBiMap上com.google.common.collect.SingletonImmutableBiMap。com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:34)上的值(SingletonImmutableBiMap.java:42) ),位于org.openqa.selenium.remote.RemoteWebDriver $的com.google.common.collect.ImmutableMap.of(ImmutableMap.java:123)的com.google.common.collect.ImmutableBiMap.of il.carambola.pages.Page.closePopupWindow(Page.java:786)上的RemoteTargetLocator.window(RemoteWebDriver.java:995)

您是否认为存在詹金斯不会在浏览器中打开新窗口的安全问题? 打开窗户很慢吗? 不使用移动仿真器时,同样会测试PASS。 (我在Chrome和Firefox中进行了相同的测试,因此点击并通过验证成功)。

JDK 1.8.0_162

詹金斯V 2.121.1

服务器-AWS t2.large-8GB RAM,Windows Server 2016数据中心,64位

很明显,当您的程序进入这一行时

driver.switchTo().window(newWindow);

newWindow仍然为null。 编写方式可能是计时问题,也可能是导致弹出窗口不显示的另一个问题。 为了确保这不是时间问题,建议您在尝试切换窗口之前添加某种等待,以等待多个窗口句柄。 就像是

(new WebDriverWait(driver,10)).until(d -> d.getWindowHandles().size() == 2);

如果等待失败,那么您将知道弹出窗口已被阻止,可以从那里去。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM