简体   繁体   English

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

[英]Why are my ExpectedConditions commands being ignored? Selenium WebDriver in Java

I am using Cucumber with Selenium WebDriver to test an application, and I have just noticed that my tests are passing on a particular area, no matter what I put into the parameters of the "ExpectedConditions.textToBe" method. 我正在将Cucumber与Selenium WebDriver一起用于测试应用程序,并且我刚刚注意到,无论我将“ ExpectedConditions.textToBe”方法的参数设置为什么,我的测试都通过了特定区域。

This part of the tests simple checks that the correct text appears in a table of user roles after the test has added a user: 测试的这一部分简单地检查在添加用户后,正确的文本是否出现在用户角色表中:

    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");
}

As you can see, I have added random characters to the parameters and the test runs and still passes. 如您所见,我在参数中添加了随机字符,并且测试运行并仍然通过。 It should fail, either because the xpath I have defined doesn't exist - or the text I am asserting does not match anything within that xpath. 它应该失败,因为我定义的xpath不存在-或我声明的文本与该xpath中的任何内容都不匹配。

I am obviously using the ExpectedConditions wrong, but I can't figure out where or how. 我显然在使用ExpectedConditions错误,但我不知道在哪里或如何。

Thanks in advance guys! 在此先感谢大家!

You have to use it in combination with a wait object like: 您必须将其与以下等待对象结合使用:

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"));

Here you need to consider a couple of things : 在这里,您需要考虑以下几点:

  • Seems you are trying to induce WebDriverWait , so you can remove the Thread.sleep(3000); 似乎您正在尝试诱导WebDriverWait ,因此可以删除Thread.sleep(3000);
  • ExpectedConditions must be bonded with an instance of WebDriverWait eg wait along with until clause as follows: ExpectedConditions必须以一个实例来粘合WebDriverWaitwait连同until条款如下:

     WebDriverWait wait = new WebDriverWait(driver, 10); 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")); 
  • Now, the most important point is, textToBe clause returns boolean . 现在,最重要的一点是, textToBe子句返回boolean So we have check for the returned Boolean Status as well as follows: 因此,我们检查了返回的Boolean Status ,如下所示:

     WebDriverWait wait = new WebDriverWait(driver, 10); Boolean bool = 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")); 

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

相关问题 Selenium Webdriver“ Expectedconditions.not”无法按预期工作 - Selenium Webdriver “Expectedconditions.not” is not working as expected Selenium Webdriver(Java):为什么找不到我的文本链接? - Selenium Webdriver (Java): Why is it that my text link can't be found? 使用带有java代码的jmeter-plugins-webdriver,出现ExpectedConditions的NoClassDefFoundError? - Useing jmeter-plugins-webdriver with java code , there is a NoClassDefFoundError of ExpectedConditions? 为什么在此忽略此Java运算符优先级? - Why is this Java operator precedence being ignored here? 为什么我的一些 Java 代码被忽略? 问题:java.lang.ArrayIndexOutOfBoundsException - Why is some of my Java code being ignored? Issue: java.lang.ArrayIndexOutOfBoundsException 为什么在MongoDB Java驱动程序中忽略WriteConcern? - why WriteConcern is being ignored in MongoDB Java driver? 为什么我的break语句被忽略? - Why is my break statement being ignored? 为什么我的if(else if)语句被忽略? - Why is my if(else if) statement being ignored? 如何使用带有Java的Selenium WebDriver将命令写入Firefox控制台? - How to write commands into the Firefox console using Selenium WebDriver with Java? 与导出到Java / WebDriver兼容的Selenium IDE命令列表 - List of Selenium IDE commands compatible with export to Java/WebDriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM