Today I want to talk about a little tool which makes the life of us testers a bit easier.
It is called Junit params.

The  following situation happened with me not so long ago:
The dev team lead asked us a favor to make a set of quick and dirty smoke tests which tests different sites and check if some elements are present.
There are of course different approaches, if we are lucky the function is already automated and documented somewhere, and we just have to make it accessible and runnable by others too.

My a quick and dirty method is to copy my base webdriver project in which i have an already prepared test base file with the bare minimum for webdriver, i add the necessary pageobjects, then all we need to do is to create a junit test and add some parameters. For adding parameters, i prefer JUnit params. It is a a lightweigth tool, which extend Junit’s parametrization runner.

@RunWith(JUnitParamsRunner.class)
public class SampleTestClass  {
WebDriver driver;

// the trick is very simple, just define the parameters values as an array
@Test
@Parameters({"https://www.google.com/",
"http://www.wedoqa.com/" })
// String website will be the variable which will contain the parameter values
public void sampleTest(String website) {
driver = new ChromeDriver();

driver.get(website);

// check if logo element is present on the page
WebDriverWait driverWait = new WebDriverWait(driver, 10);
driverWait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#logo")));

driver.quit();

}

}

For more details and example checkout the JUnit params project on GitHub:
https://github.com/Pragmatists/junitparams

Posted By Tihomir Turzai

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>