List of usage examples for org.openqa.selenium.chrome ChromeDriver ChromeDriver
public ChromeDriver()
From source file:com.thoughtworks.selenium.SeleneseTestNgHelperVir.java
License:Apache License
/** * Start browser session.//from ww w . j a v a 2s .c o m * * @param browserString * the browser string */ public final void startBrowserSession(final String browserString) { DesiredCapabilities capabilities = getWebDriverCapabilities(); WebDriver driver; if (browserString.contains("chrome") || browserString.contains("Chrome")) { driver = new ChromeDriver(); } else if (browserString.contains("safari")) { DesiredCapabilities.safari(); driver = new SafariDriver(capabilities); } else if (browserString.contains("iexplore")) { DesiredCapabilities.internetExplorer(); capabilities.setJavascriptEnabled(true); driver = new InternetExplorerDriver(capabilities); } else if (browserString.contains("firefox")) { FirefoxProfile profile = getDefaultProfile(); profile.setEnableNativeEvents(true); driver = new FirefoxDriver(profile); } else if (browserString.contains("opera")) { DesiredCapabilities.opera(); driver = new OperaDriver(capabilities); } else { getLog().info("Unsupported browser type passed " + browserString); throw new AssertionError("Unsupported Browser"); } setDriver(driver); if (getSeleniumInstances().isEmpty()) { putSeleniumInstances("default", driver); } else { putSeleniumInstances(getSeleniumInstanceName(), driver); } }
From source file:com.thoughtworks.webanalyticsautomation.scriptrunner.helper.WebDriverScriptRunnerHelper.java
License:Open Source License
@Override public void startDriver() { String os = System.getProperty("os.name").toLowerCase(); logger.info("Starting WebDriver on OS: " + os + " for browser: " + browser.name()); if (browser.equals(BROWSER.firefox)) { DesiredCapabilities capabilities = new DesiredCapabilities(); instantiateFireFoxDriver(capabilities); } else if (browser.equals(BROWSER.iehta)) { if (!os.contains("win")) { throw new SkipException( "Skipping this test as Internet Explorer browser is NOT available on " + os); }/*from w ww.ja va 2 s. c om*/ driver = new InternetExplorerDriver(); driver.get(BASE_URL); } else if (browser.equals(BROWSER.chrome)) { driver = new ChromeDriver(); driver.get(BASE_URL); } logger.info("Driver started: " + browser.name()); logger.info("Page title: " + driver.getTitle()); }
From source file:com.tricentis.automobileinsurance.utility.AutomobileUtil.java
/** * /*w ww . java 2 s. co m*/ * @param browserName */ public void setEnvironment(String browserName) { if (browserName.equalsIgnoreCase("firefox")) { /*Open firefox browser*/ System.setProperty(AutomobileConstant.FIREFOXDRIVER_KEY, AutomobileConstant.FIREFOXDRIVER_VALUE); driver = new FirefoxDriver(); } else if (browserName.equalsIgnoreCase("chrome")) { System.setProperty(AutomobileConstant.CHROMEDRIVER_KEY, AutomobileConstant.CHROMEDRIVER_VALUE); driver = new ChromeDriver(); } else { System.setProperty(AutomobileConstant.IEDRIVER_KEY, AutomobileConstant.IEDRIVER_VALUE); driver = new InternetExplorerDriver(); } /*implicit wait*/ driver.manage().timeouts().implicitlyWait(AutomobileConstant.IMPLICIT_WAIT, TimeUnit.SECONDS); /*maximize browser window*/ driver.manage().window().maximize(); /* hit the application URL*/ driver.get(AutomobileConstant.APPLICATION_URL); action = new Actions(driver); }
From source file:com.twiceagain.rservejavademo.webaccess.BasicDriver.java
License:Open Source License
/** * Return a valid driver/* ww w.j a v a2 s . com*/ * * @return */ public static WebDriver getDriver() { // Required to help locate the binary that needs to be downloaded manually :-( // See : https://sites.google.com/a/chromium.org/chromedriver/getting-started System.setProperty("webdriver.chrome.driver", "/home/xavier/bin/chromedriver"); return new ChromeDriver(); }
From source file:com.vilt.minium.script.test.WebElementsDriverConfig.java
License:Apache License
@Bean(destroyMethod = "quit") public DefaultWebElementsDriver wd() throws MalformedURLException { String remoteWebDriverUrl = System.getProperty("remote.web.driver.url"); WebDriver webDriver;// w w w . ja va2s. co m if (remoteWebDriverUrl != null) { webDriver = new RemoteWebDriver(new URL(remoteWebDriverUrl), DesiredCapabilities.chrome()); webDriver = new Augmenter().augment(webDriver); } else { try { webDriver = new ChromeDriver(); } catch (Exception e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Chrome driver not found or could not be launched, using Firefox driver instead (set log level to debug to check the exception)", e); } else { LOGGER.warn( "Chrome driver not found or could not be launched, using Firefox driver instead (set log level to debug to check the exception)"); } webDriver = new FirefoxDriver(); } } return new DefaultWebElementsDriver(webDriver); }
From source file:com.waku.mmdataextract.SalesIssues2.java
License:Open Source License
/** * @param args/*from w w w. j a v a 2s. co m*/ * @throws Exception */ public static void main(String[] args) throws Exception { String formUrl = "http://shouji.gd.chinamobile.com/gdmobile/productDetail/operatorssalesHeaderAction.do"; String fromUrl2 = "http://shouji.gd.chinamobile.com/gdmobile/productDetail/operatorssalesHeaderAction.do?provinceID=1&cityID="; String baseUrl = "http://shouji.gd.chinamobile.com/gdmobile/productDetail/operatorssalesSearchAction.do?type=1&brandId=0&productId=0&provinceId=1"; WebDriver driver = new ChromeDriver(); // Get the citySet from form url System.out.println("Go to url => " + formUrl); driver.get(formUrl); WebElement citySelector = driver.findElement(By.id("cityID")); List<WebElement> cityOptions = citySelector.findElements(By.tagName("option")); Map<String, String> cityIdNameMap = new HashMap<String, String>(); for (WebElement cityOption : cityOptions) { cityIdNameMap.put(cityOption.getAttribute("value"), cityOption.getText()); } System.out.println("Find cities: \n" + cityIdNameMap); // A class to hold Sales issue id and name class SalesIssue { @Override public String toString() { return id + ":" + name; } public SalesIssue(String id, String name) { this.id = id; this.name = name; } String id; String name; } // Get sales issues info Map<String, Set<SalesIssue>> citySalesIssueMap = new HashMap<String, Set<SalesIssue>>(); for (String cityId : cityIdNameMap.keySet()) { String cityUrl = fromUrl2 + cityId; driver.get(cityUrl); System.out.println("Go to url => " + cityUrl); WebElement salesIssueSelector = driver.findElement(By.id("salesissue")); List<WebElement> salesIssueOptions = salesIssueSelector.findElements(By.tagName("option")); if (salesIssueOptions.get(0).getAttribute("value").equals("0")) { System.out.println("No sales issues for " + cityIdNameMap.get(cityId)); } else { Set<SalesIssue> salesIssueSet = new HashSet<SalesIssue>(); for (WebElement salesIssueOption : salesIssueOptions) { SalesIssue salesIssue = new SalesIssue(salesIssueOption.getAttribute("value"), salesIssueOption.getText()); salesIssueSet.add(salesIssue); } citySalesIssueMap.put(cityId, salesIssueSet); System.out.println("Find sales issues: \n" + citySalesIssueMap); } } for (String cityId : cityIdNameMap.keySet()) { for (SalesIssue salesIssue : citySalesIssueMap.get(cityId)) { String finalUrl = baseUrl + "&cityId=" + cityId + "&salesissue=" + salesIssue.id; driver.get(finalUrl); System.out.println("Go to url => " + finalUrl); System.out .println("Province,,City," + cityIdNameMap.get(cityId) + ",Sales," + salesIssue.name); System.out.println(driver.getPageSource()); } } }
From source file:com.waku.mmdataextract.SalesIssues3.java
License:Open Source License
public static void main(String[] args) throws Exception { FileWriter fw = new FileWriter("Output.csv"); Map<String, String> cityIdNameMap = new HashMap<String, String>(); Map<String, Set<SalesIssue>> citySalesIssueMap = new HashMap<String, Set<SalesIssue>>(); String cityMapString = "116=??, 125=, 117=, 127=, 114=, 115=?, 112=?, 122=, 113=, 110=, 123=, 124=?, 230=, 272=?, 129=, 118=, 119=, 109=, 107=, 106=, 105=, 104="; String[] cityMaps = cityMapString.split(", "); for (String cityMap : cityMaps) { String[] cityIdName = cityMap.split("="); cityIdNameMap.put(cityIdName[0], cityIdName[1]); }//from w w w . j a v a2 s. c om String salesIssues = "113=[310,471:?--20110101, 311,310:--20101116, 156,133:?--?20108, 154,132:?3G--20108, 312,469:?--20110101, 149,171:??--20100907, 217,235:??--HZ20101012, -1:?, 311,470:--20110101, 312,311:?--20101116, 156,231:?--HZ20101012, 216,234:?--HZ20101012, 310,309:?--20101116, 215,472:?--20110101, 215,233:?--HZ20101012, 149,129:??--20108, 156,170:?--20100907, 149,232:??--HZ20101012, 154,169:?3G--20100907, 154,212:?3G--HZ20101012], 107=[250,449:?--20110101, 250,369:?--20101215, 250,251:?--20101018, -1:?, 190,190:?--20100825, 249,249:?--20101018, 229,350:--20101215, 189,189:?8+1--20100825, 249,349:?--20101215, 229,230:--20101015, 249,450:?--20110101, 229,451:--20110101], 106=[209,209:?--20101010, 210,210:?--20101010, 210,510:?--20110101, 211,511:--20110101, 209,390:?--20101216, 211,211:--20101010, 209,509:?--20110101, 210,389:?--20101216, 211,391:--20101216, -1:?], 105=[46,46:5--0507, 45,45:?--?, 44,44:?9?--20100507, -1:?], 104=[-1:?, 66,64:?--20100624, 23,107:?0--20100721, 66,108:?--20100721, 23,23:?0--201000624, 68,65:0--2G20100624, 271,270:--20101020, 290,430:--20110101, 290,289:--20101109, 269,269:?--20101020, 68,149:0--20100830, 66,151:?--20100830, 273,271:--20101020, 23,150:?0--20100830, 269,429:?--20110101], 119=[104,329:?--20101209, 291,409:--20101223, 291,489:--20110101, 124,229:?--20101014, -1:?, 124,490:?--20110101, 124,104:?--20100714, 291,290:--20101109, 104,84:?--20100708"; String[] forCity = salesIssues.split("], "); for (String eachCity : forCity) { String cityId = eachCity.substring(0, eachCity.indexOf("=")); String salesIssuesForCity = eachCity.substring(eachCity.indexOf("=") + 2); Set<SalesIssue> salesIssueSet = new HashSet<SalesIssue>(); for (String eachSales : salesIssuesForCity.split(", ")) { String[] a = eachSales.split(":"); if (!a[0].equals("-1")) { SalesIssue salesIssue = new SalesIssue(a[0], a[1]); salesIssueSet.add(salesIssue); } } citySalesIssueMap.put(cityId, salesIssueSet); } String baseUrl = "http://shouji.gd.chinamobile.com/gdmobile/productDetail/operatorssalesSearchAction.do?type=1&brandId=0&productId=0&provinceId=1"; WebDriver driver = new ChromeDriver(); for (String cityId : citySalesIssueMap.keySet()) { for (SalesIssue salesIssue : citySalesIssueMap.get(cityId)) { String finalUrl = baseUrl + "&cityId=" + cityId + "&salesissue=" + salesIssue.id; driver.get(finalUrl); System.out.println("Go to url => " + finalUrl); fw.write("Go to url => " + finalUrl + "\n"); System.out .println("Province,,City," + cityIdNameMap.get(cityId) + ",Sales," + salesIssue.name); fw.write("Province,,City," + cityIdNameMap.get(cityId) + ",Sales," + salesIssue.name + "\n"); List<WebElement> tables = driver.findElements(By.tagName("table")); // Second table WebElement mainTable = tables.get(1); List<WebElement> trs = mainTable.findElements(By.tagName("tr")); Boolean firstOne = true; int cols = 0; for (WebElement tr : trs) { try { if (firstOne) { StringBuilder header = new StringBuilder(); firstOne = false; List<WebElement> tds = tr.findElements(By.tagName("td")); for (WebElement td : tds) { try { String s = td.findElement(By.tagName("strong")).getText(); header.append(s + ","); } catch (NoSuchElementException e) { header.append("ImageURL,"); } } System.out.println(header.toString()); fw.write(header.toString() + "\n"); cols = header.toString().split(",").length; } else { List<WebElement> tds = tr.findElements(By.tagName("td")); if (tds.size() == cols) { StringBuilder line = new StringBuilder(); for (WebElement td : tds) { try { String s = "http://shouji.gd.chinamobile.com" + td.findElement(By.tagName("img")).getAttribute("src"); line.append(s + ","); } catch (NoSuchElementException e) { line.append(td.getText() + ","); } } System.out.println(line); fw.write(line.toString() + "\n"); } else { StringBuilder line = new StringBuilder(); for (int i = 0; i < (cols - tds.size()); i++) { line.append(","); } for (WebElement td : tds) { line.append(td.getText() + ","); } System.out.println(line); fw.write(line.toString() + "\n"); } } } catch (NoSuchElementException e) { System.out.println("One page end!"); fw.write("One page end!" + "\n"); } } // Third table WebElement lastTable = tables.get(1); List<WebElement> span = lastTable.findElements(By.xpath("//span[@class='font_b2']")); int pageNumber = Integer.parseInt(span.get(1).getText()); if (pageNumber > 1) { for (int i = 2; i <= pageNumber; i++) { goToURL(fw, driver, finalUrl + "¤tPage=" + i); } } } } fw.close(); }
From source file:com.zaizi.automation.abfts.drivers.ChromeDriverStore.java
License:Open Source License
/** * @return */ public ChromeDriver createWebDriver() { this.driver = new ChromeDriver(); return driver; }
From source file:com.zaizi.automation.alfresco.drivers.ChromeDriverStore.java
License:Open Source License
/** * @return */ public ChromeDriver createWebDriver() { this.driver = new ChromeDriver(); return driver; }
From source file:connect.Connector.java
public static WebDriver init(String BrowserName) throws IOException { System.out.println(readFile().getProperty(BrowserName)); if (readFile().getProperty(BrowserName).contains("chrome")) { System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\src\\driver\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }// w ww. j ava 2 s. co m if (BrowserName.contains("Firefox")) { WebDriver driver = new FirefoxDriver(); } return driver; }