1
셀레늄 1을 사용하여 데이터 기반 프레임 워크를 만들고 셀레늄 2 (WebDriver)를 사용하여 동일한 작업을 수행하려고했습니다. 나는 기본적인 R과 D를하고 있었다. 나의 코드는 아래와 같다.WebDriver에서 testNG를 사용하여 데이터 기반 테스트를 수행 할 수 있습니까?
그러나이 코드
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
import jxl.*;
@SuppressWarnings("unused")
public class FirstTestusingWebDriver {
private WebDriver driver;
private String baseUrl="http://www.google.co.in";
private StringBuffer verificationErrors = new StringBuffer();
@BeforeClass
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@DataProvider(name="DP")
Object[] createData(){
String[] testData = {"Cheese", "Sudeep"};
System.out.println("Data is getting created");
return testData;
}
@Test(dataProvider="DP")
public void testUntitled(String testData) throws Exception {
driver.get("http://www.google.co.in/");
driver.findElement(By.id("lst-ib")).clear();
driver.findElement(By.id("lst-ib")).sendKeys(testData);
driver.findElement(By.name("btnG")).click();
driver.findElement(By.linkText("Cheese - Wikipedia, the free encyclopedia")).click();
}
@AfterClass
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}, 테스트가 실행되고 있지 않습니다. testNG로 테스트를 실행하는 동안 Firefox가 열리고 닫힙니다. 누구든지 그것에 대해 갈 수있는 적절한 방법이나이 일을하는 방법을 제안 할 수 있습니까?