1

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.

1 Answer 1

1

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) {
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Hmm... so i suppose that @..Parameters automatically passes data to @Test? By the way, what for is dsgsd() method? is it meant as a constructor?
Parameterized.class will loop thru all the parameters you have in the collection. Try it out. And sry for the type, fixed it.
Yep, thats the solution! Thank you... Seems that 11-hour continious learning made a peanut of my brain. Accepting answer =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.