List of usage examples for org.openqa.selenium Keys SHIFT
Keys SHIFT
To view the source code for org.openqa.selenium Keys SHIFT.
Click Source Link
From source file:com.digi.selenium.util.PageNavigation.java
protected void extra() { try {/*from w w w . j a v a 2s . c o m*/ JavascriptExecutor jse = (JavascriptExecutor) getDriver(); jse.executeScript("window.scrollBy(0,500)", ""); // WebElement fb = (new WebDriverWait(fbdriver, 5000)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='main']/section/div/ul/li[1]/a"))); // fb.click(); //*[@id="main"]/section/div/ul/li[1]/a WebElement fb = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[1]/a")); Actions newTab1 = new Actions(getDriver()); newTab1.keyDown(Keys.SHIFT).click(fb).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(500); //handle windows change String base1 = getDriver().getWindowHandle(); Set<String> set1 = getDriver().getWindowHandles(); set1.remove(base1); assert set1.size() == 1; getDriver().switchTo().window((String) set1.toArray()[0]); waitForPageLoad(500); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='blueBarNAXAnchor']/div/div/div/div[1]/h1/a/i"))); //close the window getDriver().close(); getDriver().switchTo().window(base1); // handle windows change and switch back to the main window Thread.sleep(500); for (String winHandle1 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle1); // System.out.println("extra : FB Passed" ); log.info("FB Link Passed"); Thread.sleep(500); //*[@id="main"]/section/div/ul/li[2]/a WebElement tw = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[2]/a")); Actions newTab2 = new Actions(getDriver()); newTab2.keyDown(Keys.SHIFT).click(tw).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(500); //handle windows change String base2 = getDriver().getWindowHandle(); Set<String> set2 = getDriver().getWindowHandles(); set2.remove(base2); assert set2.size() == 1; getDriver().switchTo().window((String) set2.toArray()[0]); waitForPageLoad(500); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='page-container']/div[2]/div/div/div[1]/div/div/div/div[1]/h1/a"))); //close the window getDriver().close(); getDriver().switchTo().window(base2); // handle windows change and switch back to the main window Thread.sleep(2500); for (String winHandle2 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle2); // System.out.println("extra : Twitter Passed" ); log.info("Twitter Link Passed"); Thread.sleep(5000); //*[@id="main"]/section/div/ul/li[3]/a WebElement com = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[3]/a")); Actions newTab3 = new Actions(getDriver()); newTab3.keyDown(Keys.SHIFT).click(com).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(5000); //handle windows change String base3 = getDriver().getWindowHandle(); Set<String> set3 = getDriver().getWindowHandles(); set3.remove(base3); assert set3.size() == 1; getDriver().switchTo().window((String) set3.toArray()[0]); waitForPageLoad(5000); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='mainNav']/div[1]/div[1]/a"))); //close the window getDriver().close(); getDriver().switchTo().window(base3); // handle windows change and switch back to the main window Thread.sleep(2500); for (String winHandle3 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle3); // System.out.println("extra : Community Passed" ); log.info("Community Link Passed"); Thread.sleep(500); JavascriptExecutor jse1 = (JavascriptExecutor) getDriver(); jse1.executeScript("window.scrollBy(0,-500)", ""); } } } } catch (Exception e) { log.error("Failed to verify Social Media Links"); } }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @exception Exception If the test fails *//* w w w. j a v a 2 s . co m*/ @Test @BuggyWebDriver(IE) public void shiftClick() throws Exception { final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND + "'>Click Me</a>\n" + "</form></body></html>"; getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>"); final WebDriver driver = loadPage2(html); final WebElement link = driver.findElement(By.linkText("Click Me")); final String originalTitle = driver.getTitle(); final int windowsSize = driver.getWindowHandles().size(); new Actions(driver).moveToElement(link).keyDown(Keys.SHIFT).click().keyUp(Keys.SHIFT).perform(); assertEquals("Should have opened a new window", windowsSize + 1, driver.getWindowHandles().size()); assertEquals("Should not have navigated away", originalTitle, driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSelect2Test.java
License:Apache License
/** * @exception Exception If the test fails *//*from w ww. j a va2s. c o m*/ @Test @BuggyWebDriver(IE) public void shiftClick() throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'><select name='select1' multiple>\n" + " <option value='option1'>Option1</option>\n" + " <option value='option2'>Option2</option>\n" + " <option value='option3' selected='selected'>Option3</option>\n" + " <option value='option4'>Option4</option>\n" + "</select>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>"; final WebDriver driver = loadPage2(html); final List<WebElement> options = driver.findElements(By.tagName("option")); final Actions actions = new Actions(driver); final Action selectThreeOptions = actions.click(options.get(1)).keyDown(Keys.SHIFT).click(options.get(3)) .keyUp(Keys.SHIFT).build(); selectThreeOptions.perform(); assertFalse(options.get(0).isSelected()); assertTrue(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); assertTrue(options.get(3).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test./* w w w. j a va 2s . c om*/ */ @Test public void shiftSelectionDeletes() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys("abcd efgh"); assertThat(element.getAttribute("value"), is("abcd efgh")); element.sendKeys(Keys.SHIFT, Keys.LEFT, Keys.LEFT, Keys.LEFT); element.sendKeys(Keys.DELETE); assertThat(element.getAttribute("value"), is("abcd e")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test./*from w w w . j av a 2s . co m*/ */ @Test public void chordControlHomeShiftEndDelete() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement result = driver.findElement(By.id("result")); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys("!\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFG"); element.sendKeys(Keys.HOME); element.sendKeys("" + Keys.SHIFT + Keys.END); assertThat(result.getText(), containsString(" up: 16")); element.sendKeys(Keys.DELETE); assertThat(element.getAttribute("value"), is("")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.// w w w . j av a2s . c o m */ @Test public void chordReveseShiftHomeSelectionDeletes() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement result = driver.findElement(By.id("result")); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys("done" + Keys.HOME); assertThat(element.getAttribute("value"), is("done")); element.sendKeys("" + Keys.SHIFT + "ALL " + Keys.HOME); assertThat(element.getAttribute("value"), is("ALL done")); element.sendKeys(Keys.DELETE); assertThat(element.getAttribute("value"), is("done")); element.sendKeys("" + Keys.END + Keys.SHIFT + Keys.HOME); assertThat(element.getAttribute("value"), is("done")); // Note: trailing SHIFT up here assertThat(result.getText().trim(), containsString(" up: 16")); element.sendKeys("" + Keys.DELETE); assertThat(element.getAttribute("value"), is("")); }
From source file:com.lazerycode.ebselen.CreateTestCode.java
License:Apache License
public String convertCommandToEbselenCode(String seleniumCommand, String target, String value) throws Exception { ideCommand command;/*from w w w. ja v a2s.c o m*/ try { command = ideCommand.valueOf(seleniumCommand.trim().toUpperCase()); } catch (Exception ex) { throw new IDECommandNotFoundException("Unable to match command to known list of commands!"); } //TODO remove variable below String testData = ""; switch (command) { case ADDLOCATIONSTRATEGY: case ADDLOCATIONSTRATEGYANDWAIT: return "LOGGER.warn(\"Custom locator strategies are not supported!\")"; case ADDSCRIPT: case ADDSCRIPTANDWAIT: // LOGGER.error("Function not implemented yet. Raise a request to get it implemented"); //TODO case ADDSELECTION: case ADDSELECTIONANDWAIT: return select.selectByVisibleText(target, value); case ALLOWNATIVEXPATH: case ALLOWNATIVEXPATHANDWAIT: return "LOGGER.warn(\"Modifying the XPath implementation mid test is not supported!\")"; case ALTKEYDOWN: case ALTKEYDOWNANDWAIT: return action.keyboard().pressKey(Keys.ALT); case ALTKEYUP: case ALTKEYUPANDWAIT: return action.keyboard().releaseKey(Keys.ALT); case ANSWERONNEXTPROMPT: return driver.switchTo().alert().sendKeys(target); case ASSERTALERT: return com.assertEquals(driver.switchTo().alert().getText(), value); case ASSERTALERTNOTPRESENT: //TODO case ASSERTALERTPRESENT: //TODO case ASSERTALLBUTTONS: //TODO case ASSERTALLFIELDS: //TODO case ASSERTALLLINKS: //TODO case ASSERTALLWINDOWIDS: //TODO case ASSERTALLWINDOWNAMES: //TODO case ASSERTALLWINDOWTITLES: //TODO case ASSERTATTRIBUTE: //TODO case ASSERTATTRIBUTEFROMALLWINDOWS: //TODO case ASSERTBODYTEXT: //TODO case ASSERTCHECKED: return com.assertTrue(ebselen.element().isChecked(target)); case ASSERTCONFIRMATION: //TODO case ASSERTCONFIRMATIONNOTPRESENT: //TODO case ASSERTCONFIRMATIONPRESENT: //TODO case ASSERTCOOKIE: //TODO case ASSERCOOKIEBYNAME: return com.assertEquals(driver.manage().getCookieNamed(target), value); case ASSERTCOOKIENOTPRESENT: //TODO case ASSERTCOOKIEPRESENT: //TODO case ASSERTCSSCOUNT: return com.assertEquals(driver.findElements(loc.locatorAsString(target)).size(), value); case ASSERTCURSORPOSITION: //TODO only for input element of textarea gets numerical position of cursor in field case ASSERTEDITABLE: return com.assertTrue(driver.findElement(loc.locatorAsString(target)).isEnabled()); case ASSERTELEMENTHEIGHT: return com.assertEquals(driver.findElement(loc.locatorAsString(target)).getCssValue("height"), value); case ASSERTELEMENTINDEX: //TODO case ASSERTELEMENTNOTPRESENT: return com.assertFalse(ebselen.element().doesElementExist(loc.locatorAsString(target))); case ASSERTELEMENTPOSITIONLEFT: //TODO case ASSERTELEMENTPOSITIONTOP: //TODO case ASSERTELEMENTPRESENT: return com.assertTrue(ebselen.element().doesElementExist(loc.locatorAsString(target))); case ASSETELEMENTWIDTH: return com.assertEquals(driver.findElement(loc.locatorAsString(target)).getCssValue("width"), value); case ASSERTEVAL: //TODO case ASSERTEXPRESSION: //TODO case ASSERTHTMLSOURCE: //TODO case ASSERTLOCATION: return com.assertEquals(driver.getCurrentUrl(), target); case ASSERTMOUSESPEED: //TODO case ASSERTNOTALERT: //TODO case ASSERTNOTALLBUTTONS: //TODO case ASSERTNOTALLFIELDS: //TODO case ASSERTNOTALLLINKS: //TODO case ASSERTNOTALLWINDOWIDS: //TODO case ASSERTNOTALLWINDOWNAMES: //TODO case ASSERTNOTALLWINDOWTITLES: //TODO case ASSERTNOTATTRIBUTE: //TODO case ASSERTNOTATTRIBUTEFROMALLWINDOWS: //TODO case ASSERTNOTBODYTEXT: //TODO case ASSERTNOTCHECKED: return com.assertFalse(ebselen.element().isChecked(target)); case ASSERTNOTCONFIRMATION: //TODO case ASSERTNOTCOOKIE: //TODO case ASSERTNOTCOOKIEBYNAME: //TODO case ASSERTNOTCSSCOUNT: return com.assertNotEquals(driver.findElements(loc.locatorAsString(target)).size(), value); case ASSERTNOTCURSORPOSITION: //TODO case ASSERTNOTEDITABLE: return com.assertFalse(driver.findElement(loc.locatorAsString(target)).isEnabled()); case ASSERTNOTELEMENTHEIGHT: //TODO case ASSERTNOTELEMENTINDEX: //TODO case ASSERTNOTELEMENTPOSITIONLEFT: //TODO case ASSERTNOTELEMENTPOSITIONTOP: //TODO case ASSERTNOTELEMENTWIDTH: //TODO case ASSERTNOTEVAL: //TODO case ASSERTNOTEXPRESSION: //TODO case ASSERTNOTHTMLSOURCE: //TODO case ASSERTNOTLOCATION: //TODO case ASSERTNOTMOUSESPEED: //TODO case ASSERTNOTORDERED: //TODO case ASSERTNOTPROMPT: //TODO case ASSERTNOTSELECTOPTIONS: //TODO case ASSERTNOTSELECTEDID: //TODO case ASSERTNOTSELECTEDIDS: //TODO case ASSERTNOTSELECTEDINDEX: //TODO case ASSERTNOTSELECTEDINDEXES: //TODO case ASSERTNOTSELECTELABEL: //TODO case ASSERTNOTSELECTEDLABELS: //TODO case ASSERTNOTSELECTEDVALUE: //TODO case ASSERTNOTSELECTEDVALUES: //TODO case ASSERTNOTSOMETHINGSELECTED: //TODO case ASSERTNOTSPEED: //TODO case ASSERTNOTTABLE: //TODO case ASSERTNOTTEXT: //TODO case ASSERTNOTTITLE: //TODO case ASSERTNOTVALUE: //TODO case ASSERTNOTVISIBLE: //TODO case ASSERTNOTWHETHERTHISFRAMEMATCHFRAMEEXPRESSION: //TODO case ASSERTNOTWHETHERTHISWINDOWMATCHWINDOWEXPRESSION: //TODO case ASSERTNOTXPATHCOUNT: return com.assertNotEquals(value, driver.findElements(loc.locatorAsString(target)).size()); case ASSERTORDERED: //TODO case ASSERTPROMPT: //TODO case ASSERTPROMPTNOTPRESENT: //TODO case ASSERTPROMPTPRESENT: //TODO case ASSERTSELECTOPTIONS: //TODO case ASSERTSELECTEDID: //TODO case ASSERTSELECTEDIDS: //TODO case ASSERTSELECTEDINDEX: //TODO case ASSERTSELECTEDINDEXES: //TODO case ASSERTSELECTEDLABEL: //TODO case ASSERTSELECTEDLABELS: //TODO case ASSERTSELECTEDVALUE: //TODO case ASSERTSELECTEDVALUES: //TODO case ASSERTSOMETHINGSELECTED: //TODO case ASSERTSPEED: //TODO case ASSERTTABLE: //TODO case ASSERTTEXT: return com.assertEquals(driver.findElement(loc.locatorAsString(target)).getText(), value); case ASSERTTEXTNOTPRESENT: testData += "assertFalse(isElementPresent(\"//*[contains(, '" + value + "')]\"));"; //TODO case ASSERTTEXTPRESENT: //TODO case ASSERTTITLE: return com.assertEquals(driver.findElement(loc.locatorAsString("tag=title")).getText(), value); case ASSERTVALUE: return com.assertEquals(value, driver.findElement(loc.locatorAsString(target)).getAttribute("value")); case ASSERTVISIBLE: return com.assertTrue(driver.findElement(loc.locatorAsString(target)).isDisplayed()); case ASSERTWHETHERTHISFRAMEMATCHEFRAMEEXPRESSION: //TODO case ASSERTWHETHERTHISWINDOWMATCHEWINDOWEXPRESSION: //TODO case ASSERTXPATHCOUNT: return com.assertEquals(value, driver.findElements(loc.locatorAsString(target)).size()); case ASSIGNID: case ASSIGNIDANDWAIT: return createWebElement(value, driver.findElement(loc.locatorAsString(target)).toString()); case CAPTUREENTIREPAGESCREENSHOT: case CAPTUREENTIREPAGESCREENSHOTANDWAIT: return ebselen.window().takeScreenshot(); case CHECK: case CHECKANDWAIT: return ebselen.element().check(target); case CHOOSECANCELONNEXTCONFIRMATION: // return driver.switchTo().alert().dismiss(); //TODO case CHOOSEOKONNEXTCONFIRMATION: case CHOOSEOKONNEXTCONFIRMATIONANDWAIT: // return driver.switchTo().alert().accept(); //TODO case CLICK: case CLICKANDWAIT: return driver.findElement(loc.locatorAsString(target)).click(); case CLICKAT: case CLICKATANDWAIT: action.mouse().click(coords(value, target)); case CLOSE: return driver.close(); case CONTEXTMENU: case CONTEXTMENUANDWAIT: return action.mouse().contextClick( returnCoordinates(driver.findElement(loc.locatorAsString(target)).getLocation().toString())); case CONTEXTMENUAT: case CONTEXTMENUATANDWAIT: return action.mouse().contextClick(coords(value, target)); case CREATECOOKIE: case CREATECOOKIEANDWAIT: // driver.manage().addCookie() //TODO case DELETEALLVISIBLECOOKIES: case DELETEALLVISIBLECOOKIESANDWAIT: return driver.manage().deleteAllCookies(); case DELETECOOKIE: case DELETECOOKIEANDWAIT: return driver.manage().deleteCookieNamed(target); case DESELECTPOPUP: case DESELECTPOPUPANDWAIT: return driver.switchTo().defaultContent(); case DOUBLECLICK: case DOUBLECLICKANDWAIT: return action.mouse().doubleClick( returnCoordinates(driver.findElement(loc.locatorAsString(target)).getLocation().toString())); case DOUBLECLICKAT: case DOUBLECLICKATANDWAIT: return action.mouse().doubleClick(coords(value, target)); case DRAGDROP: case DRAGANDDROP: case DRAGDROPANDWAIT: case DRAGANDDROPANDWAIT: String[] dragAndDropCoords = value.split(",", 1); String dragAndDropX = driver.findElement(loc.locatorAsString(target)).getLocation().getX() + "+" + dragAndDropCoords[0]; String dragAndDropY = driver.findElement(loc.locatorAsString(target)).getLocation().getY() + "+" + dragAndDropCoords[1]; // return action.builder().clickAndHold(driver.findElement(loc.locatorAsString(target))) // .moveByOffset(Integer.parseInt(coords[0]), Integer.parseInt(coords[1])).click();"; //TODO case DRAGANDDROPTOOBJECT: case DRAGANDDROPTOOBJECTANDWAIT: testData += "coords = value.split(\",\");" + "builder.clickAndHold(driver.findElement(" + loc.locatorAsString(target) + ")).moveByOffset(Integer.parseInt(coords[0]), Integer.parseInt(coords[1])).release(driver.findElement(" + loc.locatorAsString(value) + "));"; //TODO case ECHO: return "LOGGER.info(\"{}\", " + value + ");"; case FIREEVENT: case FIREEVENTANDWAIT: return ebselen.javascript().triggerJavascriptEvent(value, driver.findElement(loc.locatorAsString(target)).toString()); case FOCUS: case FOCUSANDWAIT: //TODO focus on the element found below //((Locatable) driver.findElement(" + loc.locatorAsString(target) + ")).getLocationOnScreenOnceScrolledIntoView(); case GOBACK: case GOBACKANDWAIT: return driver.navigate().back(); case HIGHLIGHT: case HIGHLIGHTANDWAIT: //TODO case IGNOREATTRIBUTESWITHOUTVALUE: case IGNOREATTRIBUTESWITHOUTVALUEANDWAIT: //TODO case KEYDOWN: case KEYDOWNANDWAIT: return action.builder().keyDown(driver.findElement(loc.locatorAsString(target)).toString(), Keys.valueOf(value)); case KEYPRESS: case KEYPRESSANDWAIT: return driver.findElement(loc.locatorAsString(target)).sendKeys(value); case KEYUP: case KEYUPANDWAIT: return action.builder().keyUp(driver.findElement(loc.locatorAsString(target)).toString(), Keys.valueOf(value)); case METAKEYDOWN: case METAKEYDOWNANDWAIT: return action.builder().keyDown(driver.findElement(loc.locatorAsString(target)).toString(), Keys.META); case METAKEYUP: case METAKEYUPANDWAIT: return action.builder().keyUp(driver.findElement(loc.locatorAsString(target)).toString(), Keys.META); case MOUSEDOWN: case MOUSEDOWNANDWAIT: return action.mouse().mouseDown( returnCoordinates(driver.findElement(loc.locatorAsString(target)).getLocation().toString())); case MOUSEDOWNAT: case MOUSEDOWNATANDWAIT: return action.mouse().mouseDown(coords(value, target)); case MOUSEDOWNRIGHT: case MOUSEDOWNRIGHTANDWAIT: //return action.mouse().("(Coordinates)" + driver.findElement(loc.locatorAsString(target)).getLocation()); //TODO likemousedown but with context case MOUSEDOWNRIGHTAT: case MOUSEDOWNRIGHTATANDWAIT: //TODO case MOUSEMOVE: case MOUSEMOVEANDWAIT: return action.mouse().mouseMove( returnCoordinates(driver.findElement(loc.locatorAsString(target)).getLocation().toString())); case MOUSEMOVEAT: case MOUSEMOVEATANDWAIT: return action.mouse().mouseMove(coords(value, target)); case MOUSEOUT: case MOUSEOUTANDWAIT: //TODO case MOUSEOVER: case MOUSEOVERANDWAIT: return action.mouse().mouseMove( returnCoordinates(driver.findElement(loc.locatorAsString(target)).getLocation().toString())); case MOUSEUP: case MOUSEUPANDWAIT: return action.mouse().mouseUp( returnCoordinates(driver.findElement(loc.locatorAsString(target)).getLocation().toString())); case MOUSEUPAT: case MOUSEUPATANDWAIT: return action.mouse().mouseUp(coords(value, target)); case MOUSEUPRIGHT: case MOUSEUPRIGHTANDWAIT: //TODO case MOUSEUPRIGHTAT: case MOUSEUPRIGHTATANDWAIT: //TODO case OPEN: return driver.get(target); case OPENWINDOW: case OPENWINDOWANDWAIT: //TODO case PAUSE: return "Thread.sleep((long) Integer.parseInt(" + value + "));"; case REFRESH: case REFRESHANDWAIT: return driver.navigate().refresh(); case REMOVEALLSELECTIONS: case REMOVEALLSELECTIONSANDWAIT: return select.deselectAll(target); case REMOVESCRIPT: case REMOVESCRIPTANDWAIT: //TODO case REMOVESELECTION: case REMOVESELECTIONANDWAIT: return select.deselectByVisibleText(target, value); case ROLLUP: case ROLLUPANDWAIT: //TODO case RUNSCRIPT: case RUNSCRIPTANDWAIT: //TODO case SELECT: case SELECTANDWAIT: return select.selectByVisibleText(target, value); case SELECTFRAME: return driver.switchTo().frame(driver.findElement(loc.locatorAsString(target)).toString()); case SELECTPOPUP: case SELECTPOPUPANDWAIT: //TODO case SELECTWINDOW: //TODO case SETBROWSERLOGLEVEL: case SETBROWSERLOGLEVELANDWAIT: return "LOGGER.warn(\"Modifying the Log Level mid test is not supported!\")"; case SETMOUSESPEED: case SETMOUSESPEEDANDWAIT: //TODO case SETSPEED: case SETSPEEDANDWAIT: //TODO case SETTIMEOUT: return driver.manage().timeouts().setScriptTimeout(Long.parseLong(value), TimeUnit.MILLISECONDS); case SHIFTKEYDOWN: case SHIFTKEYDOWNANDWAIT: return action.keyboard().pressKey(Keys.SHIFT); case SHIFTKEYUP: case SHIFTKEYUPANDWAIT: return action.keyboard().releaseKey(Keys.SHIFT); case STORE: return store(value, target); case STOREALERT: return store(value, driver.switchTo().alert().getText()); case STOREALERTPRESENT: testData += "boolean alertVisible = false;" + "try {" + "driver.switchTo().alert();" + "alertVisible = true;" + "} catch (Exception Ex) {" + "//Alert doesn't exist" + "}" + "storedVariables.put(" + value + ", alertVisible);"; //TODO case STOREALLBUTTONS: //TODO check implementation... The IDE implementation stores ID's, not Elements return store(value, driver.findElements(loc.locatorAsString("(//input[@type='button'])|(//button)")).toString()); case STOREALLFIELDS: //TODO check implementation... The IDE implementation stores ID's, not Elements //TODO check if this should just be input[@type='text'] or textarea as well? return store(value, driver.findElements(loc.locatorAsString("//input[@type='text']")).toString()); case STOREALLLINKS: //TODO check implementation... The IDE implementation stores ID's, not Elements return store(value, driver.findElements(loc.locatorAsString("tag=a")).toString()); case STOREALLWINDOWIDS: case STOREALLWINDOWNAMES: case STOREALLWINDOWTITLES: return store(value, driver.getWindowHandles()); case STOREATTRIBUTE: String[] locatorDetails = target.split("@", 1); return store(value, driver.findElement(loc.locatorAsString(locatorDetails[0])).getAttribute(locatorDetails[1])); case STOREATTRIBUTEFROMALLWINDOWS: //TODO case STOREBODYTEXT: return store(value, driver.findElement(loc.locatorAsString("tag=body")).getText()); case STORECHECKED: return store(value, ebselen.element().isChecked(target)); case STORECONFIRMATION: //TODO case STORECONFIRMATIONPRESENT: //TODO case STORECOOKIE: //TODO case STORECOOKIEBYNAME: //TODO case STORECOOKIEPRSENT: //TODO case STORECSSCOUNT: return store(value, driver.findElements(loc.locatorAsString(target)).size()); case STORECURSORPOSITION: //TODO case STOREEDITABLE: return store(value, driver.findElement(loc.locatorAsString(target)).isEnabled()); case STOREELEMENTHEIGHT: return store(value, driver.findElement(loc.locatorAsString(target)).getSize().getHeight()); case STOREELEMENTINDEX: //TODO case STOREELEMENTPOSITIONLEFT: //TODO case STOREELEMENTPOSITIONTOP: //TODO case STOREELEMENTPRESENT: return store(value, ebselen.element().doesElementExist(loc.locatorAsString(target))); case STOREELEMENTWIDTH: return store(value, driver.findElement(loc.locatorAsString(target)).getSize().getWidth()); case STOREEVAL: //TODO case STOREEXPRESSION: //TODO case STOREHTMLSOURCE: return store(value, driver.getPageSource()); case STORELOCATION: return store(value, driver.getCurrentUrl()); case STOREMOUSESPEED: //TODO case STOREORDERED: //TODO case STOREPROMPT: //TODO case STOREPROMPTPRESENT: //TODO case STORESELECTOPTIONS: //TODO case STORESELECTEDID: //TODO case STORESELECTEDIDS: //TODO case STORESELECTEDINDEX: //TODO case STORESELECTEDINDEXES: //TODO case STORESELECTEDLABEL: //TODO case STORESELECTEDLABELS: //TODO case STORESELECTEDVALUE: //TODO case STORESELECTEDVALUES: //TODO case STORESOMETHINGSELECTED: //TODO case STORESPEED: //TODO case STORETABLE: //TODO case STORETEXT: //TODO case STORETEXTPRESENT: //TODO case STORETITLE: //TODO case STOREVALUE: //TODO case STOREVISIBLE: //TODO case STOREWHETHERTHISFRAMEMATCHFRAMEEXPRESSION: //TODO case STOREWHETHERTHISWINDOWMATCHWINDOWEXPRESSION: //TODO case STOREXPATHCOUNT: return store(value, driver.findElements(loc.locatorAsString(target)).size()); case SUBMIT: case SUBMITANDWAIT: driver.findElement(loc.locatorAsString(target)).submit(); case TYPE: case TYPEANDWAIT: case TYPEKEYS: case TYPEKEYSANDWAIT: return driver.findElement(loc.locatorAsString(target)).sendKeys(value); case UNCHECK: case UNCHECKANDWAIT: return ebselen.element().uncheck(target); case USEXPATHLIBRARY: case USEXPATHLIBRARYANDWAIT: //TODO case VERIFYALERT: return com.verifyEquals(driver.switchTo().alert().getText(), value); case VERIFYALERTNOTPRESENT: //TODO case VERIFYALERTPRESENT: //TODO case VERIFYALLBUTTONS: //TODO case VERIFYALLFIELDS: //TODO case VERIFYALLLINKS: //TODO case VERIFYALLWINDOWIDS: //TODO case VERIFYALLWINDOWNAMES: //TODO case VERIFYALLWINDOWTITLES: //TODO case VERIFYATTRIBUTE: //TODO case VERIFYATTRIBUTEFROMALLWINDOWS: //TODO case VERIFYBODYTEXT: //TODO case VERIFYCHECKED: return com.verifyTrue(com.assertFalse(ebselen.element().isChecked(target))); case VERIFYCONFIRMATION: //TODO case VERIFYCONFIRMATIONNOTPRESENT: //TODO case VERIFYCONFIRMATIONPRESENT: //TODO case VERIFYCOOKIE: //TODO case VERIFYCOOKIEBYNAME: //TODO case VERIFYCOOKIENOTPRESENT: //TODO case VERIFYCOOKIEPRESENT: //TODO case VERIFYCSSCOUNT: return com.verifyEquals(driver.findElements(loc.locatorAsString(target)).size(), value); case VERIFYCURSORPOSITION: //TODO case VERIFYEDITABLE: return com.verifyTrue(driver.findElement(loc.locatorAsString(target)).isEnabled()); case VERIFYELEMENTHEIGHT: return com.verifyEquals(driver.findElement(loc.locatorAsString(target)).getCssValue("height"), value); case VERIFYELEMENTINDEX: //TODO case VERIFYELEMENTNOTPRESENT: return com.verifyFalse(ebselen.element().doesElementExist(loc.locatorAsString(target))); case VERIFYELEMENTPOSITIONLEFT: //TODO case VERIFYELEMENTPOSITIONTOP: //TODO case VERIFYELEMENTPRESENT: return com.verifyTrue(ebselen.element().doesElementExist(loc.locatorAsString(target))); case VERIFYELEMENTWIDTH: return com.verifyEquals(driver.findElement(loc.locatorAsString(target)).getCssValue("width"), value); case VERIFYEVAL: //TODO case VERIFYEXPRESSION: //TODO case VERIFYHTMLSOURCE: //TODO case VERIFYLOCATION: //TODO case VERIFYMOUSESPEED: //TODO case VERIFYNOTALERT: //TODO case VERIFYNOTALLBUTTONS: //TODO case VERIFYNOTALLFIELDS: //TODO case VERIFYNOTALLLINKS: //TODO case VERIFYNOTALLWINDOWIDS: //TODO case VERIFYNOTALLWINDOWNAMES: //TODO case VERIFYNOTALLWINDOWTITLES: //TODO case VERIFYNOTATTRIBUTE: //TODO case VERIFYNOTATTRIBUTEFROMALLWINDOWS: //TODO case VERIFYNOTBODYTEXT: //TODO case VERIFYNOTCHECKED: return com.verifyFalse(com.assertFalse(ebselen.element().isChecked(target))); case VERIFYNOTCONFIRMATION: //TODO case VERIFYNOTCOOKIE: //TODO case VERIFYNOTCOOKIEBYNAME: //TODO case VERIFYNOTCSSCOUNT: return com.verifyNotEquals(driver.findElements(loc.locatorAsString(target)).size(), value); case VERIFYNOTCURSORPOSITION: //TODO case VERIFYNOTEDITABLE: return com.verifyFalse(driver.findElement(loc.locatorAsString(target)).isEnabled()); case VERIFYNOTELEMENTHEIGHT: return com.verifyNotEquals(driver.findElement(loc.locatorAsString(target)).getCssValue("height"), value); case VERIFYNOTELEMENTINDEX: //TODO case VERIFYNOTELEMENTPOSITIONLEFT: //TODO case VERIFYNOTELEMENTPOSITIONTOP: //TODO case VERIFYNOTELEMENTWIDTH: return com.verifyNotEquals(driver.findElement(loc.locatorAsString(target)).getCssValue("width"), value); case VERIFYNOTEVAL: //TODO case VERIFYNOTEXPRESSION: //TODO case VERIFYNOTHTMLSOURCE: //TODO case VERIFYNOTLOCATION: //TODO case VERIFYNOTMOUSESPEED: //TODO case VERIFYNOTORDERED: //TODO case VERIFYNOTPROMPT: //TODO case VERIFYNOTSELECTOPTIONS: //TODO case VERIFYNOTSELECTEDID: //TODO case VERIFYNOTSELECTEDIDS: //TODO case VERIFYNOTSELECTEDINDEX: //TODO case VERIFYNOTSELECTEDINDEXES: //TODO case VERIFYNOTSELECTEDLABEL: //TODO case VERIFYNOTSELECTEDLABELS: //TODO case VERIFYNOTSELECTEDVALUE: //TODO case VERIFYNOTSELECTEDVALUES: //TODO case VERIFYNOTSOMTHINGSELECTED: //TODO case VERIFYNOTSPEED: //TODO case VERIFYNOTTABLE: //TODO case VERIFYNOTTEXT: //TODO case VERIFYNOTTITLE: //TODO case VERIFYNOTVALUE: //TODO case VERIFYNOTVISIBLE: //TODO case VERIFYNOTWHETHERTHISFRAMEMATCHFRAMEEXPRESSION: //TODO case VERIFYNOTWHETHERTHISWINDOWMATCHWINDOWEXPRESSION: //TODO case VERIFYNOTXPATHCOUNT: return com.verifyNotEquals(value, driver.findElements(loc.locatorAsString(target)).size()); case VERIFYORDERED: //TODO case VERIFYPROMPT: //TODO case VERIFYPROMPTNOTPRESENT: //TODO case VERIFYPROMPTPRESENT: //TODO case VERIFYSELECTOPTIONS: //TODO case VERIFYSELECTEDID: //TODO case VERIFYSELECTEDIDS: //TODO case VERIFYSELECTEDINDEX: //TODO case VERIFYSELECTEDINDEXES: //TODO case VERIFYSELECTEDLABEL: //TODO case VERIFYSELECTEDLABELS: //TODO case VERIFYSELECTEDVALUE: //TODO case VERIFYSELECTEDVALUES: //TODO case VERIFYSOMETHINGSELECTED: //TODO case VERIFYSPEED: //TODO case VERIFYTABLE: //TODO case VERIFYTEXT: //TODO case VERIFYTEXTNOTPRESENT: return com.verifyFalse( ebselen.element().doesElementExist(loc.locatorAsString("//*[contains(, '" + value + "')]"))); case VERIFYTEXTPRESENT: return com.verifyTrue( ebselen.element().doesElementExist(loc.locatorAsString("//*[contains(, '" + value + "')]"))); case VERIFYTITLE: //TODO case VERIFYVALUE: //TODO case VERIFYVISIBLE: //TODO case VERIFYWHETHERTHISFRAMEMATCHFRAMEEXPRESSION: //TODO case VERIFYWHETHERTHISWINDOWMATCHWINDOWEXPRESSION: //TODO case VERIFYXPATHCOUNT: return com.verifyEquals(value, driver.findElements(loc.locatorAsString(target)).size()); case WAITFORALERT: //TODO case WAITFORALERTNOTPRESENT: //TODO case WAITFORALERTPRESENT: //TODO case WAITFORALLBUTTONS: //TODO case WAITFORALLFIELDS: //TODO case WAITFORALLLINKS: //TODO case WAITFORALLWINDOWIDS: //TODO case WAITFORALLWINDOWNAMES: //TODO case WAITFORALLWINDOWTITLES: //TODO case WAITFORATTRIBUTE: //TODO case WAITFORATTRIBUTEFROMALLWINDOWS: //TODO case WAITFORBODYTEXT: //TODO case WAITFORCHECKED: //TODO case WAITFORCONDITION: //TODO case WAITFORCONFIRMATION: //TODO case WAITFORCONFIRMATIONNOTPRESENT: //TODO case WAITFORCONFIRMATIONPRESENT: //TODO case WAITFORCOOKIE: //TODO case WAITFORCOOKIEBYNAME: //TODO case WAITFORCOOKIENOTPRESENT: //TODO case WAITFORCOOKIEPRESENT: //TODO case WAITFORCSSCOUNT: //TODO case WAITFORCURSORPOSITION: //TODO case WAITFOREDITABLE: //TODO case WAITFORELEMENTHEIGHT: //TODO case WAITFORELEMENTINDEX: //TODO case WAITFORELEMENTNOTPRESENT: //TODO case WAITFORELEMENTPOSITIONLEFT: //TODO case WAITFORELEMENTPOSITIONTOP: //TODO case WAITFORELEMENTPRESENT: //TODO case WAITFORELEMENTWIDTH: //TODO case WAITFOREVAL: //TODO case WAITFOREXPRESSION: //TODO case WAITFORFRAMETOLOAD: //TODO case WAITFORHTMLSOURCE: //TODO case WAITFORLOCATION: //TODO case WAITFORMOUSESPEED: //TODO case WAITFORNOTALERT: //TODO case WAITFORNOTALLBUTTONS: //TODO case WAITFORNOTALLFIELDS: //TODO case WAITFORNOTALLLINKS: //TODO case WAITFORNOTALLWINDOWIDS: //TODO case WAITFORNOTALLWINDOWNAMES: //TODO case WAITFORNOTALLWINDOWTITLES: //TODO case WAITFORNOTATTRIBUTE: //TODO case WAITFORNOTATTRIBUTEFROMALLWINDOWS: //TODO case WAITFORNOTBODYTEXT: //TODO case WAITFORNOTCHECKED: //TODO case WAITFORNOTCONFIRMATION: //TODO case WAITFORNOTCOOKIE: //TODO case WAITFORNOTCOOKIEBYNAME: //TODO case WAITFORNOTCSSCOUNT: //TODO case WAITFORNOTCURSORPOSITION: //TODO case WAITFORNOTEDITABLE: //TODO case WAITFORNOTELEMENTHEIGHT: //TODO case WAITFORNOTELEMENTINDEX: //TODO case WAITFORNOTELEMENTPOSITIONLEFT: //TODO case WAITFORNOTELEMENTPOSITIONTOP: //TODO case WAITFORNOTELEMENTWIDTH: //TODO case WAITFORNOTEVAL: //TODO case WAITFORNOTEXPRESSION: //TODO case WAITFORNOTHTMLSOURCE: //TODO case WAITFORNOTLOCATION: //TODO case WAITFORNOTMOUSESPEED: //TODO case WAITFORNOTORDERED: //TODO case WAITFORNOTPROMPT: //TODO case WAITFORNOTSELECTOPTIONS: //TODO case WAITFORNOTSELECTEDID: //TODO case WAITFORNOTSELECTEDIDS: //TODO case WAITFORNOTSELECTEDINDEX: //TODO case WAITFORNOTSELECTEDINDEXES: //TODO case WAITFORNOTSELECTEDLABEL: //TODO case WAITFORNOTSELECTEDLABELS: //TODO case WAITFORNOTSELECTEDVALUE: //TODO case WAITFORNOTSELECTEDVALUES: //TODO case WAITFORNOTSOMETHINGSELECTED: //TODO case WAITFORNOTSPEED: //TODO case WAITFORNOTTABLE: //TODO case WAITFORNOTTEXT: //TODO case WAITFORNOTTITLE: //TODO case WAITFORNOTVALUE: //TODO case WAITFORNOTVISIBLE: //TODO case WAITFORNOTWHETHERTHISFRAMEMATCHFRAMEEXPRESSION: //TODO case WAITFORNOTWHETHERTHISWINDOWMATCHWINDOWEXPRESSION: //TODO case WAITFORNOTXPATHCOUNT: //TODO case WAITFORORDERED: //TODO case WAITFORPAGETOLOAD: //TODO case WAITFORPOPUP: //TODO case WAITFORPROMPT: //TODO case WAITFORPROMPTNOTPRESENT: //TODO case WAITFORPROMPTPRESENT: //TODO case WAITFORSELECTOPTIONS: //TODO case WAITFORSELECTEDID: //TODO case WAITFORSELECTEDIDS: //TODO case WAITFORSELECTEDINDEX: //TODO case WAITFORSELECTEDINDEXES: //TODO case WAITFORSELECTEDLABEL: //TODO case WAITFORSELECTEDLABELS: //TODO case WAITFORSELECTEDVALUE: //TODO case WAITFORSELECTEDVALUES: //TODO case WAITFORSOMETHINGSELECTED: //TODO case WAITFORSPEED: //TODO case WAITFORTABLE: //TODO case WAITFORTEXT: //TODO case WAITFORTEXTNOTPRESENT: //TODO check implementation return ebselen.waiting().untilWebElement(loc.locatorAsString("//*[contains(., '" + target + "')]")) .doesNotExist(); case WAITFORTEXTPRESENT: //TODO check implementation return ebselen.waiting().untilWebElement(loc.locatorAsString("//*[contains(., '" + target + "')]")) .exists(); case WAITFORTITLE: //TODO case WAITFORVALUE: //wait for a value, returns value or on/off for checkbox/radio elements //TODO case WAITFORVISIBLE: //TODO case WAITFORWHETERTHISFRAMEMATCHFRAMEEXPRESSION: //TODO case WAITFORWHETERTHISWINDOWMATCHWINDOWEXPRESSION: //TODO case WAITFORXPATHCOUNT: //TODO case WINDOWFOCUS: case WINDOWFOCUSANDWAIT: //TODO case WINDOWMAXIMIZE: case WINDOWMAXIMIZEANDWAIT: //TODO default: throw new IDECommandNotFoundException(); } }
From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
@Override public void typeKeys(String locator, String value) { WebElement webElement = getWebElement(locator); if (!webElement.isEnabled()) { return;/* w w w . j ava 2s. c o m*/ } if (value.contains("line-number=")) { value = value.replaceAll("line-number=\"\\d+\"", ""); } int i = 0; Set<Integer> specialCharIndexes = getSpecialCharIndexes(value); for (int specialCharIndex : specialCharIndexes) { webElement.sendKeys(value.substring(i, specialCharIndex)); String specialChar = String.valueOf(value.charAt(specialCharIndex)); if (specialChar.equals("-")) { webElement.sendKeys(Keys.SUBTRACT); } else if (specialChar.equals("\t")) { webElement.sendKeys(Keys.TAB); } else { webElement.sendKeys(Keys.SHIFT, _keysSpecialChars.get(specialChar)); } i = specialCharIndex + 1; } webElement.sendKeys(value.substring(i, value.length())); }
From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextTester.java
License:Open Source License
protected static void selectTextAndSendKeys(BrowserDriver browserDriver, String completeText, String textToSelect, CharSequence... keys) { if (!completeText.contains(textToSelect)) { throw new IllegalArgumentException( "\"" + completeText + "\" does not contain \"" + textToSelect + "\""); }/*from w ww . j av a 2s .c o m*/ Actions boldAndItalicize = browserDriver.createActions(BODY_XPATH); WebElement body = browserDriver.findElementByXpath(BODY_XPATH); boldAndItalicize.click(body); for (int i = 0; i < completeText.length(); i++) { boldAndItalicize.sendKeys(Keys.LEFT); } int beginIndex = completeText.indexOf(textToSelect); for (int i = 0; i < beginIndex; i++) { boldAndItalicize.sendKeys(Keys.RIGHT); } boldAndItalicize.keyDown(Keys.SHIFT); for (int i = 0; i < textToSelect.length(); i++) { boldAndItalicize.sendKeys(Keys.RIGHT); } boldAndItalicize.keyUp(Keys.SHIFT); boldAndItalicize.perform(); browserDriver.sendKeysToElement(BODY_XPATH, keys); }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient//from www .j av a 2 s .c o m @InSequence(1500) public void dataEntry() throws Exception { String foo = ""; logger.log(Level.INFO, "clicking into the firstNameField ..."); firstNameField.click(); logger.log(Level.INFO, "tabbing into the next field ..."); firstNameField.sendKeys(Keys.TAB); logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value")); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); if (isThere(browser, firstNameFieldErrorXpath)) { // houston we have a problem logger.log(Level.INFO, "firstNameFieldError.isDisplayed() = " + firstNameFieldError.isDisplayed()); assertFalse( "firstNameFieldError should not be displayed after simply tabbing out of the empty field, having never entered any data. " + "But we see '" + firstNameFieldError.getText() + "'", firstNameFieldError.isDisplayed()); } logger.log(Level.INFO, "Shift tabbing back into the firstNameField ..."); (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyDown(Keys.SHIFT).perform(); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); logger.log(Level.INFO, "entering 'asdf' into the firstNameField and then tabbing out of it..."); firstNameField.sendKeys("asdf"); firstNameField.sendKeys(Keys.TAB); logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value")); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); assertTrue("The data 'asdf' should be in the firstNameField after tabbing out of it", "asdf".equals(firstNameField.getAttribute("value"))); logger.log(Level.INFO, "Shift tabbing back into the firstNameField ..."); (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT).perform(); firstNameField.click(); logger.log(Level.INFO, "clearing the firstNameField using the BACKSPACE key, and then tabbing out of the firstNameField ..."); firstNameField.sendKeys(Keys.ARROW_RIGHT, Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain 'asd' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "asd")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } logger.log(Level.INFO, "firstNameField.getText() = " + firstNameField.getText()); assertTrue( "firstNameField should contain 'asd', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain 'as' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "as")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } assertTrue( "firstNameField should contain 'as', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain 'a' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "a")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } assertTrue("firstNameField should contain 'a', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain '' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } assertTrue("firstNameField should contain '', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.TAB); logger.log(Level.INFO, "Waiting for the firstNameFieldError to contain 'Value is required' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(firstNameFieldErrorXpath), "Value is required")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("firstNameFieldError should be visible after tabbing out with no value," + " but " + firstNameFieldErrorXpath + " is not visible.", false); } logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value")); assertTrue( "The data 'asdf' should no longer be in the firstNameField after clearing it out with BACK_SPACE and then tabbing out. " + "But we see '" + firstNameField.getAttribute("value") + "'", "".equals(firstNameField.getAttribute("value"))); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); assertTrue( "The firstNameFieldError should at least be in the DOM somewhere by this point, but it is not there", isThere(browser, firstNameFieldErrorXpath)); logger.log(Level.INFO, "firstNameFieldError.getText() = " + firstNameFieldError.getText()); assertTrue("The firstNameFieldError should say 'Value is required'", firstNameFieldError.getText().contains("Value is required")); }