Search in sources :

Example 11 with ByLabel

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

the class WCheckBoxSelectExample_Test method testDeselect.

@Test
public void testDeselect() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWCheckBoxSelectWebElement cbs = getExampleWithSelections();
    // by option
    WebElement option = cbs.getOption(0);
    Assert.assertTrue(cbs.isSelected(option));
    cbs.deselect(option);
    Assert.assertFalse("Option should not selected", cbs.isSelected(option));
    // by index
    // not 0 as we used that already, not that it matters
    int idx = 1;
    Assert.assertTrue(cbs.isSelected(idx));
    cbs.deselect(idx);
    Assert.assertFalse("Option at index 'idx' should not be selected", cbs.isSelected(idx));
    // by label
    String labelText = "South Australia";
    Assert.assertTrue(cbs.isSelected(labelText));
    cbs.deselect(labelText);
    Assert.assertFalse("Option labelled '" + labelText + "' should not be selected", cbs.isSelected(labelText));
    // Deselecting an unselected option should not change the selection
    cbs = driver.findWCheckBoxSelect(new ByLabel("One selection was made", false));
    // an unselected option in this example
    idx = 1;
    Assert.assertFalse(cbs.isSelected(idx));
    cbs.deselect(idx);
    Assert.assertFalse("Option should still not be selected", cbs.isSelected(idx));
    // readOnly does nothing
    cbs = getExampleWithReadOnlySelection();
    Assert.assertTrue(cbs.isSelected(0));
    cbs.deselect(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 12 with ByLabel

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

the class WCheckBoxSelectExample_Test method testSelect.

@Test
public void testSelect() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWCheckBoxSelectWebElement cbs = getExampleNoSelections();
    // by option
    WebElement option = cbs.getOption(0);
    Assert.assertFalse(cbs.isSelected(option));
    cbs.select(option);
    Assert.assertTrue("Option should be selected", cbs.isSelected(option));
    // by index
    // not 0 as we used that already, not that it matters
    int idx = 1;
    Assert.assertFalse(cbs.isSelected(idx));
    cbs.select(idx);
    Assert.assertTrue("Option at index 'idx' should be selected", cbs.isSelected(idx));
    // by label
    String labelText = "South Australia";
    Assert.assertFalse(cbs.isSelected(labelText));
    cbs.select(labelText);
    Assert.assertTrue("Option labelled '" + labelText + "' should be selected", cbs.isSelected(labelText));
    // Selecting a selected option should not change the selection
    cbs = driver.findWCheckBoxSelect(new ByLabel("One selection was made", false));
    // the selected option in this example
    idx = 0;
    Assert.assertTrue(cbs.isSelected(idx));
    cbs.select(idx);
    Assert.assertTrue("Option should still be selected", cbs.isSelected(idx));
    // select disabled does nothing
    cbs = getDisabledExample();
    Assert.assertFalse(cbs.isSelected(0));
    cbs.select(0);
    getDriver().waitForPageReady();
    Assert.assertFalse(cbs.isSelected(0));
    // readOnly does nothing
    cbs = getExampleWithReadOnlySelection();
    Assert.assertTrue(cbs.isSelected(0));
    cbs.select(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 13 with ByLabel

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

the class WLabelExample_Test method testGetByLabelSimple.

// Use ByLabel to get a component by label text
@Test
public void testGetByLabelSimple() {
    SeleniumWComponentsWebDriver driver = getDriver();
    String labelText = "Normal input component";
    SeleniumWComponentWebElement expected = driver.findElement(byWComponentPath("WTextField[0]"));
    SeleniumWComponentWebElement actual = driver.findElement(new ByLabel(labelText, false));
    Assert.assertEquals(expected.getAttribute("id"), actual.getAttribute("id"));
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) SeleniumWComponentWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWComponentWebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Example 14 with ByLabel

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

the class WLabelExample_Test method testGetByLabelComplex.

@Test
public void testGetByLabelComplex() {
    String labelText = "Select one or more options";
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWComponentWebElement expected = driver.findElement(byWComponentPath("WCheckBoxSelect[1]"));
    SeleniumWComponentWebElement actual = driver.findElement(new ByLabel(labelText, false));
    Assert.assertEquals(expected.getAttribute("id"), actual.getAttribute("id"));
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) SeleniumWComponentWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWComponentWebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Example 15 with ByLabel

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

the class WLabelExample_Test method testGetByLabelReadOnly.

@Test
public void testGetByLabelReadOnly() {
    String labelText = "A hidden label for a read only field";
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWComponentWebElement expected = driver.findElement(byWComponentPath("WTextField[2]"));
    SeleniumWComponentWebElement actual = driver.findElement(new ByLabel(labelText, false));
    Assert.assertEquals(expected.getAttribute("id"), actual.getAttribute("id"));
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) SeleniumWComponentWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWComponentWebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Aggregations

ByLabel (com.github.bordertech.wcomponents.test.selenium.ByLabel)20 Test (org.junit.Test)19 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)16 WebElement (org.openqa.selenium.WebElement)8 SeleniumWCheckBoxSelectWebElement (com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement)6 SeleniumWComponentWebElement (com.github.bordertech.wcomponents.test.selenium.element.SeleniumWComponentWebElement)6 WebDriver (org.openqa.selenium.WebDriver)3 WContainer (com.github.bordertech.wcomponents.WContainer)2 WField (com.github.bordertech.wcomponents.WField)2 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)2 SeleniumWMultiSelectPairWebElement (com.github.bordertech.wcomponents.test.selenium.element.SeleniumWMultiSelectPairWebElement)2 SeleniumWRadioButtonSelectWebElement (com.github.bordertech.wcomponents.test.selenium.element.SeleniumWRadioButtonSelectWebElement)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1