簡體   English   中英

硒的成功和失敗消息

[英]Success and failure message with selenium

我正在用Selenium WebDrvier編寫測試腳本。 我對成功/失敗消息有疑問。 這是我大聲喊叫得到消息的部分代碼。 我不知道自己在哪里犯了錯誤,因此,如果有人可以幫助我,我將不勝感激。

WebElement msg=driver.findElement(By.xpath("/html/body/div[4]/div/div[1]/div/p"));
            String text=msg.getText();
            Object expectedText;
            Asserts.assertEquals(text,expectedText);
WebElement msg=driver.findElement(By.xpath("/html/body/div[4]/div/div[1]/div/p"));
// Get the text value of an element
String actualTxt = msg.getText();
// Expected [instead of Object expectedText ==> String expected]
String expecteTxt = "";
// Assertion (String, String)
Asserts.assertEquals(actualTxt,expectedTxt);

如果要斷言兩個字符串值,請嘗試通過以下方式斷言

void org.testng.Assert.assertEquals(String actual, String expected)
  • 定義:

     void org.testng.Assert.assertEquals(String actual, String expected) Asserts that two Strings are equal. If they are not, an AssertionError is thrown. Parameters: actual the actual value expected the expected value 
  • 您的代碼將是:

     import org.testng.Assert; WebElement msg = driver.findElement(By.xpath("/html/body/div[4]/div/div[1]/div/p")); String text = msg.getText(); Asserts.assertEquals(text,expectedText); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM