gpt4 book ai didi

java - 为什么我的 ExpectedConditions 命令被忽略? Java 中的 Selenium WebDriver

转载 作者:行者123 更新时间:2023-12-01 16:47:30 30 4
gpt4 key购买 nike

我正在使用 Cucumber 和 Selenium WebDriver 来测试应用程序,并且我刚刚注意到我的测试正在特定区域上通过,无论我在“ExpectedConditions.textToBe”方法的参数中输入什么内容。

这部分测试简单地检查在测试添加用户后用户角色表中是否显示正确的文本:

    public void admin_can_see_the_new_role_in_the_list() throws Throwable {
// Write code here that turns the phrase above into concrete actions
//throw new PendingException();
Thread.sleep(3000);
ExpectedConditions.textToBe(By.xpath("//*[@id=\"role-nbbbamze\"]"), "account manasdfsdfger");
ExpectedConditions.textToBe(By.xpath("//*[@id=\"app\"]/dizz/dib[2]/divz/div[2]zzz/table/tbody/tr[11]/td[2]"), "Accmasfsdnager");
ExpectedConditions.textToBe(By.xpath("//*[@id=\"app\"]/dbiv/div[2]/div/dziv[2]/tzable/tzzzbody/tr[11]/td[3]"), "Can acvfcess the normal dashboard");
}

如您所见,我已向参数添加了随机字符,并且测试运行并仍然通过。它应该失败,因为我定义的 xpath 不存在 - 或者我断言的文本与该 xpath 中的任何内容都不匹配。

我显然错误地使用了 ExpectedConditions,但我不知道在哪里或如何使用。

提前谢谢大家!

最佳答案

您必须将它与等待对象结合使用,例如:

WebDriverWait wait = new WebDriverWait(driver, 60); 
wait.until(ExpectedConditions.textToBe(By.xpath("//*[@id=\"app\"]/dbiv/div[2]/div/dziv[2]/tzable/tzzzbody/tr[11]/td[3]"), "Can acvfcess the normal dashboard"));

关于java - 为什么我的 ExpectedConditions 命令被忽略? Java 中的 Selenium WebDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47221676/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com