Reputation: 97
Seems I'm not enough smart to figure it out by myself - I have Eclipse Kepler installed, with jUnit 4.11, selenium-java 2.41 and a mozilla plugin for selenium.
Everything is great, everything (at this moment) works great. My aim is to create a test, that repeats n times, everytime using the second String[] array element. For example:
`@Test
public void testGoogleSearch() throws Exception {
driver.get(baseUrl);
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("Find me"); // Input text from String array here
driver.findElement(By.id("gbqfb")).click();
try {
assertEquals("Find me", driver.findElement(By.id("gbqfq")).getAttribute("value"));
} catch (Error e) {
verificationErrors.append(e.toString());
}
}`
As you can see, there is static "Find me" text. I want, that my test will run 5 times, each time input changes to early defined array elements.
How can i do that? Any clues? I've read about parametrized testing, but does it really is that i need? I didn't found anything there about multiple repeating.
Any help would be great. Thank you.
Upvotes: 1
Views: 156
Reputation: 5072
I've read about parametrized testing, but does it really is that i need?
Yes, it is exactly what you need. Parameterized.class:
@RunWith(Parameterized.class)
public class GoogleSearchClass {
private String searchString;
private String expectedString;
public GoogleSearchClass (String srch, String expect){
searchString = srch;
expectedString = expect;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"search1", "expected1"}, {"search2", "expected2"}, {"search3", "expected3"}
});
}
@Test
public void testGoogleSearch() throws Exception {
driver.get("http://google.com");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys(searchString); // Input text from String array here
driver.findElement(By.id("gbqfb")).click();
try {
// Assert.assertEquals(expectedString, driver.findElement(By.id("gbqfq")).getAttribute("value"));
} catch (AssertionError e) {
}
}
}
Upvotes: 1