-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBrowserFactory.java
53 lines (43 loc) · 1.33 KB
/
BrowserFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package helperPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import utilityPackage.ConfigReader;
public class BrowserFactory {
//Global driver
public static WebDriver driver;
//@Parameters("browserName")
//A custom method to choose the browser on which the test need to be executed
public static void startBrowser(String browserName)
{
//choose Firefox browser
if (browserName.equalsIgnoreCase("firefox"))
{
driver = new FirefoxDriver();
}
//choose Chrome browser
else if (browserName.equalsIgnoreCase("chrome"))
{
System.setProperty("webdriver.chrome.driver", ConfigReader.getChromePath());
driver = new ChromeDriver();
}
//choose IE browser
else if (browserName.equalsIgnoreCase("ie"))
{
System.setProperty("webdriver.chrome.driver", ConfigReader.getChromePath());
driver = new InternetExplorerDriver();
}
//choose Headless browser
if (browserName.equalsIgnoreCase("headless"))
{
driver = new HtmlUnitDriver();
}
//maximize browser
driver.manage().window().maximize();
//launch the url
driver.get(ConfigReader.getURL());
}
}