[英]Verifying part of text in selenium webdriver
我在項目中使用Selenium Webdriver,在1種情況下,我需要驗證最后的String。
驗證 “這是測試事件”的文字
在瀏覽器中顯示的實際文本 “時間:2016年2月13日,星期六,下午7:00-8:00,下午(UTC-06:00),中部時間(美國和加拿大),其中:驅動labS
〜〜〜〜〜〜〜〜〜
此事件是測試事件”
我正在使用以下代碼進行驗證
public static final By EventDescription_locator= By.xpath("//*[@id='divBdy']");
public String VerifyEventDescription()
{
WebElement eventDescription=websitedriver.findElement(EventDescription_locator);
return eventDescription.getText().trim();
}
我在測試腳本中調用上述函數,如下所示
String description = "This event is a test event";
Assert.assertEquals(calendar_obj.VerifyEventDescription(), description, "[FAIL] Event with description "+description+" found");
Reporter.log("[PASS] Event with description "+description+" Not found <br/>");
使用assertEquals如何只驗證所需的特定文本。
請提出如何做到這一點。
為什么不能只使用.contains()方法?
Java.lang.String中包含contains(),它將有助於檢查指定字符串中的給定char序列,並且它返回的結果表示是真還是假。 例如
String str="murali selenium";
Assert.assertEquals(true, str.contains("selenium"),"custom message");
//or
Assert.assertTrue(str.contains("selenium"),"custom message");
System.out.println("true");
謝謝,穆拉利
請以以下格式使用。
Assert.assertEquals(“ String Description”,“ Event Description”);
只需遵循“預期與實際”的基本約定即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.