Search in sources :

Example 1 with SeleniumWCheckBoxSelectWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement in project wcomponents by BorderTech.

the class WCheckBoxSelectExample_Test method testToggle.

@Test
public void testToggle() {
    SeleniumWCheckBoxSelectWebElement cbs = getExampleNoSelections();
    // by option
    WebElement option = cbs.getOption(0);
    boolean selected = cbs.isSelected(option);
    cbs.toggle(option);
    Assert.assertEquals("Option should not be in the same selected state", !selected, cbs.isSelected(option));
    cbs.toggle(option);
    Assert.assertEquals("Option should be back in the previous selected state", selected, cbs.isSelected(option));
    // by text
    String labelText = "New South Wales";
    selected = cbs.isSelected(labelText);
    cbs.toggle(labelText);
    Assert.assertEquals("Option with label should not be in the same selected state", !selected, cbs.isSelected(labelText));
    cbs.toggle(labelText);
    Assert.assertEquals("Option with label should be back in the previous selected state", selected, cbs.isSelected(labelText));
    // by index
    int idx = 3;
    selected = cbs.isSelected(idx);
    cbs.toggle(idx);
    Assert.assertEquals("Option `idx` should not be in the same selected state", !selected, cbs.isSelected(idx));
    cbs.toggle(idx);
    Assert.assertEquals("Option `idx` should be back in the previous selected state", selected, cbs.isSelected(idx));
    // disabled does nothing
    cbs = getDisabledExample();
    Assert.assertFalse(cbs.isSelected(0));
    cbs.toggle(0);
    getDriver().waitForPageReady();
    Assert.assertFalse(cbs.isSelected(0));
    // readOnly does nothing
    cbs = getExampleWithReadOnlySelection();
    Assert.assertTrue(cbs.isSelected(0));
    cbs.toggle(0);
    getDriver().waitForPageReady();
    Assert.assertTrue(cbs.isSelected(0));
}
Also used : SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) WebElement(org.openqa.selenium.WebElement) SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) Test(org.junit.Test)

Example 2 with SeleniumWCheckBoxSelectWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement in project wcomponents by BorderTech.

the class WCheckBoxSelectExample_Test method testGetSelected.

@Test
public void testGetSelected() {
    SeleniumWComponentsWebDriver driver = getDriver();
    // use item with default selection
    Assert.assertEquals(9, getExampleWithSelections().getSelected().size());
    // read only with selection
    Assert.assertEquals(9, getExampleWithReadOnlySelection().getSelected().size());
    // no selection
    Assert.assertTrue(CollectionUtils.isEmpty(getExampleNoSelections().getSelected()));
    // read-only, no selection
    Assert.assertTrue(CollectionUtils.isEmpty(getReadOnlyNoSelection().getSelected()));
    // single selection
    SeleniumWCheckBoxSelectWebElement cbs = driver.findWCheckBoxSelect(new ByLabel("One selection was made", false));
    Assert.assertEquals(1, cbs.getSelected().size());
    // read-only one selection
    cbs = driver.findWCheckBoxSelect(new ByLabel("One selection was made (read only)", false));
    Assert.assertEquals(1, cbs.getSelected().size());
    // disabled always empty
    cbs = driver.findWCheckBoxSelect(new ByLabel("Disabled with many selections and COLUMN layout", false));
    Assert.assertTrue(CollectionUtils.isEmpty(cbs.getSelected()));
}
Also used : SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Example 3 with SeleniumWCheckBoxSelectWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement in project wcomponents by BorderTech.

the class WCheckBoxSelectExample_Test method testComponentLevelBooleanProperties.

@Test
public void testComponentLevelBooleanProperties() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWCheckBoxSelectWebElement interactive = getExampleNoSelections();
    SeleniumWCheckBoxSelectWebElement readOnly = getExampleWithReadOnlySelection();
    SeleniumWCheckBoxSelectWebElement disabled = getDisabledExample();
    // read-only
    Assert.assertFalse(interactive.isReadOnly());
    Assert.assertTrue(readOnly.isReadOnly());
    Assert.assertFalse(disabled.isReadOnly());
    // enabled
    Assert.assertTrue(interactive.isEnabled());
    Assert.assertFalse(readOnly.isEnabled());
    Assert.assertFalse(disabled.isEnabled());
    // mandatory
    Assert.assertFalse(interactive.isMandatory());
    Assert.assertFalse(readOnly.isMandatory());
    Assert.assertFalse(disabled.isMandatory());
    SeleniumWCheckBoxSelectWebElement cbs = driver.findWCheckBoxSelect(new ByLabel("A selection is required", true));
    Assert.assertTrue(cbs.isMandatory());
}
Also used : SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Example 4 with SeleniumWCheckBoxSelectWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement in project wcomponents by BorderTech.

the class WCheckBoxSelectExample_Test method testClick.

@Test
public void testClick() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWCheckBoxSelectWebElement cbs = driver.findWCheckBoxSelect(new ByLabel("One selection was made", false));
    // by option
    // the selected option
    WebElement option = cbs.getOption(0);
    boolean selected = cbs.isSelected(option);
    cbs.clickNoWait(option);
    Assert.assertEquals("Option selection should have changed.", !selected, cbs.isSelected(option));
    cbs.clickNoWait(option);
    Assert.assertEquals("Option selection should have changed back.", selected, cbs.isSelected(option));
    // by label
    String labelText = "New South Wales";
    selected = cbs.isSelected(labelText);
    cbs.clickNoWait(labelText);
    Assert.assertEquals("Option with label '" + labelText + "' selection should have changed.", !selected, cbs.isSelected(labelText));
    cbs.clickNoWait(labelText);
    Assert.assertEquals("Option with label '" + labelText + "' selection should have changed back.", selected, cbs.isSelected(labelText));
    // by index
    int idx = 3;
    selected = cbs.isSelected(idx);
    cbs.clickNoWait(idx);
    Assert.assertEquals("Option with index '" + String.valueOf(idx) + "' selection should have changed.", !selected, cbs.isSelected(idx));
    cbs.clickNoWait(idx);
    Assert.assertEquals("Option with index '" + String.valueOf(idx) + "' selection should have changed back.", selected, cbs.isSelected(idx));
    // disabled does nothing
    cbs = getDisabledExample();
    Assert.assertFalse(cbs.isSelected(0));
    cbs.clickNoWait(0);
    getDriver().waitForPageReady();
    Assert.assertFalse(cbs.isSelected(0));
    // readOnly does nothing
    cbs = getExampleWithReadOnlySelection();
    Assert.assertTrue(cbs.isSelected(0));
    cbs.clickNoWait(0);
    getDriver().waitForPageReady();
    Assert.assertTrue(cbs.isSelected(0));
}
Also used : SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WebElement(org.openqa.selenium.WebElement) SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Example 5 with SeleniumWCheckBoxSelectWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement in project wcomponents by BorderTech.

the class WCheckBoxSelectExample_Test method testIsSelected.

@Test
public void testIsSelected() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWCheckBoxSelectWebElement interactive = driver.findWCheckBoxSelect(new ByLabel("One selection was made", false));
    SeleniumWCheckBoxSelectWebElement readOnly = driver.findWCheckBoxSelect(new ByLabel("One selection was made (read only)", false));
    // by index
    Assert.assertTrue(interactive.isSelected(0));
    Assert.assertFalse(interactive.isSelected(1));
    Assert.assertTrue(readOnly.isSelected(0));
    // only one option so anything else is no selected.
    Assert.assertFalse(readOnly.isSelected(1));
    // by text
    String labelText = "Outside Australia";
    Assert.assertTrue(interactive.isSelected(labelText));
    Assert.assertFalse(interactive.isSelected("Australian Capital Territory"));
    Assert.assertTrue(readOnly.isSelected(labelText));
    Assert.assertFalse(readOnly.isSelected("Australian Capital Territory"));
    // by option
    Assert.assertTrue(interactive.isSelected(interactive.getOption(0)));
    Assert.assertFalse(interactive.isSelected(interactive.getOption(1)));
    Assert.assertTrue(readOnly.isSelected(readOnly.getOption(0)));
    // cannot test for false in read only mode
    // disabled always false
    SeleniumWCheckBoxSelectWebElement disabled = driver.findWCheckBoxSelect(new ByLabel("Disabled with many selections and COLUMN layout", false));
    int i = 0;
    for (WebElement option : disabled.getOptions()) {
        Assert.assertFalse(disabled.isSelected(option));
        Assert.assertFalse(disabled.isSelected(i++));
        Assert.assertFalse(disabled.isSelected(option.getText()));
    }
}
Also used : SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WebElement(org.openqa.selenium.WebElement) SeleniumWCheckBoxSelectWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Aggregations

SeleniumWCheckBoxSelectWebElement (com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement)9 Test (org.junit.Test)9 ByLabel (com.github.bordertech.wcomponents.test.selenium.ByLabel)6 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)6 WebElement (org.openqa.selenium.WebElement)6