List of usage examples for org.openqa.selenium.chrome ChromeDriver ChromeDriver
public ChromeDriver()
From source file:com.palmetto.testautomation.regression.PalmettoVolunteerRegressionTests.java
@Before public void setUp() throws Exception { System.setProperty(PalmettoTestAutomationProperties.CHROME_DRIVER, PalmettoTestAutomationProperties.CHROME_DRIVER_PATH); driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get(PalmettoTestAutomationProperties.URL); Volunteer = new PalmettoVolunteerPageObject(driver); util = new PalmettoTestAutomationUtilities(); }
From source file:com.Priyanka.junitProgramsTests.alertNewWindow.java
@Before public void testSetup() { System.setProperty("webdriver.chrome.driver", "src/main/java/com/Priyanka/webDrivers/chromedriver.exe"); driver = new ChromeDriver(); driver.manage().window().maximize(); }
From source file:com.raja.anucarita.SeWrapper.java
License:Open Source License
public static WebDriver getDriver() throws Exception { if (Browser.equals("Firefox")) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("capability.policy.default.Window.QueryInterface", "allAccess"); profile.setPreference("capability.policy.default.Window.frameElement.get", "allAccess"); driver = new FirefoxDriver(profile); } else if (Browser.equals("IE")) { driver = new InternetExplorerDriver(); } else if (Browser.equals("GoogleChrome")) { System.setProperty("webdriver.chrome.driver", values.getProperty("GoogleChromeLocation")); driver = new ChromeDriver(); } else {/*from w w w. ja v a2 s. co m*/ throw new Exception("Browser String is wrong"); } return driver; }
From source file:com.safeway.app.appcert.smoketester.SmokeTester.java
@Test public void executeSmokeTest() throws Exception { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. System.setProperty("webdriver.chrome.driver", "C:\\Nino\\ChromeWebDriver\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); TestCaseReader tcreader = new TestCaseReader(); List<TestScriptTemplate> tcl = tcreader.readExcel(); List<TestScriptTemplate> validatedTestScript = new ArrayList(); String log_execution = ""; Iterator<TestScriptTemplate> i = tcl.iterator(); while (i.hasNext()) { TestScriptTemplate testscript = i.next(); //collect the results TestScriptTemplate testexecution = new TestScriptTemplate(); testexecution.setAppCode(testscript.getAppCode()); log_execution = log_execution + " Start smoke testing for application code: " + testexecution.getAppCode(); //access the URL driver.get(testscript.getAppURL()); //login if not yet if (driver.getCurrentUrl().contains("identity.safeway.com")) { //key in userid and password WebElement weusername = driver.findElement(By.id("username")); //System.out.println("tag:" + weusername.getTagName()); weusername.sendKeys(testscript.getAppUserID()); WebElement wepassword = driver.findElement(By.id("password")); //System.out.println("tag:" + wepassword.getTagName()); wepassword.sendKeys(testscript.getAppPassword()); WebElement weloginform = driver.findElement(By.name("loginData")); //System.out.println("tag:" + weloginform.getTagName()); weloginform.submit();// w ww . j a v a2 s . c o m } //recoding URL; required so no need to check for nullity testexecution.setAppURL(driver.getCurrentUrl()); log_execution = log_execution + " Current URL: " + driver.getCurrentUrl(); //recoding title; required so no need to check for nullity testexecution.setHomePageTitle(driver.getTitle()); log_execution = log_execution + " Login Successful"; log_execution = log_execution + " Page Title: " + driver.getTitle(); if (isElementExist(testscript.getHomePageElementType(), testscript.getHomePageElement(), driver)) { System.out.println("Element match!" + testscript.getHomePageElement()); log_execution = log_execution + " Home Page Element validation..."; testexecution.setHomePageElement(testscript.getHomePageElement()); } else { testexecution.setHomePageElement("not found"); } //next page validation if (!testscript.getLevel1URL().isEmpty() || !testscript.getLevel1URL().equals("")) { //go to next level page driver.get(testscript.getLevel1URL()); log_execution = log_execution + " Next Page validation URL: " + testscript.getLevel1URL(); testexecution.setLevel1URL(driver.getCurrentUrl()); System.out.println("execution log: current level 1 URL on set" + testexecution.getLevel1URL()); if (!testscript.getLevel1PageTitle().isEmpty() || !testscript.getLevel1PageTitle().equals("")) { testexecution.setLevel1PageTitle(driver.getTitle()); log_execution = log_execution + " Next Page title validation: " + driver.getTitle(); } if (isElementExist(testscript.getLevel1ElementType(), testscript.getLevel1Element(), driver)) { testexecution.setLevel1Element(testscript.getLevel1Element()); log_execution = log_execution + " Next Page element validation: " + testscript.getLevel1Element(); } else { testexecution.setLevel1Element("not found"); } } testexecution.setLogs(log_execution); System.out.println("Execution Log: " + log_execution); log_execution = ""; SmokeTestValidator testvalidator = new SmokeTestValidator(testscript); TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution); validatedTestScript.add(testingresult); } tcreader.writetoExcel(validatedTestScript); //Close the browser driver.quit(); //return log_execution; }
From source file:com.sat.dbds.utils.selenium.SeleniumUtilities.java
License:Open Source License
/** * Opens the Firefox instance for Selenium. *//*from w ww . ja v a 2s . co m*/ public static void openBrowser() { if (System.getProperty("run.type") == null || System.getProperty("run.type").equalsIgnoreCase("WUI")) { if (getDriver() != null) System.out.println(getDriver().toString() + "hi"); if (getDriver() == null || (!getDriver().toString().contains("-"))) { try { String browser = Validate.readsystemvariable("browser"); LogHandler.info("Browser:" + browser); String digest = Validate.readsystemvariable("browser.digest"); LogHandler.info("Digest Auth:" + digest); if (browser.equals("firefox") && digest.toUpperCase().equals("YES")) { LogHandler.info("Fire Fox Driver with addon configuration"); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.link.open_newwindow", 2); File extentions = new File(System.getProperty("user.dir") + Validate.readsystemvariable("firefox.addons.path")); if (extentions.exists()) { for (File extention : extentions.listFiles()) { if (extention.getName().endsWith(".xpi")) { try { profile.addExtension(new File(extention.getAbsolutePath())); } catch (IOException e) { Assert.assertTrue( "Exception occured while adding the extension to the profile..", false); } LogHandler.info("Added extention: " + extention.getName()); } } } driver = new FirefoxDriver(profile); } else if (browser.equals("firefox") && digest.toUpperCase().equals("NO")) { LogHandler.info("Fire Fox Driver without addon configuration"); driver = new FirefoxDriver(); } else if (browser.equals("chrome")) { LogHandler.info("Chrome Driver configuration"); JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class); jarfilehandler.copyResourcesToDirectory(jarFile, "chrome", "src/it/resources/chrome"); System.setProperty("webdriver.chrome.driver", "src/it/resources/chrome/chromedriver.exe"); driver = new ChromeDriver(); } else if (browser.equals("IE")) { LogHandler.info("IE Driver configuration"); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); String IEpath = (SeleniumUtilities.class).getResource("").getPath(); System.out.println(IEpath.substring(0, IEpath.length() - 31)); capabilities.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class); // JarFile jarFile = new // JarFile("C:\\Users\\amsathishkumar\\.m2\\repository\\com\\cisco\\dbds\\Utils\\0.0.1-Release\\Utils-0.0.1-Release.jar"); jarfilehandler.copyResourcesToDirectory(jarFile, "internetexplorer", "src/it/resources/InternetExplorer"); System.setProperty("webdriver.ie.driver", "src/it/resources/internetexplorer/IEDriverServer.exe"); driver = new InternetExplorerDriver(capabilities); // driver = new InternetExplorerDriver(); } else { Assert.assertTrue("include the browswer variable...", false); } } catch (Exception e) { LogHandler.info("Check the varaiables: browser,firefox.addons.path,user.dir"); } // driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); // driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(Integer.parseInt(System.getProperty("implicit.wait")), TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(System.getProperty("explicit.wait")), TimeUnit.SECONDS); System.out.println(getDriver().toString() + "hi"); } } }
From source file:com.sat.spvgt.utils.selenium.SeleniumUtilities.java
License:Open Source License
/** * Opens the Firefox instance for Selenium. *///from w w w. jav a 2 s . com public static void openBrowser() { if (System.getProperty("run.type") == null) { try { if (getDriver() == null || (!getDriver().toString().contains("-"))) { String browser = miscValidate.readsystemvariable("browser"); LogHandler.info("Browser:" + browser); String digest = miscValidate.readsystemvariable("browser.digest"); LogHandler.info("Digest Auth:" + digest); if (browser.equals("firefox") && digest.toUpperCase().equals("YES")) { LogHandler.info("Fire Fox Driver with addon configuration"); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.link.open_newwindow", 2); File extentions = new File(System.getProperty("user.dir") + miscValidate.readsystemvariable("firefox.addons.path")); if (extentions.exists()) { for (File extention : extentions.listFiles()) { if (extention.getName().endsWith(".xpi")) { try { profile.addExtension(new File(extention.getAbsolutePath())); } catch (IOException e) { Assert.assertTrue( "Exception occured while adding the extension to the profile..", false); } LogHandler.info("Added extention: " + extention.getName()); } } } driver = new FirefoxDriver(profile); } else if (browser.equals("firefox") && digest.toUpperCase().equals("NO")) { LogHandler.info("Fire Fox Driver without addon configuration"); driver = new FirefoxDriver(); } else if (browser.equals("chrome")) { LogHandler.info("Chrome Driver configuration"); JarFile jarFile = miscJarfileHandler.jarForClass(SeleniumUtilities.class); miscJarfileHandler.copyResourcesToDirectory(jarFile, "chrome", "src/it/resources/chrome"); System.setProperty("webdriver.chrome.driver", "src/it/resources/chrome/chromedriver.exe"); driver = new ChromeDriver(); } else if (browser.equals("IE")) { LogHandler.info("IE Driver configuration"); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); String IEpath = (SeleniumUtilities.class).getResource("").getPath(); System.out.println(IEpath.substring(0, IEpath.length() - 31)); capabilities.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); JarFile jarFile = miscJarfileHandler.jarForClass(SeleniumUtilities.class); // JarFile jarFile = new // JarFile("C:\\Users\\amsathishkumar\\.m2\\repository\\com\\cisco\\dbds\\Utils\\0.0.1-Release\\Utils-0.0.1-Release.jar"); miscJarfileHandler.copyResourcesToDirectory(jarFile, "internetexplorer", "src/it/resources/InternetExplorer"); System.setProperty("webdriver.ie.driver", "src/it/resources/internetexplorer/IEDriverServer.exe"); driver = new InternetExplorerDriver(capabilities); // driver = new InternetExplorerDriver(); } else { Assert.assertTrue("include the browswer variable...", false); } } } catch (Exception e) { LogHandler.info("Check the varaiables: browser,firefox.addons.path,user.dir"); } // driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); // driver.manage().timeouts().setScriptTimeout(10, // TimeUnit.SECONDS); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(Integer.parseInt(System.getProperty("implicit.wait")), TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(System.getProperty("explicit.wait")), TimeUnit.SECONDS); } }
From source file:com.sios.stc.coseng.util.Run.java
License:Open Source License
public synchronized WebDriver getWebDriver(final String testName) throws MalformedURLException { WebDriver driver = null;//from w w w .ja va 2 s. c o m if (testName != null) { for (final TestParam p : param.testParam) { if (p.getTestName().equals(testName)) { // DesiredCapabilities // https://code.google.com/p/selenium/wiki/DesiredCapabilities // !! It is *not* necessary to start *any* of the browser driver // profiles to start 'private/icognito' as each new driver // instance starts with a *fresh* profile that does not persist // after the driver is quit. !! if (p.getBrowser().equals(Browser.FIREFOX)) { final FirefoxProfile profile = new FirefoxProfile(); final DesiredCapabilities dc = DesiredCapabilities.firefox(); if (p.getPlatform().equals(Platform.LINUX)) { // Explicitly enable native events(this is mandatory on Linux system, // since they are not enabled by default. profile.setEnableNativeEvents(true); dc.setPlatform(p.getPlatform()); dc.setCapability(Common.BROWSER_CAPABILITY_FIREFOX_PROFILE, profile); } if (p.getSpot().equals(Spot.LOCAL)) { driver = new FirefoxDriver(profile); } else { driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc); } } else if (p.getBrowser().equals(Browser.CHROME)) { final DesiredCapabilities dc = DesiredCapabilities.chrome(); dc.setPlatform(p.getPlatform()); if (p.getSpot().equals(Spot.LOCAL)) { driver = new ChromeDriver(); } else { driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc); } } else if (p.getBrowser().toString().toLowerCase().startsWith("ie")) { final DesiredCapabilities dc = DesiredCapabilities.internetExplorer(); dc.setBrowserName(Common.BROWSER_NAME_INTERNET_EXPLORER); dc.setPlatform(p.getPlatform()); // IE8 and newer; Make sure // HKEY_USERS\.Default\Software\Microsoft\Internet // Explorer has DWORD TabProcGrowth set 0 // Launch separate process in 'private' mode. dc.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true); dc.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private"); //dc.setCapability(InternetExplorerDriver.LOG_FILE, // "C:/iedriver.log"); //dc.setCapability(InternetExplorerDriver.LOG_LEVEL, // "DEBUG"); dc.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true); // dc.setCapability( // InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, // true); // If *is* a specific IE9, IE10, IE11 (not IE) set the version if (!p.getBrowser().equals(Browser.IE)) { dc.setVersion(p.getBrowser().getVersion()); } if (p.getSpot().equals(Spot.LOCAL)) { driver = new InternetExplorerDriver(); } else { driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc); } } } // Collect the driver for quit after tests complete if (driver != null) { collectDriver(driver); } } } return driver; }
From source file:com.sol.browser.DriverFactory.java
License:Apache License
/** * Returns an instance of the requested WebDriver. * This method also sets the implicite waiting time according to the * property in the property file./*ww w .j a v a2 s.c o m*/ * @param driverType - name of the requested driver * @return if the requested driver is valid, returns an instant of the * requested driver. If the requested driver is invalid, null is returned. * @throws FileNotFoundException if property file is not found * @throws IOException * @throws NullPointerException if {@code browser} is {@code null} * @throws IllegalArgumentException if the driver type is not one of the * following: Chrome, Firefox, or HTMLUnit. * <br><b>Note:</b> The following keys <em>must</em> be present in the * properties file (and containing values): the <em>absolute</em> path * to the requested WebDriver (in case of ChromeDriver), and the default * waiting time for the implicit wait. Missing keys may cause undefined * behavior. * @see BrowserPropertyFile */ public static WebDriver getDriver(final DriverType driverType) throws FileNotFoundException, IOException, NullPointerException, IllegalArgumentException { Objects.requireNonNull(driverType); WebDriver driver = null; BrowserPropertyFile properties = BrowserPropertyFile.getInstance(); switch (driverType) { case CHROME: String pathToDriver = properties.getProperty(BrowserPropertyConstants.PATH_TO_DRIVER); System.setProperty("webdriver.chrome.driver", pathToDriver); driver = new ChromeDriver(); break; case FIREFOX: driver = new FirefoxDriver(); break; case HTMLUNIT: driver = new HtmlUnitDriver(); break; default: throw new IllegalArgumentException("Illegal driver type"); } String waitingTime = properties.getProperty(BrowserPropertyConstants.IMPLICITE_WAITING_TIME); long implicitWaitingTime = Long.parseLong(waitingTime); driver.manage().timeouts().implicitlyWait(implicitWaitingTime, TimeUnit.SECONDS); return driver; }
From source file:com.springer.omelet.driver.DriverFactory.java
License:Apache License
/*** * Return WebDriver either Remote/BrowserStack or local Browser based on * remoteFlag/*from w w w . j a v a 2 s .c o m*/ * * @return */ public WebDriver intializeDriver() { if (remoteFlag) { RemoteBrowser rb = this.new RemoteBrowser(); webDriver = rb.returnRemoteDriver(); } else if (browser.toLowerCase().startsWith("f")) { LOGGER.debug("Returning firefox driver-Without Remote."); webDriver = new FirefoxDriver(); } else if (browser.toLowerCase().startsWith("i")) { System.setProperty("webdriver.ie.driver", ieServerPath); LOGGER.debug("Returning ie driver-Without Remote."); webDriver = new InternetExplorerDriver(); } else if (browser.toLowerCase().startsWith("c")) { System.setProperty("webdriver.chrome.driver", chromeServerPath); LOGGER.debug("Returning chrome driver-Without Remote."); webDriver = new ChromeDriver(); } else if (browser.toLowerCase().startsWith("h")) { LOGGER.info("Browser is HTMLUNIT"); webDriver = new HtmlUnitDriver(); } // For maximizing driver windows and wait if (webDriver != null) { if (this.isMobileTest == false) { webDriver.manage().window().maximize(); } webDriver.manage().timeouts().implicitlyWait(driverTimeOut, TimeUnit.SECONDS); } if (ishiglightElementFlag) { EventFiringWebDriver efw = new EventFiringWebDriver(webDriver); efw.register(new MyWebDriverListner()); webDriver = efw; } return webDriver; }
From source file:com.thoughtworks.selenium.corerunner.Main.java
License:Apache License
public static void main(String[] args) { // java -jar selenium-server-standalone-<version-number>.jar -htmlSuite "*firefox" // "http://www.google.com" "c:\absolute\path\to\my\HTMLSuite.html" // "c:\absolute\path\to\my\results.html" if (args.length < 5) { throw new RuntimeException("Not enough arguments"); }//w w w . j a va 2s. c om if (!"-htmlSuite".equals(args[0])) { throw new RuntimeException("Apparently not running a test suite"); } WebDriver driver; switch (args[1]) { case "*chrome": case "*firefox": case "*firefoxproxy": case "*firefoxchrome": case "*pifirefox": DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MARIONETTE, false); driver = new FirefoxDriver(caps); break; case "*iehta": case "*iexplore": case "*iexploreproxy": case "*piiexplore": driver = new InternetExplorerDriver(); break; case "*googlechrome": driver = new ChromeDriver(); break; case "*MicrosoftEdge": driver = new EdgeDriver(); break; case "*opera": case "*operablink": driver = new OperaDriver(); break; case "*safari": case "*safariproxy": driver = new SafariDriver(); break; default: throw new RuntimeException("Unrecognized browser: " + args[1]); } try { Results results = new Results(); CoreTest test = new CoreTest(args[3]); test.run(results, driver, new WebDriverBackedSelenium(driver, args[2])); } finally { driver.quit(); } }