我是自動化測試的新手,m對assert和verify很困惑。因爲我使用TestNG,根據我的研究,我開始知道在webdriver中,我們沒有驗證,我們有硬性和軟性的斷言。但是當我搜索它時,我會得到所有不同的答案。我無處可以找到一個詳細的例子。 對於軟斷言,我看到有人使用'customverification',但是當我嘗試在我的程序中寫入時,出現錯誤,要求創建類或接口。 有人可以幫助我在這個。我正在通過互聯網學習,所以很難得到正確的答案。 感謝Webdriver的硬和軟斷言
package revision;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class Six {
WebDriver driver=new FirefoxDriver();
@Test
public void SandyOne() {
driver.get("file:///C:/Users/Sandeep%20S/Desktop/Test.html");
Assert.assertTrue(IsElementPresent(By.xpath("//input[@id='custom']")), "tab was missing");
driver.findElement(By.xpath("//input[@id='custom']")).sendKeys("abcd");
System.out.println("1st program");
System.out.println("blah 1");
System.out.println("blah 2");
}
public boolean IsElementPresent(By by) {
try {
driver.findElements(by);
return true;
} catch (org.openqa.selenium.NoSuchElementException e) {
return false;
}
}
}
你有什麼試過,結果是什麼?正如你在學校所做的那樣,請展示你的工作。 :)這是在SO上獲得問題的過程中的一部分。這對你很有幫助,因爲它會迫使你調查自己的問題並思考問題。這也向讀者證明你做了功課,並做出了合理的嘗試來回答你自己的問題。第三,它可以幫助讀者找到和診斷問題,爲您提供更好的答案,減少浪費時間。 – JeffC