java.lang.AssertionError:expected [true]但找到[false] - 这应该是true但显示为false

时间:2017-05-26 11:22:16

标签: selenium

package selenium;

import java.util.concurrent.TimeUnit;
import org.apache.log4j.BasicConfigurator;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;

public class seleniumguru{

    public static void main(String[] args){

        BasicConfigurator.configure();

        FirefoxDriver  driver=new FirefoxDriver();
        driver.get("http://demo.guru99.com/v4/");
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
        WebElement  userid=driver.findElement(By.xpath("html/body/form/table/tbody/tr[1]/td[2]/input"));
        userid.sendKeys("mngr79426");
        WebElement  password=driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td[2]/input"));
        password.sendKeys("ejEqasE");
        WebElement  login=driver.findElement(By.xpath("html/body/form/table/tbody/tr[3]/td[2]/input[1]"));
        login.click();
        WebElement  manageid=driver.findElement(By.xpath("html/body/table/tbody/tr/td/table/tbody/tr[3]/td"));
        manageid.getText();

        //To verify home page as text contains "mngr79426"
        Assert.assertTrue(manageid.equals("Manger Id : mngr79426"));

1 个答案:

答案 0 :(得分:2)

您正在将值与webElement比较

Assert.assertTrue(manageid.equals("Manger Id : mngr79426"));

需要与文字进行比较。使用以下代码:

Assert.assertTrue(manageid.getText().equals("Manger Id : mngr79426"));

或者将测试存储在字符串中

String managerID = manageid.getText();

现在进行比较:

Assert.assertTrue(managerID.equals("Manger Id : mngr79426"));