List of usage examples for org.openqa.selenium.chrome ChromeDriver ChromeDriver
public ChromeDriver()
From source file:administrationedit.addOffice.java
public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); String[] city = { "Rijeka", "Pula", "Pore?", "Rovinj", "Umag", "Novigrad", "Vrsar", "Pazin", "Motovun", "Medulin", "Faana", "Vodnjan", "Opatija", "Krk", "Punat", "Baka", "Njivice", "Labin", "Rabac", "Plomin", "I?ii", "Ika", "Malinska", "Njivice", "Omialj", "Dramalj", "Crikvenica", "Selce", "Cres", "Rab", "Novi Vinodolski", "Povile", "iii", "Vodice", "Pinezii", "Lovran", "Medveja", "shanghai", "sao paulo", "kinshasa", "cairo", "peking", "london", "bogota", "dhaka", "rio de janeiro", "santiago", "toronto", "sydney", "wuhan", "chongqing", "xian", "chengdu", "alexandria", "tianjin", "melbourne", "abidjan", "shenyang", "berlin", "montreal", "harbin", "guangzhou", "madrid", "nanjing", "kabul", "luanda", "addis abeba", "taiyuan", "salvador", "changchun", "gizeh", "fortaleza", "cali", "belo horizonte", "brasilia", "santo domingo", "paris", "jinan", "tangshan", "dalian", "medellin", "algiers", "accra", "guayaquil", "jilin", "hangzhou", "nanchang", "conakry", "brisbane", "vancouver", "minsk", "hamburg", "curitiba", "qingdao", "manaus", "xinyang", "barcelona", "vienna", "urumqi", "recife", "kumasi", "perth", "cordoba", "lanzhou", "belem", "fushun", "quito", "luoyang", "hefei", "barranquilla", "lubumbashi", "porto alegre", "handan", "suzhou", "khulna", "douala", "yaounde", "munich", "rosario", "anshan", "xuzhou", "fuzhou", "guiyang", "goiania", "guarulhos", "prague", "dubai", "baku", "brazzaville", "wuxi", "yerevan", "copenhagen", "adelaide", "sofia", "datong", "tbilisi", "xianyang", "campinas", "ouagadougou", "huainan", "kunming", "brussels", "shenzhen", "nova iguacu", "rongcheng", "baoding", "benxi", "birmingham", "mendoza", "cologne", "calgary", "maceio", "cartagena", "changzhou", "sao goncalo", "sao luis", "huaibei", "cochabamba", "pingdingshan", "qiqihar", "mbuji-mayi", "ottawa", "wenzhou", "tucuman", "edmonton", "duque de caxias", "la paz", "nanning", "marseille", "anyang", "hohhot", "valencia", "xining", "liuzhou", "natal", "qinhuangdao", "hengyang", "taian", "teresina", "xinxiang", "sao bernardo do campo", "hegang", "campo grande", "athens", "cucuta", "langfang", "ningbo", "yantai", "zhuzhou", "jaboatao", "rajshahi", "sarajevo", "zhangjiakou", "cotonou", "zigong", "fuxin", "liaoyang", "sevilla", "la plata", "bangui", "osasco", "zhangdian", "puyang", "nantong", "mudanjiang", "santo andre", "hamilton", "joao pessoa", "shaoyang", "guilin", "frankfurt", "wahran", "mar del plata", "quebec", "zhanjiang", "zaragoza", "zhenjiang", "winnipeg", "dandong", "shaoguan", "yancheng", "foshan", "contagem", "jibuti", "haikou", "sao jose dos campos", "taizhou", "xingtai", "glasgow", "jinzhou", "abu dhabi", "luancheng", "dortmund", "stuttgart", "yingkou", "zhangzhou", "belfast" }; Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/office/add"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); // Input name String nameComp = faker.company().name(); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys(nameComp); // Input address String addressComp = faker.address().fullAddress(); driver.findElement(By.id("address")).clear(); driver.findElement(By.id("address")).sendKeys(addressComp); // Input city String cityComp = faker.address().city(); driver.findElement(By.id("city")).clear(); driver.findElement(By.id("city")).sendKeys(cityComp); // Input postal code String postalCodeComp = faker.address().zipCode(); driver.findElement(By.id("postalCode")).clear(); driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp); // Country// w w w . jav a 2s . c o m Select countryComp = new Select(driver.findElement(By.id("country"))); int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1; countryComp.selectByIndex(coutryCompInt); // Email String emailComp = faker.internet().emailAddress(); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys(emailComp); // Phone String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("phone")).clear(); driver.findElement(By.id("phone")).sendKeys(phoneComp); // Mobile String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", ""); driver.findElement(By.id("mobilePhone")).clear(); driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp); // Fax String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("fax")).clear(); driver.findElement(By.id("fax")).sendKeys(faxComp); // Geolocation int cityN = r.nextInt(city.length); driver.findElement(By .xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/input")) .sendKeys(city[cityN]); driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/a")) .click(); Thread.sleep(3000); // SAVE driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[12]/div/button")) .click(); }
From source file:administrationedit.setSeasonTemplate.java
public static void main(String[] args) throws InterruptedException { for (int y = 0; y < 2; y++) { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/accommodation/seasonTemplateAdd"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); int currentYear = Calendar.getInstance().get(Calendar.YEAR) + y; String curYear = String.valueOf(currentYear); // Input name of template driver.findElement(By.id("name")).sendKeys("Season-" + curYear); // Choose year Select year = new Select(driver.findElement(By.id("year"))); year.selectByVisibleText(curYear); // Now select seasons WebElement tableId = driver.findElement(By.xpath("//*[@class='ui-calendar hasDatepicker']")); if (year.getFirstSelectedOption().getText().equals(curYear)) { String id = tableId.getAttribute("id"); for (int i = 1; i <= 12; i++) { Thread.sleep(1000); for (int j = 1; j <= 7; j++) { if (!driver.findElements(By.xpath( "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a")) .isEmpty()) { driver.findElement(By.xpath( "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a")) .click(); break; }//from w w w .j a va2 s . co m } i++; int weeks = driver .findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr")) .size(); int test = 0; for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) { test = 1; break; } else test = 2; } switch (test) { case 1: for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) { driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); Select season1 = new Select(driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); int season1int = r.nextInt(season1.getOptions().size() - 1) + 1; season1.selectByIndex(season1int); driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]")) .click(); break; } } break; case 2: for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).isEmpty()) { driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); Select season2 = new Select(driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); int season2int = r.nextInt(season2.getOptions().size() - 1) + 1; season2.selectByIndex(season2int); driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]")) .click(); break; } } } } } // SAVE wait.until(ExpectedConditions.visibilityOfElementLocated( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input"))); driver.findElement(By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input")) .click(); if (driver.getTitle().equals("Accommodation season templates administration")) { driver.close(); } } }
From source file:aplikacjafb.Graph.java
/** * *//*w ww .j a v a 2s. c o m*/ //private static final long serialVersionUID = -2707712944901661771L; public Graph(int liczba, String nazwa) { //super("Hello, World!"); Baza baza = new Baza(); baza.polaczZbazaDanych(); List<String> dane = baza.selectDane(wyszukiwanie, liczba); //List<String> dane2 =baza.selectDane(wyszukiwanie,liczba); baza.rozlaczZbazaDanych(); mxGraph graph = new mxGraph(); Object parent = graph.getDefaultParent(); graph.getModel().beginUpdate(); try { Object v1 = graph.insertVertex(parent, null, "https://fb.com/" + wyszukiwanie, 600, 350, 200, 30); for (int i = 0; i < liczba; i++) { if (i < dane.size()) { Object v = graph.insertVertex(parent, Integer.toString(i), dane.get(i), 600 + 250 * cos(i * 2 * PI / liczba), 350 + 250 * sin(i * 2 * PI / liczba), 200, 30); graph.insertEdge(parent, null, null, v1, v); } } } finally { graph.getModel().endUpdate(); } mxGraphComponent graphComponent = new mxGraphComponent(graph); getContentPane().add(graphComponent); graphComponent.getGraphControl().addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { Object cell = graphComponent.getCellAt(e.getX(), e.getY()); String url; if (cell != null) { System.out.println("cell=" + graph.getLabel(cell)); url = graph.getLabel(cell); url = url.substring(url.lastIndexOf("https")); System.out.println(url); System.setProperty("webdirver.chrome.driver", "chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get(url); } } }); }
From source file:AQ.TeamsUnitTest.java
@Before public void setUp() { this.webDriver = new ChromeDriver(); this.baseUrl = "http://localhost:8080"; this.webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); //DataBaseTool.restartDB(); try {//from w ww.j a va 2s .co m DataBaseTool.executeSQLfromFile("emptyDB.sql"); } catch (Exception e) { e.printStackTrace(); } }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java
License:Apache License
protected final WebDriver createDriver() throws Exception { Exception exception = null;//from w w w.j av a 2 s .c o m WebDriver webDriver = null; int tries = 0; while (tries < MAX_DRIVER_GET_RETRY) { try { if (chromeService != null) { webDriver = new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome()); } else { webDriver = new ChromeDriver(); } } catch (Exception ex) { exception = ex; try { webDriver = new FirefoxDriver(); } catch (Exception ex1) { exception.addSuppressed(ex1); try { webDriver = new SafariDriver(); } catch (Exception ex2) { exception.addSuppressed(ex2); try { if (ieService != null) { webDriver = new RemoteWebDriver(ieService.getUrl(), DesiredCapabilities.internetExplorer()); } else { webDriver = new InternetExplorerDriver(); } } catch (Exception ex3) { exception.addSuppressed(ex3); } } } } if (webDriver != null) { break; } } if (webDriver == null) { throw new RuntimeException("Could not find a browser for testing", exception); } webDrivers.add(webDriver); webDriver.get(webappUrl); if (login != null) { user = login.doLogin(webDriver); if (user == null) { user = ""; errorCollector.checkThat("Could not login", true, is(false)); } } return webDriver; }
From source file:at.ac.tuwien.big.we14.lab2.tests.SeleniumTest.java
License:Open Source License
/** * @throws java.lang.Exception/*from w ww . ja v a 2 s. com*/ */ @Before public void setUp() throws Exception { try { driver = new FirefoxDriver(); } catch (Exception ffExceptions) { try { driver = new ChromeDriver(); } catch (Exception chromeExceptions) { try { driver = new InternetExplorerDriver(); } catch (Exception ieExceptions) { throw new Exception( "Couldn't create a valid webdriver for Firefox, Chrome, or Internet Explorer"); } } } driver.get("http://" + host + ":" + port + contextPath + mainUrl); currentCheckCategory = new Stack<String>(); }
From source file:au.com.onegeek.lambda.core.BrowserFactory.java
License:Apache License
/** * Factory method that creates a OS \ architecture independent WebDriver based on the browser * requested.//from www. j a v a 2 s . com * * @param browser The name of the browser to create. Currently supports Firefox, * Chrome, IE, HTMLUnit and null. Default is HTMLunit if none * supplied. Parameter is case insensitive.. * @return The WebDriver to run the tests. * @throws Exception */ public static WebDriver getDriver(String browser) throws Exception { WebDriver driver = null; // HTMLUnit is default browser if (browser == null || browser.equalsIgnoreCase("htmlunit") || browser.trim().equalsIgnoreCase("")) { logger.debug("Creating new HTMLUnit driver"); driver = new HtmlUnitDriver(); } else if (browser.equalsIgnoreCase("firefox")) { logger.debug("Creating new Firefox driver"); driver = new FirefoxDriver(); } else if (browser.equalsIgnoreCase("opera")) { logger.debug("Creating new Opera driver"); driver = new OperaDriver(); } else if (browser.equalsIgnoreCase("chrome")) { logger.debug("Creating new Chrome driver"); // Chrome has it's own web driver implementation, need to specify the property 'webdriver.chrome.driver' Properties props = System.getProperties(); if (System.getProperty("webdriver.chrome.driver") == null) { // Create a new instance of the Chrome driver // Notice that the remainder of the code relies on the interface, // not the implementation. Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); logger.debug("key {} -- value{}", key, props.getProperty(key)); } String os = System.getProperty("os.name"); String arch = System.getProperty("sun.arch.data.model"); String currentDir = new File(".").getAbsolutePath(); // Check OS if (os.indexOf("Mac OS X") > -1) { //capabilities.setCapability("chrome.binary", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"); System.setProperty("webdriver.chrome.driver", currentDir + "/lib/chromedriver-macosx"); } else if (arch.equalsIgnoreCase("32") && os.indexOf("Linux") > -1) { System.setProperty("webdriver.chrome.driver", currentDir + "/lib/chromedriver-linux32"); } else if (arch.equalsIgnoreCase("64") && os.indexOf("Linux") > -1) { System.setProperty("webdriver.chrome.driver", currentDir + "/lib/chromedriver-linux64"); } else if (os.indexOf("Linux") > -1) { System.setProperty("webdriver.chrome.driver", currentDir + "/lib/chromedriver-linux32"); } else if (os.indexOf("Windows") > -1) { System.setProperty("webdriver.chrome.driver", currentDir + "/lib/chromedriver.exe"); } else { throw new Exception("Cannot find WebDriver for os, therefore cannot run these tests: " + os); } } logger.debug("Chrome driver binary: " + System.getProperty("webdriver.chrome.driver")); // driver = new ChromeDriver(capabilities); driver = new ChromeDriver(); } else if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore")) { logger.debug("Creating new Internet Explorer driver"); driver = new InternetExplorerDriver(); } else { throw new BrowserNotFoundException("Browser " + browser + " not supported."); } return driver; }
From source file:authentication.AccountInfo.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed WebDriver driver = new ChromeDriver(); driver.get(//ww w.ja v a 2 s . c o m "https://www.facebook.com/?stype=lo&jlou=Afeo3usnUHyB5AT4TqVF4PpoNba5Ld2sOALGhGMfhib8xyeI0FjYqdYf72ZtVncLyfHnYBBU6pY3XZ_l-D-KchQXCwLecdkAemJcXs_dIu-UmQ&smuh=16711&lh=Ac-txP8J-TK6lCJ5"); WebElement username = driver.findElement(By.id("email")); WebElement password = driver.findElement(By.id("pass")); username.sendKeys(b.getUserName()); password.sendKeys(b.getPassWord()); WebElement button = driver.findElement(By.id("loginbutton")); button.click(); }
From source file:authentication.TestingTable.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); WebDriver driver = new ChromeDriver(); driver.get(//from w w w .j a va 2 s .c o m "https://www.facebook.com/?stype=lo&jlou=Afeo3usnUHyB5AT4TqVF4PpoNba5Ld2sOALGhGMfhib8xyeI0FjYqdYf72ZtVncLyfHnYBBU6pY3XZ_l-D-KchQXCwLecdkAemJcXs_dIu-UmQ&smuh=16711&lh=Ac-txP8J-TK6lCJ5"); WebElement username = driver.findElement(By.id("email")); WebElement password = driver.findElement(By.id("pass")); password.sendKeys(model.getValueAt(jTable1.getSelectedRow(), 0).toString()); username.sendKeys(model.getValueAt(jTable1.getSelectedRow(), 1).toString()); WebElement button = driver.findElement(By.id("loginbutton")); button.click(); }
From source file:automated_tests.InitialPopups.java
@Parameters("browser") @BeforeClass//from w w w . j a va 2 s . c o m public static void beforeTest(String browser) { //set browser driver if (browser.equalsIgnoreCase("firefox")) { System.setProperty("webdriver.gecko.driver", "C:\\webDrivers\\geckodriver.exe"); driver = new FirefoxDriver(); System.out.println("Set for browser " + browser); } else if (browser.equalsIgnoreCase("chrome")) { System.setProperty("webdriver.chrome.driver", "C:\\webDrivers\\chromedriver.exe"); driver = new ChromeDriver(); System.out.println("Set for browser " + browser); } else if (browser.equalsIgnoreCase("ie")) { System.setProperty("webdriver.ie.driver", "C:\\webDrivers\\IEDriverServer.exe"); driver = new InternetExplorerDriver(); System.out.println("Set for browser " + browser); } //Opera and IE only work on Windows? // System.setProperty("webdriver.opera.driver","/Users/catherineszeto/Documents/workspace/MPN/operadriver"); // driver = new OperaDriver(); // System.setProperty("webdriver.ie.driver","/Users/catherineszeto/Documents/workspace/MPN/IEDriverServer.exe"); // driver = new InternetExplorerDriver(); else { System.out.println("Driver not configured for browser " + browser); } wait = new WebDriverWait(driver, 20); //set base URL }