List of usage examples for org.openqa.selenium WebElement submit
void submit();
From source file:com.spambot.invisicow.SeleniumDriver.java
public void driveExample() { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new FirefoxDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); }//from ww w .j a v a2s . co m }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.testmax.runner.SeleniumTestRunner.java
License:CDDL license
protected WebElement executeWhile() throws TestMaxException { long executionTime = System.currentTimeMillis(); List<WebElement> controls = null; try {/* ww w .ja v a 2 s . c o m*/ this.setImpilicitTimeInMiliSec(new Integer(timeout)); controls = this.getWebElements(); for (WebElement control : controls) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); if (method.equalsIgnoreCase("click")) { try { printMessage("**** Clicking " + this.controlIdentifier); control.click(); printMessage("**** Clicked " + this.controlIdentifier + ":" + addMessage()); //do not return to continue with while } catch (Exception e) { return control; //WebElement target=executeClick(control); //do not return to continue with while } } else if (method.equalsIgnoreCase("selectByValue")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).selectByValue(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Selected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("deselectByVisibleText")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).deselectByVisibleText(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Deselected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("selectByVisibleText")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).selectByVisibleText(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Selected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("clear")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); control.clear(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Cleared " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("movemouse")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); this.mouseMove(control); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Moved Mouse " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("submit")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); control.submit(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Submitted " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("asserttext")) { try { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); String actual = control.getText(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** verifying Text Value " + actual + " for " + this.controlIdentifier + ":" + addMessage()); if (actual != null && !actual.isEmpty() && actual.contains(this.stripchar)) { if (value != null && value.contains("@")) { this.addTestExtract(value, actual); } else { this.assertText(value, actual); } return control; } } catch (Exception e) { } } else if (method.equalsIgnoreCase("sendKeys")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); control.sendKeys(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Entered Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } } } catch (NumberFormatException e) { // TODO Auto-generated catch block this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } catch (InterruptedException e) { // TODO Auto-generated catch block this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } catch (Exception e) { // TODO Auto-generated catch block this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } //if you are here then quit return null; }
From source file:com.testmax.runner.SeleniumTestRunner.java
License:CDDL license
protected WebElement executeMobileAll() throws TestMaxException { long executionTime = System.currentTimeMillis(); List<WebElement> controls = null; try {//from w w w . ja v a 2 s. c o m this.setImpilicitTimeInMiliSec(new Integer(timeout)); //handle custom operations if (this.isBypassCustomMethod()) { if (method.equalsIgnoreCase("get")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); this.waitToPageLoad(new Integer(timeout)); if (!url.contains("http") && !url.contains("file:")) { url = this.baseUrl + url; } url = url.replace("[env]", ConfigLoader.getConfig("QA_TEST_ENV")); if (this.baseUrl.contains("https")) { url = url.replace("http:", "https:"); } this.printCommand(this.tagdesc + " URL=" + url); driver.get(url); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Executed Open URL= " + url + " for Control=" + this.controlIdentifier + ":" + addMessage()); return null; } else if (method.equalsIgnoreCase("closewindow")) { this.driver.close(); return null; } else if (method.equalsIgnoreCase("sleep")) { this.executeSleep(); return null; } else if (method.equalsIgnoreCase("executescript")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); Thread.sleep(100); this.executeScript(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + "\n Script=" + addMessage()); //printMessage("**** Executed Java Script= "+addMessage()+ " for Control="+this.controlIdentifier +":"+ addMessage()); return null; } else if (method.equalsIgnoreCase("executeoperation")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); Thread.sleep(100); this.executeOperation(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); //printMessage("**** Executed Java Script= "+addMessage()+ " for Control="+this.controlIdentifier +":"+ addMessage()); return null; } else if (this.method.equalsIgnoreCase("urlextract")) { String currenturl = this.driver.getCurrentUrl(); if (currenturl != null && !currenturl.isEmpty()) { this.addTestExtract(this.value, currenturl); printMessage("#### Extracted parameters from URL=" + currenturl); } return null; } else if (method.equalsIgnoreCase("closewindow")) { this.driver.close(); return null; } } controls = this.getWebElements(); for (WebElement control : controls) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); if (!isBypassDisplay()) { while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } } if (method.equalsIgnoreCase("click")) { try { printMessage("**** Clicking " + this.controlIdentifier); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); control.click(); printMessage("**** Clicked " + this.controlIdentifier + ":" + addMessage()); return control; } catch (Exception e) { WebElement target = executeClick(control); if (target != null) { return target; } } } else if (method.equalsIgnoreCase("selectByValue")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).selectByValue(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Selected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("deselectByVisibleText")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).deselectByVisibleText(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Deselected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("selectByVisibleText")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).selectByVisibleText(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Selected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("clear")) { try { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); if (control.isEnabled()) control.clear(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Cleared " + this.controlIdentifier + ":" + addMessage()); return control; } catch (Exception e) { this.clearElement(); Thread.sleep(500); return control; } } else if (method.equalsIgnoreCase("movemouse")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); this.mouseMove(control); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Moved Mouse " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("download")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); this.downloadFile(control); if (this.value != null && !this.value.isEmpty() && this.value.contains("[")) { this.modifyexcel(this.value); } this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Download File " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("uploadfile")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); String dest = ConfigLoader.getWmOutputWebServicePath() + "modifytest.xls"; File mfile = new File(dest); String modifyfile = mfile.getCanonicalPath(); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + modifyfile); control.sendKeys(modifyfile); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Entered Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("submit")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); control.submit(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Submitted " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("asserttext")) { try { this.setImpilicitTimeInMiliSec(new Integer(timeout)); Thread.sleep(100); String actual = control.getText(); if (actual == null || actual.isEmpty()) { actual = control.getAttribute("value"); printMessage( "**** Control won't have Text Value. Extracted Value using attribute Name=value. Found value= " + actual + " for " + this.controlIdentifier + ":" + addMessage()); } this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage() + ", actual=" + actual); printMessage("**** verifying Text Value= " + actual + " for " + this.controlIdentifier + ":" + addMessage()); if (actual != null && !actual.isEmpty()) { if (value != null && value.contains("@")) { this.addTestExtract(value, actual); } else { this.assertText(value, actual); } return control; } } catch (Exception e) { } } else if (method.equalsIgnoreCase("sendKeys")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); control.sendKeys(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Entered Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } } } catch (NumberFormatException e) { this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); // TODO Auto-generated catch block String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } catch (InterruptedException e) { // TODO Auto-generated catch block this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } catch (Exception e) { // TODO Auto-generated catch block this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } //if you are here then quit //driver.quit(); return null; }
From source file:com.testmax.runner.SeleniumTestRunner.java
License:CDDL license
protected WebElement executeAll() throws TestMaxException { long executionTime = System.currentTimeMillis(); List<WebElement> controls = null; try {//from w w w. ja v a2s . c o m this.setImpilicitTimeInMiliSec(new Integer(timeout)); //handle custom operations if (this.isBypassCustomMethod()) { if (method.equalsIgnoreCase("get")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); this.waitToPageLoad(new Integer(timeout)); if (!url.contains("http") && !url.contains("file:")) { url = this.baseUrl + url; } url = url.replace("[env]", ConfigLoader.getConfig("QA_TEST_ENV")); if (this.baseUrl.contains("https")) { url = url.replace("http:", "https:"); } this.printCommand(this.tagdesc + " URL=" + url); driver.get(url); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Executed Open URL= " + url + " for Control=" + this.controlIdentifier + ":" + addMessage()); return null; } else if (method.equalsIgnoreCase("closewindow")) { this.driver.close(); return null; } else if (method.equalsIgnoreCase("sleep")) { this.executeSleep(); return null; } else if (method.equalsIgnoreCase("executescript")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); Thread.sleep(100); this.executeScript(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + "\n Script=" + addMessage()); printMessage("**** Executed Java Script= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return null; } else if (method.equalsIgnoreCase("executeoperation")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); Thread.sleep(100); this.executeOperation(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); printMessage("**** Executed Java Script= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return null; } else if (this.method.equalsIgnoreCase("urlextract")) { String currenturl = this.driver.getCurrentUrl(); if (currenturl != null && !currenturl.isEmpty()) { this.addTestExtract(this.value, currenturl); printMessage("#### Extracted parameters from URL=" + currenturl); } return null; } } controls = this.getWebElements(); for (WebElement control : controls) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); if (!isBypassDisplay()) { while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } } if (method.equalsIgnoreCase("click")) { try { printMessage("**** Clicking " + this.controlIdentifier); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); control.click(); printMessage("**** Clicked " + this.controlIdentifier + ":" + addMessage()); return control; } catch (Exception e) { WebElement target = executeClick(control); if (target != null) { return target; } } } else if (method.equalsIgnoreCase("selectByValue")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).selectByValue(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Selected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("deselectByVisibleText")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).deselectByVisibleText(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Deselected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("selectByVisibleText")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } new Select(control).selectByVisibleText(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Selected Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("clear")) { try { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); if (control.isEnabled()) control.clear(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Cleared " + this.controlIdentifier + ":" + addMessage()); return control; } catch (Exception e) { this.clearElement(); Thread.sleep(500); return control; } } else if (method.equalsIgnoreCase("movemouse")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); this.mouseMove(control); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Moved Mouse " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("download")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); this.downloadFile(control); if (this.value != null && !this.value.isEmpty() && this.value.contains("[")) { this.modifyexcel(this.value); } this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Download File " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("uploadfile")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); String dest = ConfigLoader.getWmOutputWebServicePath() + "modifytest.xls"; File mfile = new File(dest); String modifyfile = mfile.getCanonicalPath(); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + modifyfile); control.sendKeys(modifyfile); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Entered Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("submit")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); control.submit(); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Submitted " + this.controlIdentifier + ":" + addMessage()); return control; } else if (method.equalsIgnoreCase("asserttext")) { try { this.setImpilicitTimeInMiliSec(new Integer(timeout)); Thread.sleep(100); String actual = control.getText(); if (actual == null || actual.isEmpty()) { actual = control.getAttribute("value"); printMessage( "**** Control won't have Text Value. Extracted Value using attribute Name=value. Found value= " + actual + " for " + this.controlIdentifier + ":" + addMessage()); } this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage() + ", actual=" + actual); printMessage("**** verifying Text Value= " + actual + " for " + this.controlIdentifier + ":" + addMessage()); if (actual != null && !actual.isEmpty()) { if (value != null && value.contains("@")) { this.addTestExtract(value, actual); } else { this.assertText(value, actual); } return control; } } catch (Exception e) { } } else if (method.equalsIgnoreCase("sendKeys")) { this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + " value=" + addMessage()); this.setImpilicitTimeInMiliSec(new Integer(timeout)); while (!control.isDisplayed()) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); } Thread.sleep(100); control.sendKeys(sendkeyValue); this.timeTaken = this.timeTaken + (System.currentTimeMillis() - executionTime); printMessage("**** Entered Value= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); return control; } } } catch (NumberFormatException e) { this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); // TODO Auto-generated catch block String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } catch (InterruptedException e) { // TODO Auto-generated catch block this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } catch (Exception e) { // TODO Auto-generated catch block this.printCommand( " FAILED with Exception for Command=" + this.tagdesc + " for control with identifier=" + this.controlIdentifier + " file=" + addMessage() + "\n Message=" + e.getMessage()); this.printCommand(WmLog.getStackTrace(e)); String v_msg = ">>Dataset:" + this.threadIndex + " FAILED TO EXECUTE CONTROL IN " + addMessage() + " " + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage()); e.printStackTrace(); throw new TestMaxException(v_msg); //handleTimeOut(v_msg); } //if you are here then quit //driver.quit(); return null; }
From source file:com.twiceagain.rservejavademo.webaccess.BasicDriverTest.java
/** * Test of _getDriver method, of class BasicDriver. * @throws java.lang.InterruptedException */// w w w . j a va 2s . c o m @Test public void testGetDriver() throws InterruptedException { System.out.println("getDriver"); WebDriver expResult = null; WebDriver wd = BasicDriver.getDriver(); wd.get("http://www.google.fr"); Thread.sleep(1000); assert (wd.getTitle().contains("Google")); WebElement searchBox = wd.findElement(By.name("q")); searchBox.sendKeys("ChromeDriver test"); searchBox.submit(); Thread.sleep(5000); // Let the user actually see something! wd.close(); }
From source file:com.vmware.gemfire.tools.pulse.testbed.driver.PulseUITest.java
License:Apache License
private static void loginToPulse(WebDriver driver, String userName, String password) { driver.get(pulseURL);// www.j av a 2 s .co m WebElement userNameElement = driver.findElement(By.id("user_name")); WebElement passwordElement = driver.findElement(By.id("user_password")); userNameElement.sendKeys(userName); passwordElement.sendKeys(password); passwordElement.submit(); WebElement userNameOnPulsePage = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver d) { return d.findElement(By.id("userName")); } }); assertNotNull(userNameOnPulsePage); }
From source file:com.vmware.gemfire.tools.pulse.tests.PulseAbstractTest.java
License:Apache License
public static void setUpServer(String username, String password, String jsonAuthFile) throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); jmxPropertiesFile = classLoader.getResource("test.properties").getPath(); path = getPulseWarPath();//from ww w. j a va2s . com server = Server.createServer(9999, jmxPropertiesFile, jsonAuthFile); String host = "localhost"; int port = 8080; String context = "/pulse"; jetty = JettyHelper.initJetty(host, port, false, false, null, null, null); JettyHelper.addWebApplication(jetty, context, getPulseWarPath()); jetty.start(); pulseURL = "http://" + host + ":" + port + context; Awaitility.await().until(() -> jetty.isStarted()); driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get(pulseURL); WebElement userNameElement = driver.findElement(By.id("user_name")); WebElement passwordElement = driver.findElement(By.id("user_password")); userNameElement.sendKeys(username); passwordElement.sendKeys(password); passwordElement.submit(); Thread.sleep(3000); WebElement userNameOnPulsePage = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver d) { return d.findElement(By.id("userName")); } }); assertNotNull(userNameOnPulsePage); driver.navigate().refresh(); Thread.sleep(7000); }
From source file:com.vmware.gemfire.tools.pulse.tests.PulseTest.java
License:Apache License
@BeforeClass public static void setUpBeforeClass() throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); jmxPropertiesFile = classLoader.getResource("test.properties").getPath(); path = getPulseWarPath();/*from www. java 2 s . c o m*/ server = Server.createServer(9999, jmxPropertiesFile); String host = "localhost";// InetAddress.getLocalHost().getHostAddress(); int port = 8080; String context = "/pulse"; jetty = JettyHelper.initJetty(host, port, false, false, null, null, null); JettyHelper.addWebApplication(jetty, context, getPulseWarPath()); jetty.start(); pulseURL = "http://" + host + ":" + port + context; Thread.sleep(5000); // wait till the container settles down driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.get(pulseURL); WebElement userNameElement = driver.findElement(By.id("user_name")); WebElement passwordElement = driver.findElement(By.id("user_password")); userNameElement.sendKeys(userName); passwordElement.sendKeys(pasword); passwordElement.submit(); Thread.sleep(3000); WebElement userNameOnPulsePage = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver d) { return d.findElement(By.id("userName")); } }); Assert.assertNotNull(userNameOnPulsePage); driver.navigate().refresh(); Thread.sleep(7000); }
From source file:com.vmware.veei.qe.devcenter.SampleExchangeTest.java
/** * S87854: [Sample Exchange] Search and browse for code samples *///from ww w .j a v a2 s . com @Test(groups = { "test", "stage" }) @NavigateTo(SAMPLE_CODE_URL) public void testSampleCodeSearchBrowse() { String titleText = "stest"; // #action 1: Adding sample addSample(titleText); // #action 2: Navigate to default page. driver.get(baseUrl + SAMPLE_CODE_URL); selectTab("Samples"); int defaultSampleCodeCount = driver.findElements(By.cssSelector("#search-results-list .title-list li")) .size(); // #action 3: Filter search input check WebElement filterSearchRadioButton = driver.findElement(By.cssSelector("input[value='Python']")); filterSearchRadioButton.click(); int filterSearchCount = driver.findElements(By.cssSelector("#search-results-list .title-list li")).size(); // #expects: Search result should be less then by default result for Filter Search assertThat(defaultSampleCodeCount).isGreaterThanOrEqualTo(filterSearchCount); // #action 4: Navigate to default page. selectTab("Samples"); WebElement globalSearchInputField = driver .findElement(By.cssSelector("#main-content .internal-global-search .search input[type='text']")); // #action 5: Giving text input for search text global search text input globalSearchInputField.sendKeys(titleText); globalSearchInputField.submit(); int sampleCodeSearchCount = driver.findElements(By.cssSelector("#search-results-list .title-list li")) .size(); // #expects: Search result should be less then by default result for Global Search if (defaultSampleCodeCount > 0) { assertThat(defaultSampleCodeCount).isGreaterThanOrEqualTo(sampleCodeSearchCount); } // #action 6: Select Tab : My sample selectTab("My Samples"); // #action 7 : Selecting latest first Select dropdown = new Select(driver.findElement(By.cssSelector("#search-results-sort-by"))); dropdown.selectByIndex(2); List<WebElement> sampleCodeLinkList = driver .findElements(By.cssSelector("#search-results-list .title-list li")); if (sampleCodeSearchCount >= 1) { for (WebElement samplecodelink : sampleCodeLinkList) { String linkHeadText = samplecodelink.findElement(By.cssSelector(".title")).getText(); if (linkHeadText.equals(titleText)) { samplecodelink.click(); samplecodelink.findElement(By.cssSelector("div a")).click(); String sampleCodePageHeadText = driver.findElement(By.cssSelector(".header .span9 h1 ")) .getText(); // #expects: Validating browsed link header with headText assertThat(linkHeadText).isEqualTo(sampleCodePageHeadText); // #expects: Checking Faveroite link WebElement favoriteLink = driver.findElement(By.cssSelector(".favoriteHeart")); String favoriteCount = favoriteLink.getText(); favoriteLink.click(); assertThat(driver.findElement(By.cssSelector(".favoriteHeart"))).isNotEqualTo(favoriteCount); // #action 8: Deleting created JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("$('.sample-delete-dialog').submit();"); new WebDriverWait(driver, 10).until( ExpectedConditions.presenceOfElementLocated(By.cssSelector("#search-results-list"))); break; } } } }
From source file:com.vmware.veei.qe.devcenter.SampleExchangeTest.java
/** * S87854: [Sample Exchange] Search and browse for Sample Requests *//*www . j ava 2s . c om*/ @Test(groups = { "test", "stage" }) @NavigateTo(SAMPLE_CODE_URL) public void testSampleRequestSearchBrowse() { // #action 1: Selecting request tab selectTab("Requests"); // #action 2: Adding request String titleText = "Rtest"; String language = "java"; String sdkTool = "Airwatch"; addRequest(titleText, language, sdkTool); // #action 3: Navigating to the default page after adding request driver.get(baseUrl + SAMPLE_CODE_URL); selectTab("Requests"); // Total count of sample code presented int defaultRequestCount = driver.findElements(By.cssSelector("#search-results-list .title-list li")).size(); // Filter search input check WebElement filterSearchRadioButton = driver.findElement(By.cssSelector("input[value='Python']")); filterSearchRadioButton.click(); int filterSearchCount = driver.findElements(By.cssSelector("#search-results-list .title-list li")).size(); // #expects: Search result should be less then by default result for Filter Search assertThat(defaultRequestCount).isGreaterThanOrEqualTo(filterSearchCount); // #action 4: Navigating to the default page selectTab("Requests"); WebElement globalSearchInputField = driver .findElement(By.cssSelector("#main-content .internal-global-search .search input[type='text']")); // #action 5: Giving text input for search text global search text input globalSearchInputField.sendKeys(titleText); globalSearchInputField.submit(); // #action 6: Count the total search result int requestSearchCount = driver.findElements(By.cssSelector("#search-results-list .title-list li")).size(); // #expects: Search result should be less then by default result for Global Search if (defaultRequestCount > 0) { assertThat(defaultRequestCount).isGreaterThanOrEqualTo(requestSearchCount); } // #action 7: Select Tab : My request selectTab("My Requests"); // #action 8 : Selecting latest first Select dropdown = new Select(driver.findElement(By.cssSelector("#search-results-sort-by"))); dropdown.selectByIndex(2); List<WebElement> requestLinkList = driver .findElements(By.cssSelector("#search-results-list .title-list li")); if (requestSearchCount >= 1) { for (WebElement requestlink : requestLinkList) { String linkHeadText = requestlink.findElement(By.cssSelector("div a")).getText(); if (linkHeadText.equals(titleText)) { requestlink.click(); requestlink.findElement(By.cssSelector("div a")).click(); String requestlinkPageHeadText = driver.findElement(By.cssSelector(".header-title h1 ")) .getText(); // #expects: Validating browsed link header assertThat(linkHeadText).isEqualTo(requestlinkPageHeadText); // #action 9: Deleting created JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("$('.request-delete-dialog').submit();"); new WebDriverWait(driver, 10).until( ExpectedConditions.presenceOfElementLocated(By.cssSelector("#search-results-list"))); break; } } } }