Search in sources :

Example 21 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class AbstractCompare_Test method testGetTriggerValueInvalidTrigger.

@Test
public void testGetTriggerValueInvalidTrigger() {
    SubordinateTrigger trigger = new MyInvalidTrigger();
    AbstractCompare compare = new MyCompare(trigger, null);
    try {
        compare.execute();
        Assert.fail("Should have thrown exception for invalid subordinate trigger.");
    } catch (SystemException e) {
        Assert.assertNotNull("Exception for invalid subordinate trigger should have a message", e.getMessage());
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Test(org.junit.Test)

Example 22 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumWComponentsWebDriver method findButton.

/**
 * @param buttonTextOrTitle the text expected in the button
 * @param searchAttributes if {@code true} then also look at labelling attributes title and aria-label.
 * @return a WebElement representing a button described by the required text.
 */
public WebElement findButton(final String buttonTextOrTitle, final boolean searchAttributes) {
    if (Util.empty(buttonTextOrTitle)) {
        throw new IllegalArgumentException("Cannot find a button with no text");
    }
    List<WebElement> buttons = findElements(By.tagName("button"));
    for (WebElement button : buttons) {
        String text = button.getText();
        if (buttonTextOrTitle.equalsIgnoreCase(text)) {
            return button;
        }
        if (searchAttributes) {
            text = button.getAttribute("title");
            if (buttonTextOrTitle.equalsIgnoreCase(text)) {
                return button;
            }
            text = button.getAttribute("aria-label");
            if (buttonTextOrTitle.equalsIgnoreCase(text)) {
                return button;
            }
        }
    }
    throw new SystemException("No button containing required text.");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) SeleniumWPhoneNumberFieldWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWPhoneNumberFieldWebElement) SeleniumWMessageBoxWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWMessageBoxWebElement) SeleniumWButtonWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWButtonWebElement) SeleniumWTextFieldWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTextFieldWebElement) WebElement(org.openqa.selenium.WebElement) SeleniumWMultiSelectPairWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWMultiSelectPairWebElement) SeleniumWComponentWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWComponentWebElement) SeleniumWDialogWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWDialogWebElement) SeleniumWRadioButtonWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWRadioButtonWebElement) SeleniumWEmailFieldWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWEmailFieldWebElement) SeleniumWTableWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement) SeleniumWSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWSelectWebElement) SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) SeleniumWMessagesWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWMessagesWebElement) SeleniumWLabelWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWLabelWebElement) SeleniumWTextAreaWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTextAreaWebElement) SeleniumWCheckBoxWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxWebElement) SeleniumWMultiDropdownWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWMultiDropdownWebElement) SeleniumWRadioButtonSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWRadioButtonSelectWebElement)

Example 23 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumWComponentsWebDriverFactory method createBackingDriver.

/**
 * Create a WebDriver implementation from a String class name.
 *
 * @param backingDriverClass the WebDriver implementation class.
 * @return the WebDriver implementation.
 */
public static WebDriver createBackingDriver(final String backingDriverClass) {
    if (StringUtils.isBlank(backingDriverClass)) {
        throw new IllegalArgumentException("backingDriverClass must not be blank");
    }
    try {
        Class clazz = Class.forName(backingDriverClass);
        if (!WebDriver.class.isAssignableFrom(clazz)) {
            throw new SystemException("backingDriverClass does not implement WebDriver inteface. backingDriverClass=[" + backingDriverClass + "]");
        }
        Class<WebDriver> driverClass = (Class<WebDriver>) clazz;
        WebDriver backingDriver = (WebDriver) driverClass.newInstance();
        return backingDriver;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        throw new SystemException("Unable to create backingDriverClass by classname String. backingDriverClass=[" + backingDriverClass + "]", ex);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Example 24 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumCheckableGroupInputWebElement method getOption.

/**
 * Find an option with a particular label.
 *
 * @param labelText the text content of the option's label
 * @return the option
 */
public WebElement getOption(final String labelText) {
    List<WebElement> options = getOptions();
    if (CollectionUtils.isEmpty(options)) {
        throw new SystemException("No options available");
    }
    if (isReadOnly()) {
        for (WebElement o : options) {
            if (labelText.equalsIgnoreCase(o.getText())) {
                return o;
            }
        }
        throw new IllegalArgumentException("Could not find option identified by " + labelText);
    }
    SeleniumWComponentWebElement input = findElementImmediate(new ByLabel(labelText, false, true));
    return input.findElementImmediate(By.xpath(".."));
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WebElement(org.openqa.selenium.WebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel)

Example 25 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumWMultiDropdownWebElement method getDropdown.

/**
 * @param optionText the text of the selected option
 * @return a representation of the select list with selection equal to the selected option text
 */
public WebElement getDropdown(final String optionText) {
    if (isReadOnly()) {
        throw new SystemException("Cannot get option lists from a read-only WMultiDropdown");
    }
    if (optionText == null) {
        throw new IllegalArgumentException("Cannot get a reference to the selected option list without the option text");
    }
    List<WebElement> dropdowns = getDropdowns();
    if (dropdowns.isEmpty()) {
        // theoretically this is impossible
        throw new SystemException("Cannot find any selected lists");
    }
    Select se;
    WebElement option;
    for (WebElement dropdown : dropdowns) {
        se = new Select(dropdown);
        option = se.getFirstSelectedOption();
        if (optionText.equalsIgnoreCase(option.getText())) {
            return dropdown;
        }
    }
    throw new SystemException("Cannot get a list for that option text");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Select(org.openqa.selenium.support.ui.Select) WebElement(org.openqa.selenium.WebElement)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)94 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)13 Test (org.junit.Test)12 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 WebElement (org.openqa.selenium.WebElement)9 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)4 Request (com.github.bordertech.wcomponents.Request)4 InputStream (java.io.InputStream)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 Environment (com.github.bordertech.wcomponents.Environment)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Date (java.util.Date)3 List (java.util.List)3