Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package org.webmd.qa.utilities;
  2.  
  3. import java.io.File;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.chrome.ChromeDriver;
  6. import org.openqa.selenium.chrome.ChromeOptions;
  7. import org.openqa.selenium.firefox.FirefoxDriver;
  8. import org.openqa.selenium.remote.DesiredCapabilities;
  9.  
  10. /*
  11. @author siva.gullapalli
  12. This class provides various methods for browser operations
  13. */
  14. public class BrowserUtility {
  15.  
  16. protected static WebDriver driver;
  17. protected static String currentDirectory = System.getProperty("user.dir");
  18.  
  19. //This method launches a private chrome browser
  20. public void launchChromeIncognitoBrowser(String url) {
  21. try {
  22. String path = currentDirectory + File.separator + "testinputs" + File.separator + "chromedriver.exe";
  23. System.setProperty("webdriver.chrome.driver", path);
  24. ChromeOptions options = new ChromeOptions();
  25. options.addArguments("incognito");
  26. options.addArguments("start-maximized");
  27. DesiredCapabilities capabilities = DesiredCapabilities.chrome();
  28. capabilities.setCapability(ChromeOptions.CAPABILITY, options);
  29. driver = new ChromeDriver(capabilities);
  30. driver.get(url);
  31. }
  32. catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. //This method launches the url in chrome browser
  38. public void launchChromeBrowser(String url) {
  39. try {
  40. String path = currentDirectory + File.separator + "testinputs" + File.separator + "chromedriver.exe";
  41. System.setProperty("webdriver.chrome.driver", path);
  42. ChromeOptions options = new ChromeOptions();
  43. options.addArguments("start-maximized");
  44. DesiredCapabilities capabilities = DesiredCapabilities.chrome();
  45. capabilities.setCapability(ChromeOptions.CAPABILITY, options);
  46. driver = new ChromeDriver(capabilities);
  47. driver.get(url);
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. //This method launches the url in firefox browser
  54. public void launchFirefoxBrowser(String url) {
  55. try {
  56. driver = new FirefoxDriver();
  57. driver.manage().window().maximize();
  58. driver.navigate().to(url);
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. }
  62. }
  63. }
  64.  
  65.  
  66. //Mobile browser - chrome, firefox
  67. //Tablet browser -chrome
  68.  
  69. //String path=System.getProperty("user.dir")+"\\TestInputs\\chromedriver.exe";
  70. //System.setProperty("webdriver.chrome.driver", path);
  71. //ChromeOptions options = new ChromeOptions();
  72. //options.addArguments("--user-agent=Apple-iPhone5C1/1001.525");
  73. //DesiredCapabilities capabilities = DesiredCapabilities.chrome();
  74. //capabilities.setCapability("chromeOptions", options);
  75. //WebDriver driver = new ChromeDriver(capabilities);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement