【发布时间】:2017-08-21 13:24:32
【问题描述】:
我正在帮助我的一位朋友完成他在 jUnit 中的第一次测试。 我们最近遇到了一个问题,我不知道是什么原因造成的。
我们正在执行测试,在我们的页面上弹出 Facebook 登录窗口,然后填写登录输入,它将关闭窗口并刷新浏览器。登录后,我们希望继续测试登录用户的功能。
事情是......在提交并关闭窗口的元素上执行click()函数后,测试没有跟随并表现得像是重新开始工作,但一段时间后停止。
为了更好地说明问题...这是代码示例:
@Before
public void setUp() throws Exception
{
driver = new FirefoxDriver();
baseUrl = "https://www.example.com/";
}
@Test
public void OrderWithLoginFbCash() throws Exception
{
driver.get(baseUrl);
// remembers the parent Windowhandle
String parentHandle = driver.getWindowHandle();
// Opens Facebook login window
WebElement FbLogin = (new WebDriverWait(driver , 20)).until(
ExpectedConditions.presenceOfElementLocated(By.id("fblogin"))
);
FbLogin.click();
for (String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
// ... filling up the inputs ...
WebElement FbLoginFacebook = (new WebDriverWait(driver, 20)).until(
ExpectedConditions.presenceOfElementLocated(By.id("u_0_0"))
);
// everything's still fine here
FbLoginFacebook.click(); // logs in, closes the window and reloads the page
// !!! Test won't continue here for some reason. !!!
System.out.println("Did the logging in stuff"); // Won't be printed
}
我自己不是测试人员,所以我很难说它为什么会停在那里。我认为这可能是因为它设置的窗口在元素的click() 上关闭,但是我想不出任何解决该问题的方法。任何帮助,将不胜感激。谢谢。
【问题讨论】:
标签: java testing junit automated-tests junit4