首页 > 解决方案 > 程序中出现假阴性

问题描述

我正在尝试在 selenium 中执行简单的程序,但在成功运行后,我也收到了假阴性错误,任何人都可以帮忙。它工作正常,如果 id 正确,它可以自动登录,但即使它工作方法登录显示失败

package TestNG;
//import java.util.concurrent.TimeUnit;//
import org.testng.annotations.*;import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.openqa.selenium.*;

public class DemoTestNG 
{
  @Test
  public void login() 
  {
    System.setProperty("webdriver.chrome.driver", "C:\\BrowserDriver\\chromedriver.exe");
    ChromeDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get("https://www.netflix.com/nz/login"); 
    
    System.out.println(driver.getCurrentUrl());
    driver.findElement(By.id("id_userLoginId"));
    WebElement username=driver.findElement(By.id("id_userLoginId"));

    driver.findElement(By.id("id_password"));
    WebElement password=driver.findElement(By.id("id_password"));

    //driver.findElement(By.id("submit-login"));
    WebElement loginbutton= driver.findElement(By.xpath("//button[text()='Sign in']"));

    username.sendKeys("anything");
    password.sendKeys("anything");
    loginbutton.click();

    String expectedUrl="https://www.netflix.com/browse";
    String actualUrl = driver.getCurrentUrl();
    //https://githubmemory.com/repo/cbeust/testng/issues/2524
    //System.out.println(actualUrl);
    //System.out.println(expectedUrl);
    
    if(actualUrl.equalsIgnoreCase(expectedUrl)) 
    { 
          System.out.println("FAIL"); 
    } 
    else 
    { 
        System.out.println("PASS"); 
    }
    
    Assert.assertEquals(actualUrl, expectedUrl, "successfully to move dashboard");
    //System.out.println("successfully moved to dashboard");
    driver.close();
  }
}

标签: automation

解决方案


推荐阅读