List of usage examples for org.openqa.selenium WebElement isDisplayed
boolean isDisplayed();
From source file:com.testmax.handler.SeleniumBaseHandler.java
License:CDDL license
protected List<WebElement> getWebElements() throws NumberFormatException, TestMaxException { List<WebElement> elms = this.getPrimaryElement(); List<WebElement> selms = new ArrayList<WebElement>(); List<WebElement> havings = new ArrayList<WebElement>(); PrintTime timer = new PrintTime(); int msgcount = 1; if (elms != null) { for (WebElement elm : elms) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); try { havings = getElementByHaving(elm); } catch (Exception e) { printMessage(getExceptionMessage(e)); }//from www .jav a2 s .c om if (havings != null && havings.size() > 0) { if (msgcount == elms.size() || msgcount == 1) { printMessage("**** ELEMENT WITH HAVING FOUND " + timer.getPrintTime() + ">> BY Identifier=" + this.controlIdentifier + ">>" + this.tagdesc); msgcount++; } if (timer.getTime() > maxTimeToWait * 1000) { String msg = "****EXCEPTION: WAITING PERIOD EXCEEDS TO DISPLAY ELEMENT " + maxTimeToWait * 1000 + " mili (sec)>> BY Identifier=" + this.controlIdentifier + ">>" + this.tagdesc; throw new TestMaxException(msg); } for (WebElement target : havings) { try { if (target.isDisplayed()) { selms.add(target); } } catch (Exception e) { if (timer.getTime() > maxTimeToWait * 1000) { String msg = "****EXCEPTION: WAITING PERIOD EXCEEDS TO DISPLAY ELEMENT " + maxTimeToWait * 1000 + " mili (sec)>> BY Identifier=" + this.controlIdentifier + ">>" + this.tagdesc; throw new TestMaxException(msg); } } } } } } if (secondary.keySet().isEmpty() && (this.havingTag == null || this.havingTag.isEmpty())) { return elms; } if (selms.size() < 1) { try { if (this.value != null && this.value.contains("@")) { this.getScreenShot(this.value.split("@")[1]); } } catch (WebDriverException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TestMaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } String msg = "$$$$$ ELEMENT WITH HAVING NOT FOUND " + timer.getPrintTime() + ">> BY Identifier=" + this.controlIdentifier + ">>" + this.tagdesc; printMessage(msg); } return selms; }
From source file:com.testmax.handler.SeleniumBaseHandler.java
License:CDDL license
protected boolean executeOperation() throws TestMaxException { PrintTime timer = new PrintTime(); String elmId = ""; WebElement elm = null; if (this.isEmptyValue(this.tagName) && !this.isEmptyValue(this.havingTag)) { this.tagName = this.havingTag; }//from ww w . j av a2 s . co m if (this.operation.equalsIgnoreCase("acceptalert")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); this.getDriver().switchTo().alert().accept(); this.printMessage("Invoked Custom Operation=" + this.operation); return true; } else if (this.operation.equalsIgnoreCase("runscript")) { this.setImpilicitTimeInMiliSec(new Integer(timeout)); try { Thread.sleep(100); this.executeScript(); this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier + "\n Script=" + addMessage()); printMessage("**** Executed Java Script= " + addMessage() + " for Control=" + this.controlIdentifier + ":" + addMessage()); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; } else if (this.operation.equalsIgnoreCase("closepopup")) { this.getElementByJavaScript(); return true; } if (this.havingAttribute != null && !this.havingAttribute.isEmpty()) { //first check if element present this.controlIdentifier = " tagname=" + this.tagName + " and havingAttribute" + "=" + this.havingAttribute; elm = getElementByTechnique(); //log element to re-record elementToReRecord(elm); //if(this.isCustomOperation() ){ try { if (this.operation.equalsIgnoreCase("read")) { this.readElement(elm); if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) { resetElementId(id); } return true; } else if (this.operation.equalsIgnoreCase("write")) { if (elm != null) { try { this.setImpilicitTimeInMiliSec(new Integer(timeout)); // this.waitForElement(this.getDriver().findElement(by), new Integer(timeout)); elm.sendKeys(this.sendkeyValue); if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) { resetElementId(id); } } catch (Exception e) { if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) { resetElementId(id); } } } //resetElementId(); return true; } else if (this.operation.equalsIgnoreCase("click")) { //waitToPageLoad(new Integer(timeout)); if (elm != null) { try { this.setImpilicitTimeInMiliSec(new Integer(timeout)); new Actions(this.getDriver()).moveToElement(elm).click().build().perform(); //this.mouseMove(elm); String menuclick = ConfigLoader.getConfig("MENU_CLICK_NUMBER"); if (menuclick == null || !menuclick.equals("1")) { try { if (this.v_driver.equalsIgnoreCase("firefox") && elm.isDisplayed()) { Thread.sleep(500); elm = this.getDriver().findElement(By.id(elmId)); new Actions(this.getDriver()).moveToElement(elm).click().build().perform(); //this.mouseMove(elm); } } catch (Exception e) { if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) { resetElementId(id); } } } waitToPageLoad(new Integer(timeout)); if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) { resetElementId(id); } return true; } catch (Exception e) { if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) { resetElementId(id); } } } } } catch (Exception e) { if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) { resetElementId(id); } printMessage("**** Failed to Execute Java Script " + timer.getPrintTime() + " Element id=" + this.id + " " + getExceptionMessage(e)); return false; } } if (this.havingAttribute == null || this.havingAttribute.isEmpty()) { throw new TestMaxException( "$$$$$$ERROR: Operation can not be executed since havingAttribute property for tag Element is Empty!! Please modify your XML configuration in Taglib."); } return false; }
From source file:com.testmax.runner.SeleniumTestRunner.java
License:CDDL license
protected WebElement executeClick(final WebElement control) { long start = System.currentTimeMillis(); WebElement element = null;/*from www. j a v a 2 s . co m*/ int addTimeOut = 0; int counter = 0; if (ConfigLoader.getConfig("SELENIUM_DRIVER") != null && ConfigLoader.getConfig("SELENIUM_DRIVER").equalsIgnoreCase("ie")) { addTimeOut = addTimeOut + new Integer(ConfigLoader.getConfig("SELENIUM_IE_EXTRA_TIME") == null ? "500" : ConfigLoader.getConfig("SELENIUM_IE_EXTRA_TIME")); } final int v_timeout = (this.timeout != null && !this.timeout.isEmpty() ? new Integer(this.timeout) : 500) + addTimeOut; try { //Set up a WebDriverWait to wait in second WebDriverWait driverWait = new WebDriverWait(this.driver, v_timeout, 500); //Define an ExpectedCondition ExpectedCondition<WebElement> expectedCondition = new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver d) { try { setImpilicitTimeInMiliSec(v_timeout); while (!control.isDisplayed()) { setImpilicitTimeInMiliSec(v_timeout); } control.click(); return control; } catch (TestMaxException t) { // TODO Auto-generated catch block t.printStackTrace(); } catch (NoSuchElementException ex) { } return null; }; }; //Find our web element while (element == null && counter < 10) { element = driverWait.until(expectedCondition); counter++; printMessage("CLICKING CONTROL BY TRIAL=" + counter + " >> Time=(" + (System.currentTimeMillis() - start) + ") mili Sec '" + this.tagdesc + "' >> with Id=" + this.controlIdentifier + addMessage()); } //this.setImplicitTime(); this.timeTaken = this.timeTaken + System.currentTimeMillis() - start; printMessage("EXECUTED CONTROL >> Time=(" + (System.currentTimeMillis() - start) + ") mili Sec '" + this.tagdesc + "' >> with Id=" + this.controlIdentifier + addMessage()); return element; } catch (Exception e) { this.printMessage("***FAILED TO EXECUTE CONTROL >> Time=(" + (System.currentTimeMillis() - start) + ") mili Sec '" + this.tagdesc + "' >> with Id=" + this.controlIdentifier + " :" + (e.getMessage() != null && e.getMessage().length() > 100 ? e.getMessage().substring(0, 100) : e.getMessage())); return null; } }
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 {/*from ww w .ja v a 2s. 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 {//w w w .j av a 2s. co 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 {/*w w w. j a v a 2 s. com*/ 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.testmax.track.BaseTrack.java
License:CDDL license
public boolean isElementDisplayed(By by) { try {/* ww w . j av a 2 s . co m*/ List<WebElement> elms = driver.findElements(by); for (WebElement elm : elms) { if (elm != null && elm.isDisplayed()) { return true; } } } catch (NoSuchElementException e) { return false; } return false; }
From source file:com.triangleleft.flashcards.PhoneMainTest.java
License:Open Source License
private void checkNotVisible(WebElement element) { appiumRule.getTimeOutDuration().setTime(0); boolean displayed = false; try {//w w w .j a v a 2s . c om displayed = element.isDisplayed(); } catch (NoSuchElementException e) { // Ignored; } assertThat(displayed, is(false)); appiumRule.getTimeOutDuration().setTime(60); }
From source file:com.twiceagain.rservejavademo.extract.FTree.java
private void initFTree(WebDriver wd, WebElement we, FTree parent) { if (parent != null) { this.parent = parent; depth = parent.getDepth() + 1;/* w w w . j a v a 2s .c om*/ path.addAll(parent.path); path.add(we.getTagName()); } if (we != null) { tag = we.getTagName(); visible = we.isDisplayed(); if (isVisible()) { Dimension d = we.getSize(); width = d.width; height = d.height; Point p = we.getLocation(); x = p.x; y = p.y; area = getWidth() * getHeight(); ratio = (getHeight() == 0) ? 0 : getWidth() / getHeight(); text = we.getText(); } attributes.putAll(BasicDriver.getAttributes(wd, we)); String cl = attributes.get("class"); if (cl != null) { classList.addAll(Arrays.asList(cl.split("\\s+"))); } List<WebElement> lwe = we.findElements(By.xpath("./*")); for (WebElement w : lwe) { FTree cc = new FTree(wd, w, this); getChildren().add(cc); } } }
From source file:com.vaadin.addon.spreadsheet.elements.SpreadsheetElement.java
License:Open Source License
private void scrollSheetVisible(WebElement targetSheet) { // Make sure the target sheet is visible if (!targetSheet.isDisplayed()) { scrollSheetsToStart();/*from w w w .j a va2s . c o m*/ while (!targetSheet.isDisplayed()) { scrollSheets(1); } } }