Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.webmd.qa.utilities;
- import java.io.File;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.chrome.ChromeOptions;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.remote.DesiredCapabilities;
- /*
- @author siva.gullapalli
- This class provides various methods for browser operations
- */
- public class BrowserUtility {
- protected static WebDriver driver;
- protected static String currentDirectory = System.getProperty("user.dir");
- //This method launches a private chrome browser
- public void launchChromeIncognitoBrowser(String url) {
- try {
- String path = currentDirectory + File.separator + "testinputs" + File.separator + "chromedriver.exe";
- System.setProperty("webdriver.chrome.driver", path);
- ChromeOptions options = new ChromeOptions();
- options.addArguments("incognito");
- options.addArguments("start-maximized");
- DesiredCapabilities capabilities = DesiredCapabilities.chrome();
- capabilities.setCapability(ChromeOptions.CAPABILITY, options);
- driver = new ChromeDriver(capabilities);
- driver.get(url);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- //This method launches the url in chrome browser
- public void launchChromeBrowser(String url) {
- try {
- String path = currentDirectory + File.separator + "testinputs" + File.separator + "chromedriver.exe";
- System.setProperty("webdriver.chrome.driver", path);
- ChromeOptions options = new ChromeOptions();
- options.addArguments("start-maximized");
- DesiredCapabilities capabilities = DesiredCapabilities.chrome();
- capabilities.setCapability(ChromeOptions.CAPABILITY, options);
- driver = new ChromeDriver(capabilities);
- driver.get(url);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- //This method launches the url in firefox browser
- public void launchFirefoxBrowser(String url) {
- try {
- driver = new FirefoxDriver();
- driver.manage().window().maximize();
- driver.navigate().to(url);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- //Mobile browser - chrome, firefox
- //Tablet browser -chrome
- //String path=System.getProperty("user.dir")+"\\TestInputs\\chromedriver.exe";
- //System.setProperty("webdriver.chrome.driver", path);
- //ChromeOptions options = new ChromeOptions();
- //options.addArguments("--user-agent=Apple-iPhone5C1/1001.525");
- //DesiredCapabilities capabilities = DesiredCapabilities.chrome();
- //capabilities.setCapability("chromeOptions", options);
- //WebDriver driver = new ChromeDriver(capabilities);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement