use of com.github.bordertech.wcomponents.test.selenium.ByWComponentPath in project wcomponents by BorderTech.
the class ExampleSeleniumTest method testDuplicatorWithNoGettersWComponentPathImpl.
/**
* This test implementation uses ByWComponentPath to find the HTML controls.
* A ByWComponentPath is built using a full or partial set of classes which
* describe a path through the WComponent Tree structure. This is the
* preferred method of testing WComponent UIs, as it should be stable
* between releases, and does not require applications to expose UI
* structure via getters.
*
* The UI structure tree structure used in this example is as follows:
* <pre>
* ExampleUI
* WTabSet
* WTab
* TextDuplicator
* WTextField
* WButton
* WButton
* WTab
* TextDuplicatorWithGetters
* WTextField
* WButton
* WButton
* </pre>
*
* So to obtain the first WTextField, any of the following paths could be
* used:
*
* <dl>
* <dt>Full path, including tab index</dt>
* <dd>ExampleUI/WTabSet/WTab[0]/ExampleSeleniumTest$TextDuplicator/WTextField</dd>
*
* <dt>Full path, minus tab index (first tab is used)</dt>
* <dd>ExampleUI/WTabSet/WTab/ExampleSeleniumTest$TextDuplicator/WTextField</dd>
*
* <dt>First text field in a TextDuplicator</dt>
* <dd>ExampleSeleniumTest$TextDuplicator/WTextField</dd>
*
* <dt>First text field in the first tab</dt>
* <dd>WTab/WTextField</dd>
*
* <dt>First text field in the whole UI</dt>
* <dd>WTextField</dd>
* </dl>
*
* The amount of detail you will need to specify for the paths in your tests
* will depend on how your UI is structured. If you have created reusable
* application components (e.g. a "NamePanel"), you will be able to match on
* this directly in the path rather than having to look for the
* WComponent[x]/WComponent[y]/WComponent[z].
*/
@Test
public void testDuplicatorWithNoGettersWComponentPathImpl() {
// Launch the web browser to the LDE
WebDriver driver = getDriver();
// Paths to frequently used components
By textFieldPath = new ByWComponentPath(ui, "ExampleSeleniumTest$TextDuplicator/WTextField");
// Enter some text and use the duplicate button
driver.findElement(textFieldPath).sendKeys("dummy");
driver.findElement(new ByWComponentPath(ui, "ExampleSeleniumTest$TextDuplicator/WButton[0]")).click();
Assert.assertEquals("Incorrect text field text after duplicate", "dummydummy", driver.findElement(textFieldPath).getAttribute("value"));
// Clear the text
driver.findElement(new ByWComponentPath(ui, "ExampleSeleniumTest$TextDuplicator/WButton[1]")).click();
Assert.assertEquals("Incorrect text field text after clear", "", driver.findElement(textFieldPath).getAttribute("value"));
}
use of com.github.bordertech.wcomponents.test.selenium.ByWComponentPath in project wcomponents by BorderTech.
the class ExampleSeleniumTest method testDuplicatorWithGettersWComponentPathImpl.
/**
* This test implementation uses ByWComponentPath to find the HTML controls.
* See {@link #testDuplicatorWithNoGettersWComponentPathImpl()} for an
* explanation of how the paths function.
*/
@Test
public void testDuplicatorWithGettersWComponentPathImpl() {
// Launch the web browser to the LDE
WebDriver driver = getDriver();
// Paths to frequently used components
By textFieldPath = new ByWComponentPath(ui, "ExampleSeleniumTest$TextDuplicatorWithGetters/WTextField");
// Select the 2nd tab
driver.findElement(new ByWComponentPath(ui, "WTab[1]")).click();
// Enter some text and use the duplicate button
driver.findElement(textFieldPath).sendKeys("dummy");
driver.findElement(new ByWComponentPath(ui, "ExampleSeleniumTest$TextDuplicatorWithGetters/WButton[0]")).click();
Assert.assertEquals("Incorrect text field text after duplicate", "dummydummy", driver.findElement(textFieldPath).getAttribute("value"));
// Clear the text
driver.findElement(new ByWComponentPath(ui, "ExampleSeleniumTest$TextDuplicatorWithGetters/WButton[1]")).click();
Assert.assertEquals("Incorrect text field text after clear", "", driver.findElement(textFieldPath).getAttribute("value"));
}
use of com.github.bordertech.wcomponents.test.selenium.ByWComponentPath in project wcomponents by BorderTech.
the class ExampleSeleniumTest method testDuplicatorWithGettersWComponentImpl.
/**
* This test implementation uses ByWComponent to find the HTML controls.
* This is the easiest approach to use, but requires that the UI being
* tested has been built with getters for every control, which is not
* usually practical.
*/
@Test
public void testDuplicatorWithGettersWComponentImpl() {
// Launch the web browser to the LDE
WebDriver driver = getDriver();
// UI components
WTextField textField = ui.getTextDuplicatorWithGetters().getTextField();
WButton duplicateButton = ui.getTextDuplicatorWithGetters().getDuplicateButton();
WButton clearButton = ui.getTextDuplicatorWithGetters().getClearButton();
// Select the 2nd tab
driver.findElement(new ByWComponentPath(ui, "WTab[1]")).click();
// Enter some text and use the duplicate button
driver.findElement(new ByWComponent(textField)).sendKeys("dummy");
driver.findElement(new ByWComponent(duplicateButton)).click();
Assert.assertEquals("Incorrect text field text after duplicate", "dummydummy", driver.findElement(new ByWComponent(textField)).getAttribute("value"));
// Clear the text
driver.findElement(new ByWComponent(clearButton)).click();
Assert.assertEquals("Incorrect text field text after clear", "", driver.findElement(new ByWComponent(textField)).getAttribute("value"));
}
Aggregations