I am using page object pattern with java language.First step is driver initialization then go to login page.These steps are repeatable in every test pages.
Here is my code..
util
package util;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* Created by naveen on 29/11/16.
*/
public class DriverManager {
public static WebDriver driver;
String baseUrl="http://qmsadm.local";
public DriverManager()
{
System.setProperty("webdriver.chrome.driver","/home/naveen/chromedriver");
driver=new ChromeDriver();
driver.get(baseUrl);
driver.manage().window().maximize();
}
}
Test cases
package client;
import org.testng.Assert;
import org.testng.annotations.*;
import pageobjects.ClientPage;
import pageobjects.HomePage;
import steps.LoginSteps;
import steps.clientsteps;
import util.DriverManager;
import static util.DriverManager.driver;
public class clientTest {
@BeforeSuite(groups = {"regression"})
public void initDriver() {
DriverManager manager = new DriverManager();
LoginSteps loginSteps = new LoginSteps();
HomePage expected_message = loginSteps.Login("geosony", "1");
}
@Test
public void verifyValidLoginWithDataProvider() throws Exception {
clientsteps log = new clientsteps();
ClientPage ex = log.Valid("guru99","Test Group","ekm","active","1","2");
Assert.assertTrue(driver.getPageSource().contains("Hello Sony George"));
}
}
package steps;
import org.openqa.selenium.support.PageFactory;
import pageobjects.ClientPage;
import pageobjects.HomePage;
import util.DriverManager;
/**
* Created by srikanth on 20/11/16.
*/
public class LoginSteps {
public HomePage Login(String nam, String pas) {
HomePage homePageObj = PageFactory.initElements(DriverManager.driver, HomePage.class);
homePageObj.userLogin(nam,pas);
return homePageObj;
}
}
Here initdriver method. Every time for new test pages I want to write the same method again again. How to reduce the repeatable statement?