我創建了我的腳本來驗證我的實際結果和預期結果。從Excel中獲取元素
由於有太多的鏈接到驗證的腳本會得到太多的編碼m,所以我需要將其轉換爲數據驅動的情況。
Webdriver將從excel中獲取URL,xpath,期望值。
但是不知道如何繼續。
的演示代碼是非常讚賞
這裏是我當前的腳本:
public void test() throws Exception
{
String home_logo_url="158321";
String enough_talk_promo="1057406";
System.out.println("Check for home_logo_url");
driver.get(baseUrl);
String SiteWindow = driver.getWindowHandle(); // get the current window handle
driver.findElement(By.xpath("//*[@id='logo']/a")).click();
for (String PromoWindow : driver.getWindowHandles())
{
driver.switchTo().window(PromoWindow); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}
String script = "return rlSerial;";
String value = (String) ((JavascriptExecutor)driver).executeScript(script);
Assert.assertEquals(value,home_logo_url);
driver.close();
driver.switchTo().window(SiteWindow);
System.out.println("Pass");
System.out.println("Check for enough_talk_promo");
driver.get(baseUrl + "/category/tournaments/");
driver.findElement(By.xpath("//*[@id='content']/div/div[4]/aside/div/div/p[1]/a")).click();
for (String PromoWindow : driver.getWindowHandles())
{
driver.switchTo().window(PromoWindow); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}
String sr_enough_talk_promo = (String) ((JavascriptExecutor)driver).executeScript(script);
Assert.assertEquals(sr_enough_talk_promo,enough_talk_promo);
driver.close();
driver.switchTo().window(SiteWindow);
System.out.println("Pass");
}
如何迭代到各行,讓我運行測試用例!
如果有人可以將我現有的代碼轉換爲在Excel工作表上工作,這將非常有幫助。
感謝
您是否嘗試閱讀關於遍歷行和單元格的Apache POI文檔(http://poi.apache.org/spreadsheet/quick-guide.html#Iterator)? – Gagravarr
是的,我做了,但沒有得到如何進行,你能請把我現有的腳本轉換爲從excel中讀取所有元素,並做必要的斷言 –
你似乎誤以爲這個網站的某個地方爲你做你的工作...... :( – Gagravarr