zoukankan      html  css  js  c++  java
  • 使用断言时报错:java.lang.AssertionError: expected [true] but found [false]

    package cn.pagefactory.loginpage;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.PageFactory;

    public class Loginpage {
    String url="https://en.mail.qq.com/cgi-bin/loginpage";
    public WebDriver driver;
    @FindBy(id="u")
    public WebElement Username;
    @FindBy(id="p")
    public WebElement Password;
    @FindBy(id="login_button")
    public WebElement loginbutton;
    @FindBy(id="login_frame")
    public WebElement loginframe;

    public Loginpage(){
    System.setProperty("webdriver.firefox.bin", "D:\Firefox\installpath\firefox.exe");
    driver=new FirefoxDriver();


    PageFactory.initElements(driver,this);
    }
    public void load(){
    driver.get(url);
    }
    public void quit(){
    driver.quit();
    }
    /* public WebDriver getDriver(){
    return driver;
    }*/
    public void login(){

    driver.switchTo().frame(loginframe);
    Username.sendKeys("XXXXXX");
    Password.sendKeys("XXXXXXX");
    loginbutton.click();
    }
    }

    package cn.pagefactory.testqqmail;

    import org.testng.Assert;
    import org.testng.annotations.Test;

    import cn.pagefactory.loginpage.Loginpage;

    public class testqqmail {
    @Test
    public void testqqmail(){
    Loginpage loginpage=new Loginpage();
    loginpage.load();
    loginpage.login();
    Assert.assertTrue(loginpage.driver.getPageSource().contains("收件箱"));
    }
    }

    解决方案:由于没有加等待时间,所以导致没有获取到页面所含资源,加一个等待时间就解决了

    修改后的代码:

    public class testqqmail {
    @Test
    public void testqqmail() throws InterruptedException{
    Loginpage loginpage=new Loginpage();
    loginpage.load();
    loginpage.login();
    Thread.sleep(5000);
    Assert.assertTrue(loginpage.driver.getPageSource().contains("收件箱"));
    }
    }

  • 相关阅读:
    第几天?
    农历02__资料
    农历01
    VC6_预编译头
    QWebEngine_C++_交互
    Qt570_CentOS64x64_02
    Qt570_CentOS64x64_01
    QWebEngineView_CssVariables
    Windows__书
    Win7SDK
  • 原文地址:https://www.cnblogs.com/Hebe-Huang/p/7482188.html
Copyright © 2011-2022 走看看