天天看點

Java自動化測試系列[v1.0.0][資料驅動DPArray]

package testNGWithDataDriven;
 
import java.util.concurrent.TimeUnit;
import org.testng.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
 
public class TestNGDriven {
    private static WebDriver driver;
    @DataProvider(name="searchWords")
    public static Object[][] words(){
        return new Object[][]{{"蝙蝠俠","主演","邁克爾"},{"超人","導演","唐納"},{"生化危機","編劇","安德森"}};
    }
    @Test(dataProvider = "searchWords")
    public void test(String searchWord1, String searchWord2, String SearchResult){
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.sogou.com");
        driver.findElement(By.id("query")).sendKeys(searchWord1+" "+searchWord2);
        driver.findElement(By.id("stb")).click();
        try{
            Thread.sleep(3000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        Assert.assertTrue(driver.getPageSource().contains(SearchResult));
        driver.quit();
 
    }
}