DEV Community

Anne Quinkenstein
Anne Quinkenstein

Posted on • Edited on

Building a Selenium Framework

Create a Maven Project

1. Create new Maven Project

-> Maven - new Project - maven-quickstart - GroupID + ArtifactID

2. Add all Dependencies in pom.xml

Add from Maven Repro: Selenium & TestNG

3. Create Base and utility functions

Create base Class in main/java & add Browser Invocation

  • create a resources Package in main/java
  • create a file "data.properties" to store data in a central place store things like browser = chrome
  • envoce it in the base.file
Properties prop = Properties(); 
FileInputStream fis = new FileInputStream("//home//helloworld//Documents//Code//Ecplise//SampleProject//E2EProject//src//main//java//SampleProject//data.properties"); 
prop.load(fis);
String browsername = prop.getProperty("browser");
Enter fullscreen mode Exit fullscreen mode

Find absolute path of data.properties in rightclick Properties
put it in the FileInputStream

if (browserName == "chrome") 
{
            System.setProperty("webdriver.chrome.driver", "C://home//helloworld//chromedriver"); 
driver = new ChromeDriver(); 
} else if .... 
....
// instead of former implicitly Wait: 
new WebDriverWait(driver, Duration.ofSeconds(10));
return driver; 
Enter fullscreen mode Exit fullscreen mode

4. Organizing Page objects

  • Adding Tests
  • Datadriving/ Prameterizing Tests
  • Converting into TestNG Framework
  • TestNG Listeners
  • Screenshot on Test Failures
  • Creating Excellent HTML reports for Test Results
  • Jenkins Continuous Integration

Top comments (0)