Cucumber + Selenium:即使我在下一次操作之前解除对话并等待,测试也会失败

时间:2018-02-27 14:46:05

标签: java selenium cucumber

我正在为我的项目和页面对象模型使用Java。

我有一个测试,应该在富文本编辑器中编辑一些内容,然后单击一个按钮。但是在显示文本编辑器之前,会出现一个对话框,上面写着“你想做什么?”它有一个“编辑”按钮。所以我做了这样的事情:

Given user is on edit page
When dialog is displayed, user clicks on Edit
And user enters text in the editor
And user clicks on Save button 
Then edited content is displayed

我有每个页面的页面对象,其中定位器由PageFactory初始化为:

PageFactory.initElements(new AjaxElementLocatorFactory(driver, 20), pageObject);

以及与它们交互的定位器和方法都在页面对象中,如下所示:

@FindBy(css="span.saveLink span#editform-save a.buttonElement")
private WebElement saveLink;

public void saveEdits(){
    saveLink.click();
}

奇怪的是,当我尝试单击保存链接(断言前的最后一步)时,我的测试仍然失败,并出现此错误:

org.openqa.selenium.WebDriverException: unknown error: Element <a role="button" tabindex="0" aria-disabled="false" href="/document/DOC1335" rel="nofollow" class="buttonElement">...</a> is not clickable at point (659, 563). Other element would receive the click: <div class="welcome-window dialog window-active window-setup" role="dialog">...</div>

我正在尝试在浏览器检查器中找到<div class="welcome-window dialog window-active window-setup" role="dialog">元素,但它似乎不存在(即使对话框在屏幕上),但我仍然认为该对话框与此

奇怪的是,单击保存按钮时测试失败,因此在对话框中单击“编辑”并在编辑器中输入文本的前面步骤是成功的。

我设置它以获取失败测试的屏幕截图,有时它仍然显示对话框,有时它显示编辑器(对话框被解除)。所以我添加了一个显式的等待(除了初始化对象时添加的等待):

public void saveEdits(){
    new WebDriverWait(driver, 15).until(ExpectedConditions.elementToBeClickable(saveLink)).click();
}

然而,这没有帮助。当我查看测试运行时,一旦对话框被解除,它似乎就会失败,而根本没有等待。

我不确定这里会发生什么......

0 个答案:

没有答案