List of usage examples for org.openqa.selenium WebDriver get
void get(String url);
From source file:FirefoxConsoleExportTest.java
License:Open Source License
@org.junit.Test public void testLogger() throws Exception { FirefoxConsoleExport test = new FirefoxConsoleExport(9999); WebDriver driver = test.getDriver(); driver.get("https://slashdot.org"); ArrayList<LogEntry> logs = test.getLogEntries(); driver.close();/* w w w . jav a2s .c o m*/ System.out.println(logs); assertTrue("No console logs were created from slashdot.", logs.size() > 0); }
From source file:SmokeTester_UnitTest.java
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 + "\nStart 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();//from ww w. j a va2 s. c om log_execution = log_execution + " Login Successful"; } //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 + " 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); SmokeTestValidator_UnitTest testvalidator = new SmokeTestValidator_UnitTest(testscript); TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution); validatedTestScript.add(testingresult); } tcreader.writetoExcel(validatedTestScript); //Close the browser driver.quit(); //return log_execution; }
From source file:IdNameDemo.java
public static void main(String[] args) { String baseURL = "http://www.google.com"; System.setProperty("webdriver.gecko.driver", "/Users/srijana/Documents/seleniumpractise notes/geckodriver 2"); WebDriver driver = new FirefoxDriver(); driver.get(baseURL); driver.findElement(By.id("lst-ib")).sendKeys("letskodeit"); driver.findElement(By.name("btnG")).click(); }
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//from w w w . j av a2 s.c om 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: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); 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;// w ww . j a v a 2s . c o m 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); Elements e1 = doc.body().getAllElements(); Element e = doc.body();/*from w w w . ja v a 2 s .co m*/ 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); // 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 ww w . j a v a 2 s. co m*/ }
From source file:alwaysonline.Access.java
License:Open Source License
/** * Method for the access./*from w w w .j a v a 2 s . c o m*/ * @param user String that contains the username * @param pass String that contains the password * @return Access result: 0 failed, 1 success. */ public int doAccess(String user, String pass) { WebDriver driver = new HtmlUnitDriver(); WebElement username, password; // access page driver.get("https://auth3.unipi.it/auth/perfigo_cm_validate.jsp"); // looking for the credential fields username = driver.findElement(By.name("username")); username.clear(); username.sendKeys(user); password = driver.findElement(By.name("password")); password.clear(); password.sendKeys(pass); // Executing the access, submiting values driver.findElement(By.name("username")).submit(); // If the session was already opened if (driver.getPageSource().contains("Too many users using this account")) { // put again credentials username = driver.findElement(By.name("username")); username.clear(); username.sendKeys(user); password = driver.findElement(By.name("password")); password.clear(); password.sendKeys(pass); // remove the old session driver.findElement(By.name("remove_old")).click(); // submit again access data driver.findElement(By.name("username")).submit(); } // controll if the access has been done successful if (driver.getPageSource().contains("You have been successfully logged on the network")) return 1; return 0; }
From source file:aplikacjafb.Graph.java
/** * */// w ww . j av a2 s .co 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
@Test public void hello() { WebDriver driver = webDriver; int noTeams = 3; driver.get(baseUrl + "/champgen/faces/index.xhtml"); driver.findElement(By.linkText("Login")).click(); driver.findElement(By.id("login-form:username")).sendKeys("admin"); driver.findElement(By.id("login-form:password")).sendKeys("admin"); driver.findElement(By.id("login-form:btnSubmit")).click(); driver.findElement(By.linkText("New Championship")).click(); driver.findElement(By.id("new-championship-form:name")).clear(); driver.findElement(By.id("new-championship-form:name")).sendKeys("TestChamp1"); driver.findElement(By.id("new-championship-form:btnSubmit")).click(); assertTrue(driver.findElement(By.id("msg:info")).getText().matches("^[\\s\\S]*added ![\\s\\S]*$")); for (int i = 0; i < noTeams; i++) { driver.findElement(By.linkText("New Team")).click(); driver.findElement(By.id("newteam-form:team")).clear(); driver.findElement(By.id("newteam-form:team")).sendKeys("Team" + i); driver.findElement(By.id("newteam-form:leader")).clear(); driver.findElement(By.id("newteam-form:leader")).sendKeys("Leader" + i); driver.findElement(By.id("newteam-form:btnSubmit")).click(); }/*from w w w .j a va 2s .com*/ this.pause(TIME_TO_PAUSE); this.pause(TIME_TO_PAUSE); driver.get(baseUrl + "/champgen/faces/index.xhtml"); int rowCount = webDriver.findElements(By.xpath("//table/tbody/tr")).size(); System.out.println(rowCount); assertTrue(rowCount == noTeams + 1); // + 1 because title is counted as row this.pause(TIME_TO_PAUSE); }