List of usage examples for org.openqa.selenium By linkText
public static By linkText(String linkText)
From source file:scormADL12.java
License:Open Source License
/** * Login into ADL SCORM Test Course//from w w w . j a va2 s . co m * @param course */ public void loginCourse(int course) { driver.findElement(By.linkText("SCORM 1.2 ADL Test course")).click(); wait.until(presenceOfElementLocated(By.id("username"))); driver.findElement(By.id("username")).clear(); driver.findElement(By.id("password")).clear(); if (course != 2) { driver.findElement(By.id("username")).sendKeys("joestudent"); driver.findElement(By.id("password")).sendKeys("joestudent"); } else { driver.findElement(By.id("username")).sendKeys("marylearner"); driver.findElement(By.id("password")).sendKeys("marylearner"); } driver.findElement(By.id("loginbtn")).click(); wait.until(presenceOfElementLocated(By.xpath("//span[text()='LMSTestCourse01']"))); if (course != 1) { driver.findElement(By.xpath("//span[text()='LMSTestCourse02']")).click(); } else { driver.findElement(By.xpath("//span[text()='LMSTestCourse01']")).click(); } }
From source file:scormADL12.java
License:Open Source License
public void logoutLogin(int course) { driver.switchTo().window("moodleWindow"); driver.findElement(By.linkText("Logout")).click(); loginCourse(course);//from www .j av a 2s . com }
From source file:OrdenReaprovisionamientoTest.java
@Test public void testUpdateProveedor() throws Exception { /**//from w ww .ja va 2 s . co m * Se hace clic en el vinculo "Edit" del primer elemento de la lista de * sports */ driver.findElement(By.linkText("Editar")).click(); Thread.sleep(2000); /** * Se realiza el mismo proceso de diligenciamento de los campos con los * cambios */ driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys(name2); driver.findElement(By.id("fecha")).clear(); driver.findElement(By.id("fecha")).sendKeys(fecha2); driver.findElement(By.id("cantidad")).clear(); driver.findElement(By.id("cantidad")).sendKeys(cantidad2); driver.findElement(By.id("nombreProducto")).clear(); driver.findElement(By.id("nombreProducto")).sendKeys(nombreProducto2); driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); Thread.sleep(2000); /** * Se verifica que en la lista de respuesta hallan aparecido los cambios * en el elemento y tambin el mensaje de edicin exitosa. */ WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]")); List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean fail = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals(name2) && Integer.parseInt( elems.get(1).getText().split("/")[0]) == (Integer.parseInt(fecha2.split("/")[0])) && Integer.parseInt( elems.get(1).getText().split("/")[1]) == (Integer.parseInt(fecha2.split("/")[1])) && Integer.parseInt( elems.get(1).getText().split("/")[2]) == (Integer.parseInt(fecha2.split("/")[2])) && elems.get(2).getText().equals(cantidad2) && elems.get(3).getText().equals(nombreProducto2)) { fail = true; } } assertTrue(dialog != null && fail); }
From source file:OrdenReaprovisionamientoTest.java
@Test public void testDeleteProveedor() throws Exception { /**// w w w . j av a 2 s .c om * Se hace clic en el vinculo "Delete" del primer elemento de la lista * de sports */ driver.findElement(By.linkText("Eliminar")).click(); Thread.sleep(2000); /** * Se verifica que en la lista el elemento halla desaparecido. Si * existe, hubo un error. */ try { List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean fail = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals(name2) && Integer.parseInt( elems.get(1).getText().split("/")[0]) == (Integer.parseInt(fecha2.split("/")[0])) && Integer.parseInt( elems.get(1).getText().split("/")[1]) == (Integer.parseInt(fecha2.split("/")[1])) && Integer.parseInt( elems.get(1).getText().split("/")[2]) == (Integer.parseInt(fecha2.split("/")[2])) && elems.get(2).getText().equals(cantidad2) && elems.get(3).getText().equals(nombreProducto2)) { fail = true; } } WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]")); assertTrue(dialog != null && !fail); } catch (Exception e) { assertTrue(true); } }
From source file:scormADL2004.java
License:Open Source License
@Test /**/*from w w w . j a va 2 s . c o m*/ * navigate inside ADL SCORM 2004 Test Course to check for packages uploaded. */ public void loginCourse() throws IOException { driver.findElement(By.linkText("SCORM 2004 ADL test course")).sendKeys(Keys.ENTER); wait.until(presenceOfElementLocated(By.id("username"))); driver.findElement(By.id("username")).clear(); driver.findElement(By.id("password")).clear(); //Login username password as specified driver.findElement(By.id("username")).sendKeys(username1); driver.findElement(By.id("password")).sendKeys(password1); loginSession = 1; driver.findElement(By.id("loginbtn")).click(); fetchAllContent(); }
From source file:scormADL2004.java
License:Open Source License
public void switchLoginSession(int toLogin) { // To be safe and avoid Selenium Native click element, using submit wherever possible, to be fixed in 2.5.0 WebElement element;/*ww w. ja v a 2s .co m*/ driver.switchTo().window("moodleWindow"); // Check if already logged in if (!isElementPresent(By.linkText("Login"))) { //driver.findElement(By.linkText("Logout")).click(); // Workaround for Selenium bug - 1020, to be fixed in 2.5.0 driver.findElement(By.linkText("Logout")).sendKeys(Keys.ENTER); wait.until(presenceOfElementLocated(By.linkText("SCORM 2004 ADL test course"))); driver.findElement(By.linkText("SCORM 2004 ADL test course")).click(); } if (toLogin != 2) { wait.until(presenceOfElementLocated(By.id("username"))); driver.findElement(By.id("username")).clear(); element = driver.findElement(By.id("password")); element.clear(); driver.findElement(By.id("username")).sendKeys(username1); element.sendKeys(password1); loginSession = 1; } else { wait.until(presenceOfElementLocated(By.id("username"))); driver.findElement(By.id("username")).clear(); element = driver.findElement(By.id("password")); driver.findElement(By.id("username")).sendKeys(username2); element.sendKeys(password2); loginSession = 2; } element.submit(); }
From source file:scormADL2004.java
License:Open Source License
/** * Handle / Launch SCO's//from w ww.j a v a 2 s. c o m */ public void defaultSCOHandler() { // Handle Selenium IE Bug by explicit wait int scoCount = fetchAllSCO(); int scoNo = 1; String userInstruction, activityName = null; // Not infinite loop, testing based on TestSuite Instrcutions while (scoCount > 0) { //First Activity does not need to be launched, launch after first driver.switchTo().window("moodleWindow"); driver.switchTo().frame("scorm_object"); wait.until(presenceOfElementLocated(By.id("teststatus"))); //wait.until(presenceOfElementLocated(By.xpath("//*[contains(.,'progress...')]"))); // Allow loading time, specially for UI tests try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } userInstruction = readUserInstructions(); if (userInstruction.contains("LMS User Interface")) { answerDefaultUI(scoNo); driver.switchTo().window("moodleWindow"); } else { // Print only for 1st Activity. if (scoNo == 1) { System.out.println("Testing Activity. Please Wait... "); } driver.switchTo().window("moodleWindow"); driver.switchTo().frame("scorm_object"); //Check only for "Completed." as some packages contain extra spaces wait.until(presenceOfElementLocated(By.xpath("//div[contains(.,'Completed.')]"))); System.out.println("Testing of Activity Completed."); driver.switchTo().window("moodleWindow"); } // Read instructions to launch new activity // First Activity does not need to be launched. userInstruction = readUserInstructions(); if (!userInstruction.contains("relaunch") && !(userInstruction.contains("please exit the package/course")) && userInstruction.contains("launch")) { activityName = userInstruction.substring((userInstruction.lastIndexOf("nch ") + 4), userInstruction.lastIndexOf(".")); activityName = activityName.trim(); driver.switchTo().window("moodleWindow"); driver.findElement(By.xpath("//span[contains(.,'" + activityName + "')]")).click(); System.out.println("Testing Activity " + activityName + ". Please Wait... "); // Allow loading time of new Activity try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } else if (userInstruction.contains("trigger a Continue Navigation Event")) { driver.switchTo().window("moodleWindow"); driver.findElement(By.id("nav_next-button")).sendKeys(Keys.ENTER); } else if (userInstruction.contains("trigger a Previous Navigation Event")) { driver.switchTo().window("moodleWindow"); driver.findElement(By.id("nav_prev-button")).sendKeys(Keys.ENTER); } else if (userInstruction.contains("relaunch")) { driver.switchTo().window("moodleWindow"); driver.findElement(By.linkText("ADL 2004")).sendKeys(Keys.ENTER); launchTestPackage(userInstruction.substring((userInstruction.lastIndexOf("age ") + 4), (userInstruction.lastIndexOf("to") - 1))); } else if (userInstruction.contains("please exit the package/course")) { if (userInstruction.contains("launch")) { driver.switchTo().window("moodleWindow"); driver.findElement(By.linkText("ADL 2004")).sendKeys(Keys.ENTER); launchTestPackage(userInstruction.substring((userInstruction.lastIndexOf("age ") + 4), userInstruction.lastIndexOf("."))); } else { System.out.println("Testing of Package Completed."); break; } } else if (userInstruction.isEmpty()) { // Launch last activity again. driver.switchTo().window("moodleWindow"); driver.findElement(By.xpath("//span[contains(.,'" + activityName + "')]")).click(); } scoNo++; } // Old way of handling tests. /*for (int i = 1; i <= scoCount; i++) { //First Activity does not need to be launched. if(i != 1) { driver.findElement(By.id("ygtvlabelel"+i)).click(); } driver.switchTo().frame("scorm_object"); wait.until(presenceOfElementLocated(By.id("teststatus"))); wait.until(presenceOfElementLocated(By.xpath("//*[contains(.,'progress...')]"))); boolean uiTestPresent = isInstructionForUIPresent(); if (uiTestPresent) { answerDefaultUI(i); } else { System.out.println("Testing Activity "+i+". Please Wait... "); //Check only for "Completed." as some packages contain extra spaces wait.until(presenceOfElementLocated(By.xpath("//*[contains(.,'Completed.')]"))); System.out.println("Testing of Activity "+i+" Completed."); driver.switchTo().window("moodleWindow"); } } // Some test packages need to launch System.out.println("Testing Completed."); driver.switchTo().window(""); driver.switchTo().frame("controls"); wait.until(presenceOfElementLocated(By.id("continue"))); driver.findElement(By.id("continue")).click(); */ }
From source file:scormADL2004.java
License:Open Source License
/** * Handle / Launches test packages in order they are specified. * @param String[] testsToExecute//from w w w.j av a2s . co m */ public void testsHandler(String[] testsToExecute) { if (testsToExecute[0] == "") { // No tests uploaded throw new NullPointerException("No specified tests found or uploaded."); } initialiseTestSuite(testsToExecute); driver.switchTo().window(""); driver.switchTo().frame("currentInstructions"); wait.until(presenceOfElementLocated(By.xpath("//*[contains(.,'Login to the LMS')]"))); // Check if current user login is the required user logged in checkLoginSession(); driver.switchTo().window("moodleWindow"); // Wait till Page completely loads - Selenium Bug wait.until(presenceOfElementLocated(By.xpath("//*[contains(.,'Recent activity)]"))); for (int i = 0; i < testsToExecute.length; i++) { System.out.println("Testing ADL SCORM 2004 " + testsToExecute[i] + " package..."); launchTestPackage(testsToExecute[i]); //switch cannot compare string // TODO add handle for CM-01 Test if (testsToExecute[i].equalsIgnoreCase("CM-01")) { handleCM01Test(); } // default case else { defaultSCOHandler(); } driver.switchTo().window("moodleWindow"); driver.findElement(By.linkText("Exit activity")).click(); wait.until(presenceOfElementLocated(By.partialLinkText(testsToExecute[i] + " SCORM package"))); driver.switchTo().window(""); driver.switchTo().frame("controls"); wait.until(presenceOfElementLocated(By.id("continue"))); driver.findElement(By.id("continue")).sendKeys(Keys.ENTER); } driver.findElement(By.linkText("Logout")).click(); System.out.println("Tested All Packages. The Script will now exit."); }
From source file:WebTestSelenium5.java
public void testTagNameByLinkText() { assertEquals(driver.findElement(By.linkText("about")).getTagName(), "a"); }
From source file:ClientServicesQA.java
public void createNewTegrityCustomer(WebDriver driver) throws Exception { driver.findElement(By.linkText("Create Tegrity customer")).click(); Thread.sleep(2000);//from ww w. j av a2s .c o m driver.close(); }