硒webdriver检测UI弹出错误消息

拉胡尔SK:

我已经使用硒webdriver测试了这个React应用程序。

如果我的登录错误,如何使用Selenium Webdriver检测文本?我无法找到代码/弄清楚如何捕获弹出消息。“身份验证失败”

@Test
public void failed_login() {
    System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\rahul\\Downloads\\chromedriver_win32_83\\chromedriver.exe");
    
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get("http://testingapp.workspez.com");
    driver.manage().window().maximize();
    WebElement username = driver.findElement(By.id("field_email"));
    WebElement password = driver.findElement(By.id("field_password"));
    WebElement login = driver.findElement(By.xpath("//*[text()='Log In']"));
    
    username.sendKeys("[email protected]");
    password.sendKeys("wrongpassword");
    login.click();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
    String url = driver.getCurrentUrl();
    assertEquals(url, "http://testingapp.workspez.com/login");
}

在此处输入图片说明

Kuldeep Kamune:

您可以使用以下代码来验证是否authentication failed显示弹出窗口:

List<WebElement> popUpElement = driver.findElements(By.id("client-snackbar");
if(popUpElement.size() != 0){
  System.out.println("Pop up is Present "+popUpElement.get(0).getText());
}else{
  System.out.println("Pop up is Absent");
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章