List of usage examples for org.openqa.selenium.firefox FirefoxDriver FirefoxDriver
public FirefoxDriver()
From source file:Practice01.java
public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); // Open Website driver.get("https://enterprise-demo.orangehrmlive.com/auth/login"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Type Username driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("Admin"); // Type Password driver.findElement(By.cssSelector("#txtPassword")).sendKeys("admin"); // Click on Login driver.findElement(By.id("btnLogin")).click(); // Click on PIM driver.findElement(By.id("menu_pim_viewPimModule")).click(); // Click Add Employee driver.findElement(By.xpath("//a[@id='menu_pim_addEmployee']")).click(); // DateFormat dateFormat = new SimpleDateFormat("ddhhss"); // Date date = new Date(); // String date1 = dateFormat.format(date); // String userName = "John"+date1; // String username1= "Smith"+date1; // Type First name driver.findElement(By.id("firstName")).sendKeys("John"); // Type Last name driver.findElement(By.id("lastName")).sendKeys("Smith"); Random random = new Random(); int eID = random.nextInt(1000); // Click on Location driver.findElement(By.id("employeeId")).clear(); driver.findElement(By.id("employeeId")).sendKeys("" + eID); // Click on//w w w . j a v a 2s .c o m WebElement location_dd = driver.findElement(By.xpath("//select[@id='location']")); Select location = new Select(location_dd); location.selectByIndex(9); // Click Save driver.findElement(By.id("btnSave")).click(); // Click on edit driver.findElement(By.xpath("//input[@value='Edit']")).click(); // Click on licences expiry driver.findElement(By.id("personal_txtLicExpDate")).click(); // Select date driver.findElement(By.xpath("html/body/div[4]/table/tbody/tr[5]/td[2]/a")).click(); // Click on marital box driver.findElement(By.id("personal_cmbMarital")).click(); // Click on married driver.findElement(By.xpath("//select[@name='personal[cmbMarital]']/option[3]")).click(); // Click on Dob box driver.findElement(By.id("personal_DOB")).click(); //click month box Select month_dd = new Select(driver.findElement(By.xpath("//div[@class='ui-datepicker-title']/select[1]"))); month_dd.selectByVisibleText("Jul"); // Select Year Select year_dd = new Select(driver.findElement(By.xpath("//div/select[2]"))); year_dd.selectByIndex(35); // Click on Date driver.findElement(By.xpath("//table/tbody/tr[4]/td[4]/a")).click(); // Click Save driver.findElement(By.id("btnSave")).click(); // Verify Successfully Saved Message //Assert Assert.assertTrue("Successfully Saved", driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).isEnabled()); System.out.println("Successfully Saved"); //assert1 // String expectedText = "Successfully Saved"; // String actualText = driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).getText(); // Assert.assertEquals(expectedText,actualText); // Click Employee List driver.findElement(By.id("menu_pim_viewEmployeeList")).click(); // Thread.sleep(3000); // //click on emp name // driver.findElement(By.xpath("//input[@id='empsearch_employee_name_empName']")).sendKeys(userName + username1); // // Type Employee ID // driver.findElement(By.id("empsearch_id")).sendKeys(" "+eID); // // Clear Employee ID // driver.findElement(By.id("empsearch_id")).clear(); Thread.sleep(2000); // Search Emp by ID driver.findElement(By.id("empsearch_id")).sendKeys("" + eID); // Search Employee By ID // driver.findElement(By.id("searchBtn")).click(); Thread.sleep(2000); driver.findElement(By.id("searchBtn")).click(); //Assert Assert.assertTrue("John", driver.findElement(By.xpath("//tbody/tr/td[3]/a")).isEnabled()); System.out.println("John"); // }
From source file:acceptance.SharedDriver.java
License:Open Source License
private static WebDriver createWebDriver() { String driverType = getWebDriverType(); final WebDriver driver; switch (driverType.toLowerCase()) { case "htmlunit": driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_24); break;//www.j ava2s . c o m case "firefox": driver = new FirefoxDriver(); break; case "phantomjs": String phantomjsBinaryPath = getPhantomjsBinaryPath(); if (phantomjsBinaryPath.length() > 0) { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setCapability("phantomjs.binary.path", phantomjsBinaryPath); driver = new PhantomJSDriver(desiredCapabilities); } else { driver = new PhantomJSDriver(); } break; default: throw new RuntimeException( "WebDriver type not correctly configured. Unknown driver type: '" + driverType + "'"); } driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); driver.manage().window().setSize(new Dimension(1280, 800)); return driver; }
From source file:akori.AKORI.java
public static void main(String[] args) throws IOException, InterruptedException { System.out.println("esto es AKORI"); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\"; NAME = "mbauchile.png"; // Extrar DOM tree Document doc = Jsoup.connect(URL).timeout(0).get(); // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); int xmax = driver.manage().window().getSize().width; int ymax = driver.manage().window().getSize().height; // Go to the URL page driver.get(URL);/*from w ww . j a v a 2 s .c o m*/ File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screen, new File(PATH + NAME)); BufferedImage img = ImageIO.read(new File(PATH + NAME)); //Graphics2D graph = img.createGraphics(); BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB); Graphics2D graph1 = img.createGraphics(); double[][] matrix = new double[ymax][xmax]; BufferedReader in = new BufferedReader(new FileReader("et.txt")); String linea; double max = 0; graph1.drawImage(img, 0, 0, null); HashMap<String, Integer> lista = new HashMap<String, Integer>(); int count = 0; for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[0]); int y = (int) Double.parseDouble(datos[2]); long time = Double.valueOf(datos[4]).longValue(); if (x >= xmax || y >= ymax) continue; if (time < 691215) continue; if (time > 705648) break; if (lista.containsKey(x + "," + y)) lista.put(x + "," + y, lista.get(x + "," + y) + 1); else lista.put(x + "," + y, 1); ++count; } System.out.println(count); in.close(); Iterator iter = lista.entrySet().iterator(); Map.Entry e; for (String key : lista.keySet()) { Integer i = lista.get(key); if (max < i) max = i; } System.out.println(max); max = 0; while (iter.hasNext()) { e = (Map.Entry) iter.next(); String xy = (String) e.getKey(); String[] datos = xy.split(","); int x = Integer.parseInt(datos[0]); int y = Integer.parseInt(datos[1]); matrix[y][x] += (int) e.getValue(); double aux; if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) { max = aux; } //normalMatrix(matrix,x,y,20); if (matrix[y][x] > max) max = matrix[y][x]; } int A, R, G, B, n; for (int i = 0; i < xmax; ++i) { for (int j = 0; j < ymax; ++j) { if (matrix[j][i] != 0) { n = (int) Math.round(matrix[j][i] * 100 / max); R = Math.round((255 * n) / 100); G = Math.round((255 * (100 - n)) / 100); B = 0; A = Math.round((255 * n) / 100); ; if (R > 255) R = 255; if (R < 0) R = 0; if (G > 255) G = 255; if (G < 0) G = 0; if (R < 50) A = 0; graph1.setColor(new Color(R, G, B, A)); graph1.fillOval(i, j, 1, 1); } } } //graph1.dispose(); ImageIO.write(img, "png", new File("example.png")); System.out.println(max); graph1.setColor(Color.RED); // Extraer elementos Elements e1 = doc.body().getAllElements(); int i = 1; ArrayList<String> tags = new ArrayList<String>(); for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) continue; System.out.println(i + " " + temp.nodeName()); System.out.println(" x: " + po.x + " y: " + po.y); System.out.println(" width: " + d.width + " height: " + d.height); graph1.draw(new Rectangle(po.x, po.y, d.width, d.height)); ++i; } } } graph1.dispose(); ImageIO.write(img, "png", new File(PATH + NAME)); driver.quit(); }
From source file:akori.Features.java
public static void main(String[] args) throws IOException, InterruptedException { URL = "http://www.mbauchile.cl"; Document doc = Jsoup.connect(URL).timeout(0).get(); WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get(URL);/*w w w . jav a 2s . c om*/ Elements e1 = doc.body().getAllElements(); Element e = doc.body(); PrintWriter writer = new PrintWriter("features.txt", "UTF-8"); int i = 1; // String[][] matrix = new String[e1.size()][10]; // traverse(e, 1, 1, "", 1, writer, driver); ArrayList<String> tags = new ArrayList<String>(); System.out.println(""); // for (Element temp : e1) { // if (!temp.nodeName().equals("br")) { // writer.println(i + "," + temp.hashCode() + "," + temp.nodeName() + "," + temp.id()); // //System.out.println(i+","+temp.hashCode()+","+temp.nodeName()); // ++i; // } // } i = 1; for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) { continue; } if (temp1.getTagName().equals("img")) writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("src")); else if (temp1.getTagName().equals("a")) writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("href")); else writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getText()); ++i; } } } driver.quit(); writer.close(); }
From source file:akori.SELENIUM.java
public static void main(String[] args) throws Exception { // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\1.png"; // Go to the Google Suggest home page driver.get(URL);// w w w .j a v a2 s . co m // Enter the query string "Cheese" WebElement query = driver.findElement(By.id("container")); Point p = query.getLocation(); Dimension d = query.getSize(); System.out.println("x: " + p.x + " y: " + p.y); System.out.println("width: " + d.width + " height: " + d.height); driver.quit(); }
From source file:all_iterations_scripts.US954_Resume_Attachment.java
@Before public void setUp() throws Exception { // setting up IE, Chrome, and FireFox Web Drivers File file = new File(Constants.IE); System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); File file1 = new File(Constants.Chrome); System.setProperty("webdriver.chrome.driver", file1.getAbsolutePath()); driver = new InternetExplorerDriver(); // driver=new ChromeDriver(); driver = new FirefoxDriver(); driver.manage().window().maximize(); }
From source file:app.Stepdefs.java
public Stepdefs() { baseUrl = "http://localhost:8080"; File file;// www . j a va 2 s. c o m if (System.getProperty("os.name").matches("Mac OS X")) { file = new File("lib/macgeckodriver"); } else if (System.getProperty("os.name").matches("Linux")) { file = new File("lib/geckodriver"); } else { file = new File("lib/wingeckodriver.exe"); } String path = file.getAbsolutePath(); System.setProperty("webdriver.gecko.driver", path); this.driver = new FirefoxDriver(); }
From source file:application.Main.java
License:Open Source License
public static void appSingleThread(Globals GLOBALS) { LinkedList<String> list = Input.readFacebookPostIds(GLOBALS.FILENAME); if (GLOBALS.RANDOM) { Collections.shuffle(list); }/*from w ww .j a va2 s. co m*/ String email = GLOBALS.fb_eamil; String pass = GLOBALS.password; WebDriver driver = new FirefoxDriver(); // The Firefox driver supports javascript Autenticate.perform(driver, email, pass); try { Thread.sleep(Globals.TIME_TO_LOGIN_IN_FB_MS); } catch (Exception ex) { System.out.println("InterruptedException in crawl.run()"); ex.printStackTrace(); System.exit(-1); } for (String post_id : list) { System.out.println("\n****** STARTING NEW TREE: " + post_id + "******"); try { //OPEN NEW TAB WebElement body = driver.findElement(By.tagName("body")); body.sendKeys(Keys.CONTROL + "t"); Tree post = new Tree(post_id, GLOBALS); boolean result = post.crawl(driver); if (result) { post.prune(); post.print(); post.printEdgeList(); System.out.println("****** TREE " + post_id + " ACCOMPLISHED ******"); } else { body.sendKeys(Keys.CONTROL + "w"); System.out.println("****** TREE " + post_id + " FAILED ******"); } //SWITCH TAB ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles()); driver.switchTo().window(tabs.get(tabs.size() - 1)); } catch (Exception e) { System.out.println("****** TREE " + post_id + " FAILED ******"); System.out.println("EXCEPTION in MAIN " + e); System.out.println("...RESTARTING APPLICATION AFTER 1 minute APPLICATION..."); driver.quit(); try { Thread.sleep(Globals.ONE_MINUTE); } catch (Exception ex) { System.out.println("InterruptedException in crawl.run()"); ex.printStackTrace(); System.exit(-1); } driver = new FirefoxDriver(); // The Firefox driver supports javascript Autenticate.perform(driver, email, pass); } } driver.quit(); }
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 ww . ja v a 2s . 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/* w ww . j av 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>(); }