org.openqa.selenium.support.ui.ExpectedConditions Java Examples

The following examples show how to use org.openqa.selenium.support.ui.ExpectedConditions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SeleniumSpec.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * Wait for render a html element
 *
 * @param method
 * @param element
 * @param sTimeout
 */
@When("^I wait for element '([^:]*?):(.+?)' to be available for '(\\d+?)' seconds$")
public void seleniumWait(String method, String element, String sTimeout) {
    Integer timeout = sTimeout != null ? Integer.parseInt(sTimeout) : null;
    RemoteWebDriver driver = commonspec.getDriver();
    WebDriverWait driverWait = new WebDriverWait(driver, timeout);
    By criteriaSel = null;
    if ("id".equals(method)) {
        criteriaSel = By.id(element);
    } else if ("name".equals(method)) {
        criteriaSel = By.name(element);
    } else if ("class".equals(method)) {
        criteriaSel = By.className(element);
    } else if ("xpath".equals(method)) {
        criteriaSel = By.xpath(element);
    } else if ("css".equals(method)) {
        criteriaSel = By.cssSelector(element);
    } else {
        fail("Unknown search method: " + method);
    }
    driverWait.until(ExpectedConditions.
            presenceOfElementLocated(criteriaSel));
}
 
Example #2
Source File: Edition016_Clipboard.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
private void automateClipboard(AppiumDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, 5);

    try {
        wait.until(ExpectedConditions.presenceOfElementLocated(clipboardNav)).click();

        String text = "Hello World";
        ((HasClipboard) driver).setClipboardText(text);
        wait.until(ExpectedConditions.presenceOfElementLocated(refreshClipboardBtn)).click();
        By clipboardText = MobileBy.AccessibilityId(text);
        Assert.assertEquals(driver.findElement(clipboardText).getText(), text);

        text = "Hello World Again";
        driver.findElement(clipboardInput).sendKeys(text);
        try {
            driver.hideKeyboard();
        } catch (Exception ign) {}
        driver.findElement(setTextBtn).click();
        Assert.assertEquals(((HasClipboard) driver).getClipboardText(), text);

    } finally {
        driver.quit();
    }
}
 
Example #3
Source File: GitBranches.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * select given branch check enabled or not button checkout
 *
 * @param nameOfBranch is name of branch
 */
public void selectBranchAndCheckEnabledButtonCheckout(final String nameOfBranch) {
  new WebDriverWait(seleniumWebDriver, 5)
      .until(
          new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver webDriver) {
              new WebDriverWait(seleniumWebDriver, 5)
                  .until(
                      ExpectedConditions.visibilityOfElementLocated(
                          By.id(
                              String.format(Locators.BRANCH_NAME_IN_LIST_PREFIX, nameOfBranch))))
                  .click();
              return seleniumWebDriver.findElement(By.id(Locators.CHECKOUT_BTN_ID)).isEnabled();
            }
          });
}
 
Example #4
Source File: Edition043_iOS_Permissions.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocationPermissions() {
    // first, set the geolocation to something arbitrary
    double newLat = 49.2827, newLong = 123.1207;
    driver.setLocation(new Location(newLat, newLong, 0));

    // now navigate to the location demo
    wait.until(ExpectedConditions.presenceOfElementLocated(geolocation)).click();

    // if permissions were set correctly, we should get no popup and instead be
    // able to read the latitude and longitude that were previously set
    By newLatEl = MobileBy.AccessibilityId("Latitude: " + newLat);
    By newLongEl = MobileBy.AccessibilityId("Longitude: " + newLong);
    wait.until(ExpectedConditions.presenceOfElementLocated(newLatEl));
    wait.until(ExpectedConditions.presenceOfElementLocated(newLongEl));
}
 
Example #5
Source File: TextEntryStepDefinitions.java    From IridiumApplicationTesting with MIT License 6 votes vote down vote up
/**
 * Clears the contents of an element
 *
 * @param selector      Either ID, class, xpath, name or css selector
 * @param alias         If this word is found in the step, it means the selectorValue is found from the
 *                      data set.
 * @param selectorValue The value used in conjunction with the selector to match the element. If alias was
 *                      set, this value is found from the data set. Otherwise it is a literal value.
 */
@When("^I clear (?:a|an|the) element with (?:a|an|the) "
	+ "(ID|class|xpath|name|css selector)( alias)? of \"([^\"]*)\"")
public void clearElement(final String selector, final String alias, final String selectorValue) {
	final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread();
	final By by = getBy.getBy(selector, StringUtils.isNotBlank(alias), selectorValue, State.getFeatureStateForThread());
	final WebDriverWait wait = new WebDriverWait(
		webDriver,
		State.getFeatureStateForThread().getDefaultWait(),
		Constants.ELEMENT_WAIT_SLEEP_TIMEOUT);
	final WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

	mouseMovementUtils.mouseGlide(
		webDriver,
		(JavascriptExecutor) webDriver,
		element,
		Constants.MOUSE_MOVE_TIME,
		Constants.MOUSE_MOVE_STEPS);

	element.clear();
	sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep());
}
 
Example #6
Source File: NativeAppElement.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
@Override
public void sendKeys(CharSequence... arg0) {
	int attemp = 1;
	boolean typeSucess = false;
	while (!typeSucess && attemp <= 5) {
		try {
			WebDriverWait wait = new WebDriverWait(this.nativeAppDriver, maxWaitTime, 500);
			wait.until(ExpectedConditions.presenceOfElementLocated(this.getByLocator()));
			attemp++;
			webElement.sendKeys(arg0);
			typeSucess = true;
		} catch (Exception e) {
			if (attemp > 5) {
				Reporter.log("Unable to enter text into element by " + this.getByLocator().toString());
				this.getCateredWebDriver().captureScreenshot();
				throw e;
			}
		}
	}
}
 
Example #7
Source File: BakerySteps.java    From NoraUi with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @param conditions
 *            list of 'expected' values condition and 'actual' values ({@link com.github.noraui.gherkin.GherkinStepCondition}).
 * @throws FailureException
 *             if the scenario encounters a functional error.
 */
@Conditioned
@Alors("La partie referenceur du portail BAKERY est affichée(\\?)")
@Then("The referencer part of the BAKERY portal is displayed(\\?)")
public void checkReferencerPage(List<GherkinStepCondition> conditions) throws FailureException {
    try {
        Wait.until(ExpectedConditions.presenceOfElementLocated(Utilities.getLocator(referencerPage.titleMessage)));
        if (!referencerPage.checkPage()) {
            logInToBakeryWithBakeryRobot();
        }
        if (!referencerPage.checkPage()) {
            new Result.Failure<>(referencerPage.getApplication(), Messages.getMessage(Messages.FAIL_MESSAGE_UNKNOWN_CREDENTIALS), true, referencerPage.getCallBack());
        }
    } catch (Exception e) {
        new Result.Failure<>(referencerPage.getApplication(), Messages.getMessage(Messages.FAIL_MESSAGE_UNKNOWN_CREDENTIALS), true, referencerPage.getCallBack());
    }
    Auth.setConnected(true);
}
 
Example #8
Source File: Edition044_Shadow_DOM.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
public void testShadowElementsWithJS(AppiumDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, 10);

    driver.get(URL);

    // find the web component
    WebElement switchComponent = wait.until(ExpectedConditions.presenceOfElementLocated(
        SWITCH_COMPONENT));

    // pierce shadow dom to get checked status of inner control, and assert on it
    boolean checked = (boolean) driver.executeScript(INPUT_CHECKED, switchComponent);
    Assert.assertEquals(false, checked);

    // change the state from off to on by clicking inner input
    // (clicking the parent component will not work)
    driver.executeScript(CLICK_INPUT, switchComponent);

    // check that state of inner control has changed appropriately
    checked = (boolean) driver.executeScript(INPUT_CHECKED, switchComponent);
    Assert.assertEquals(true, checked);
}
 
Example #9
Source File: ESStoreAnonHomePageTestCase.java    From product-es with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.es.store", description = "Test Anonymous Navigation from top menu")
public void testAnonNavigationTop() throws Exception {
    //test menu navigation
    driver.get(resolveStoreUrl());
    WebDriverWait wait = new WebDriverWait(driver, 60);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("popoverExampleTwo")));
    driver.findElement(By.id("popoverExampleTwo")).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Gadget")));
    driver.findElement(By.linkText("Gadget")).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText(LINE_CHART )));
    driver.findElementPoll(By.linkText(LINE_CHART ), MAX_POLL_COUNT);
    assertEquals(LINE_CHART, driver.findElement(By.linkText(LINE_CHART ))
            .getText(), "Gadgets Menu not working");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("popoverExampleTwo")));
    driver.findElement(By.id("popoverExampleTwo")).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Site")));
    driver.findElement(By.linkText("Site")).click();
    driver.findElementPoll(By.linkText(AMAZON), MAX_POLL_COUNT);
    assertEquals(AMAZON, driver.findElement(By.linkText(AMAZON)).getText(),
                 "Sites Menu not working");
    driver.findElement(By.cssSelector("h2.app-title")).click();
}
 
Example #10
Source File: AbstractSeleniumTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
public WebElement selectValue( String locator, String value, boolean scrollToView )
{
    int count = 5;
    boolean check = true;
    WebDriverWait wait = new WebDriverWait( getWebDriver( ), 10 );
    WebElement element = null;
    while(check && count-->0)
    {
        try
        {
            element = findElement( locator );
            List<WebElement> elementList = new ArrayList<>( );
            elementList.add( element );
            wait.until( ExpectedConditions.visibilityOfAllElements( elementList ) );
            check=false;
        } catch (Throwable e) {
            logger.info("Waiting for select element {} to be visible", locator);
        }
    }
    Select select = new Select(element);
    select.selectByValue( value );
    return element;
}
 
Example #11
Source File: TextEntryStepDefinitions.java    From IridiumApplicationTesting with MIT License 6 votes vote down vote up
/**
 * Clears the contents of an element
 *
 * @param selector      Either ID, class, xpath, name or css selector
 * @param alias         If this word is found in the step, it means the selectorValue is found from the
 *                      data set.
 * @param selectorValue The value used in conjunction with the selector to match the element. If alias was
 *                      set, this value is found from the data set. Otherwise it is a literal value.
 */
@When("^I clear (?:a|an|the) hidden element with (?:a|an|the) "
	+ "(ID|class|xpath|name|css selector)( alias)? of \"([^\"]*)\"")
public void clearHiddenElement(final String selector, final String alias, final String selectorValue) {
	final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread();
	final By by = getBy.getBy(selector, StringUtils.isNotBlank(alias), selectorValue, State.getFeatureStateForThread());
	final WebDriverWait wait = new WebDriverWait(
		webDriver,
		State.getFeatureStateForThread().getDefaultWait(),
		Constants.ELEMENT_WAIT_SLEEP_TIMEOUT);
	final WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

	mouseMovementUtils.mouseGlide(
		webDriver,
		(JavascriptExecutor) webDriver,
		element,
		Constants.MOUSE_MOVE_TIME,
		Constants.MOUSE_MOVE_STEPS);

	final JavascriptExecutor js = (JavascriptExecutor) webDriver;
	js.executeScript("arguments[0].value='';", element);
	sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep());
}
 
Example #12
Source File: LoginPageStep3.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 5 votes vote down vote up
public void logInWithUsernameAndPassword(String username, String password) throws Exception {
    usernameField.sendKeys(username);
    passwordField.sendKeys(password);
    loginButton.click();

    WebDriverWait wait = new WebDriverWait(DriverBase.getDriver(), 15, 100);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
}
 
Example #13
Source File: SliderTest.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void dragNDrop() {
    login("login").click();
    waitForElement("dragAndDrop").click();
    new WebDriverWait(driver, 30)
        .until(ExpectedConditions
            .elementToBeClickable(MobileBy.AccessibilityId("dragMe")));

}
 
Example #14
Source File: ElementAction.java    From PatatiumAppUi with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 等待30秒让元素可见
 * @param locator
 */
public void DisplayElement(Locator locator)
{
	ElementAction action =new ElementAction();
	WebDriverWait webDriverWait=new WebDriverWait(driver, 30);
	webDriverWait.until(ExpectedConditions.visibilityOf(action.findElement(locator))).isDisplayed();

}
 
Example #15
Source File: FindText.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** click on the 'Whole word only' checkbox */
public void clickOnWholeWordCheckbox() {
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(
          ExpectedConditions.visibilityOfElementLocated(
              By.id(Locators.WHOLE_WORD_CHECKLBOX_SPAN)))
      .click();
}
 
Example #16
Source File: Wizard.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** wait type project in the Configuration wizard form */
public void waitTypeProject(String typeProject) {
  new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
      .until(
          ExpectedConditions.visibilityOfElementLocated(
              By.id(TypeProject.TYPE_PREFIX_ID + typeProject)));
}
 
Example #17
Source File: ConnectedCupDeviceViewPage.java    From product-iots with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the connected cup device web app URL.
 * @return : Link of the connected cup device web app.
 */
public String getDeviceLink() {
    WebDriverWait wait = new WebDriverWait(driverServer, UIUtils.webDriverTime);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
            uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))));
    return driverServer.findElement(By.xpath(
            uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))).getAttribute("href");
}
 
Example #18
Source File: FindText.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * type text into 'Text to find' field
 *
 * @param text is text that need to find
 */
public void typeTextIntoFindField(String text) {
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(ExpectedConditions.visibilityOfElementLocated(By.id(Locators.FIND_TEXT_INPUT)))
      .clear();
  loader.waitOnClosed();
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(ExpectedConditions.visibilityOfElementLocated(By.id(Locators.FIND_TEXT_INPUT)))
      .sendKeys(text);
}
 
Example #19
Source File: ITCreateDuplicateBucket.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    // bucket cleanup

    // confirm all buckets checkbox exists
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nifi-registry-workflow-administration-buckets-list-container-column-header div.mat-checkbox-inner-container")));

    // select all buckets checkbox
    WebElement selectAllCheckbox = driver.findElement(By.cssSelector("#nifi-registry-workflow-administration-buckets-list-container-column-header div.mat-checkbox-inner-container"));
    selectAllCheckbox.click();

    // confirm actions drop down menu exists
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nifi-registry-workflow-administration-perspective-buckets-container button.mat-fds-primary")));

    // select actions drop down
    WebElement selectActions = driver.findElement(By.cssSelector("#nifi-registry-workflow-administration-perspective-buckets-container button.mat-fds-primary"));
    selectActions.click();

    // select delete
    WebElement selectDeleteBucket = driver.findElement(By.cssSelector("div.mat-menu-content button.mat-menu-item"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", selectDeleteBucket);

    // verify bucket deleted
    WebElement confirmDelete = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.fds-dialog-actions button.mat-fds-warn")));
    confirmDelete.click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[data-automation-id='no-buckets-message']")));

    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
    }
}
 
Example #20
Source File: Wizard.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** type project name on wizard */
public void typeProjectNameOnWizard(String projectName) {
  new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC)
      .until(ExpectedConditions.visibilityOf(projectNameInput))
      .clear();
  waitProjectNameOnWizard();
  new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC)
      .until(ExpectedConditions.visibilityOf(projectNameInput))
      .sendKeys(projectName);
  loader.waitOnClosed();
}
 
Example #21
Source File: ConfigureClasspath.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** close the 'Configure Classpath' form by click on the close icon */
public void closeConfigureClasspathFormByIcon() {
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(
          ExpectedConditions.visibilityOfElementLocated(By.xpath(CONFIGURE_CLASSPATH_CLOSE_ICON)))
      .click();
  waitConfigureClasspathFormIsClosed();
}
 
Example #22
Source File: OrganizationPage.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
public void waitOrganizationName(String name) {
  redrawUiElementsTimeout.until(
      ExpectedConditions.attributeToBeNotEmpty(organizationName, "value"));
  redrawUiElementsTimeout.until(
      (WebDriver driver) ->
          driver
              .findElement(By.xpath(Locators.ORGANIZATION_NAME))
              .getAttribute("value")
              .equals(name));
}
 
Example #23
Source File: CommandsPalette.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** Start CommandPalette widget by Shift+F10 hot keys */
public void openCommandPaletteByHotKeys() {
  loader.waitOnClosed();
  actionsFactory
      .createAction(seleniumWebDriver)
      .sendKeys(Keys.SHIFT.toString(), Keys.F10.toString())
      .perform();
  redrawUiElementTimeout.until(ExpectedConditions.visibilityOf(commandPalette));
}
 
Example #24
Source File: NativeAppDriver.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * To check the given text contains by the element located by the locator
 * 
 * @param by
 * @param text
 * @return
 */
public boolean verifyElementTextContains(By by, String text) {
	boolean result = false;
	String actualText = "";
	int attempt = 0;
	NativeAppElement webElment = findElement(by);
	while (!result && attempt <= 5) {
		try {
			attempt++;
			WebDriverWait wait = (WebDriverWait) new WebDriverWait(
					appiumDriver, maxWaitTime, 500);
			wait.until(ExpectedConditions.presenceOfElementLocated(by));
			wait.until(ExpectedConditions.visibilityOfElementLocated(by));
			if (webElment.getTagName().equalsIgnoreCase("input")
					|| webElment.getTagName().equalsIgnoreCase("textarea")) {
				actualText = webElment.getAttribute("value");
			} else {
				actualText = webElment.readInnerText();
			}
		} catch (Exception e) {
			System.err.println("attempt " + attempt + "...");
			if (attempt > 5) {
				Reporter.log("Unable to get the text by locator "
						+ by.toString());
				captureScreenshot();
				throw new WebDriverException(e);
			}
		}
		result = actualText.contains(text);
	}
	if (result) {
		return true;
	} else {
		Reporter.log("\"" + text + "\" not found in \"" + actualText + "\"");
		captureScreenshot();
		throw new AssertionError("\"" + text + "\" not found in \""
				+ actualText + "\"" + "\n"
				+ Thread.currentThread().getStackTrace().toString());
	}
}
 
Example #25
Source File: ElementService.java    From senbot with MIT License 5 votes vote down vote up
/**
 * 
 * @param viewName
 * @param elementName
 * @return {@link WebElement}
 * @throws IllegalAccessException
 */
public WebElement viewShouldShowElement(String viewName, String elementName) throws IllegalAccessException {
	WebElement found = getElementFromReferencedView(viewName, elementName);
	waitForLoaders();
	
	try {			
		found = new WebDriverWait(getWebDriver(), getSeleniumManager().getTimeout()).until(ExpectedConditions.visibilityOf(found));
	}
	catch (Exception e) {
		String notFoundLocator = getElementLocatorFromReferencedView(viewName, elementName);
		fail("The element \"" + notFoundLocator + "\" referenced by element name \"" + elementName+ "\" on view/page \"" + viewName + "\" is not found after a wait of " + getSeleniumManager().getTimeout() + " seconds.");
	}
	
	return found;
}
 
Example #26
Source File: Edition021_Waiting.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogin_ExplicitWait() {
    WebDriverWait wait = new WebDriverWait(driver, 10);

    wait.until(ExpectedConditions.presenceOfElementLocated(loginScreen)).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(username)).sendKeys(AUTH_USER);
    wait.until(ExpectedConditions.presenceOfElementLocated(password)).sendKeys(AUTH_PASS);
    wait.until(ExpectedConditions.presenceOfElementLocated(loginBtn)).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(getLoggedInBy(AUTH_USER)));
}
 
Example #27
Source File: SynchronisationServiceTest.java    From senbot with MIT License 5 votes vote down vote up
@Test
public void testCheckAndAssertForExpectedCondition() throws Exception {
    seleniumNavigationService.navigate_to_url(TEST_PAGE_URL);

    seleniumSynchronisationService.checkAndAssertForExpectedCondition(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div[id='text']")));
    seleniumElementService.findExpectedElement(By.cssSelector("button[id='delayedDisplayButton']")).click();
    seleniumSynchronisationService.checkAndAssertForExpectedCondition(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[id='text']")));
}
 
Example #28
Source File: Wizard.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Select the type of packaging on Wizard
 *
 * @param mavenType type project of Maven
 */
public void selectPackagingType(PackagingMavenType mavenType) {
  List<WebElement> DropDownList =
      new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
          .until(
              ExpectedConditions.presenceOfAllElementsLocatedBy(
                  By.xpath(Locators.SELECT_PACKAGING_DROPDOWN_BLOCK)));

  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(
          ExpectedConditions.visibilityOfElementLocated(
              By.xpath(Locators.SELECT_PACKAGING_DROPDOWN)))
      .click();

  switch (mavenType) {
    case JAR:
      DropDownList.get(1).click();
      break;
    case WAR:
      DropDownList.get(2).click();
      break;
    case POM:
      DropDownList.get(3).click();
      break;
    default:
      DropDownList.get(0).click();
      break;
  }
}
 
Example #29
Source File: ViewConfigTestDrone.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
public void testNavigationActionMethod2() throws MalformedURLException
{
    driver.get(new URL(contextPath, "origin.xhtml").toString());

    WebElement button = driver.findElement(By.id("destination:pb004ActionMethod2"));
    button.click();
    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("overviewPage"),
            "You arrived at overview page").apply(driver));
}
 
Example #30
Source File: Step.java    From NoraUi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Update a html input text with a text.
 * 
 * @param timeOutInSeconds
 *            The timeout in seconds when an expectation is called.
 * @param pageElement
 *            Is target element.
 * @param textOrKey
 *            Is the new data (text or text in context (after a save)).
 * @param keysToSend
 *            character to send to the element after {@link org.openqa.selenium.WebElement#sendKeys(CharSequence...) sendKeys} with textOrKey.
 * @param args
 *            list of arguments to format the found selector with.
 * @throws TechnicalException
 *             is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
 *             Exception with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_ERROR_ON_INPUT} message (with screenshot, no exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void updateText(int timeOutInSeconds, PageElement pageElement, String textOrKey, CharSequence keysToSend, Object... args) throws TechnicalException, FailureException {
    String value = getTextOrKey(textOrKey);
    if (!"".equals(value)) {
        try {
            Wait.untilAnd(ExpectedConditions.elementToBeClickable(Utilities.getLocator(pageElement, args)), timeOutInSeconds).map((WebElement elem) -> {
                elem.clear();
                return elem;
            }).then(elem -> {
                if (DriverFactory.IE.equals(Context.getBrowser())) {
                    final String javascript = "arguments[0].value='" + value + "';";
                    ((JavascriptExecutor) getDriver()).executeScript(javascript, elem);
                } else {
                    elem.sendKeys(value);
                }
                if (keysToSend != null) {
                    elem.sendKeys(keysToSend);
                }
            });

        } catch (final Exception e) {
            new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_ERROR_ON_INPUT), pageElement, pageElement.getPage().getApplication()), true,
                    pageElement.getPage().getCallBack());
        }
    } else {
        log.debug("Empty data provided. No need to update text. If you want clear data, you need use: \"I clear text in ...\"");
    }
}