Base class
package com.wbsn.mobile.env;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
public abstract class Browser{
private String browserName;
private String browserType;
private String browserBinary;
private String browserProfile;
public WebDriver browserDriver;
public String getBrowserName() {
return browserName;
}
public void setBrowserName(String browserName) {
this.browserName = browserName;
}
public String getBrowserType() {
return browserType;
}
public void setBrowserType(String browserType) {
this.browserType = browserType;
}
public String getBrowserBinary() {
return browserBinary;
}
public void setBrowserBinary(String browserBinary) {
this.browserBinary = browserBinary;
}
public String getBrowserProfile() {
return browserProfile;
}
public void setBrowserProfile(String browserProfile) {
this.browserProfile = browserProfile;
}
public abstract WebDriver getDriver();
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Chrome browser
package com.wbsn.mobile.env;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Chrome extends Browser {
public WebDriver getDriver(){
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
return new ChromeDriver(options);
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Firefox browser
package com.wbsn.mobile.env;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.FirefoxBinary;
public class Firefox extends Browser {
public void init() throws Exception{
//super.init();
}
public void close(){
//super.close();
}
public WebDriver getDriver(){
WebDriver driver;
FirefoxProfile firefoxProfile;
FirefoxBinary firefoxBinary;
if(this.getBrowserProfile()!=null && !this.getBrowserProfile().isEmpty()){
File profile=new File(this.getBrowserProfile());
firefoxProfile=new FirefoxProfile(profile);
if(this.getBrowserBinary()!=null && !this.getBrowserBinary().isEmpty()){
File binary=new File(this.getBrowserBinary());
firefoxBinary=new FirefoxBinary(binary);
driver=new FirefoxDriver(firefoxBinary, firefoxProfile);
return driver;
}
driver=new FirefoxDriver(firefoxProfile);
return driver;
}
driver=new FirefoxDriver();
return driver;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IE browser
package com.wbsn.mobile.env;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class IExplorer extends Browser {
public void init() throws Exception{
//super.init();
}
public void close(){
//super.close();
}
public WebDriver getDriver(){
return new InternetExplorerDriver();
}
}