JUNIT Annotations, Commands and Assertions
Annotations
The following annotations are used frequently in Selenium scripts:
@Ignore - test methods that use this annotation will be ignored at run time
@Test - identifies a test method; methods that don't have @Test won' be executed at run time
@Before - method will be run before every JUnit @Test method
@After - method will be run after every JUnit @Test method
@BeforeClass - method will be run once before any methods in that class
@AfterClass - method will be run once after all methods in the class
Commands
Some of the commands may return one or more results depending on the number of HTML elements matched by the XPATH locator.
selenium.open(page's relative path)
usage: opens the page that has the relative path provided as argument
example: selenium.open("/selenium/search.php");
selenium.type(XPATH locator of the HTML element, value)
usage: types the value in the HTML element found through the XPATH value
example: selenium.type("xpath=//input[@name='q']", value);
selenium.click(XPATH locator of the HTML element)
usage: clicks the HTML element found through the XPATH value
example: selenium.click("//a[@title = 'a12345']");
selenium.waitForPageToLoad("30000")
usage: wait for some time for the page to load
selenium.getTitle()
usage: gets the value of the title of the current page
selenium.getText(XPATH locator of the HTML element)
usage: gets the text of the HTML element found through the locator
example: selenium.getText("//p[@class = 'abcdef']");
selenium.submit(XPATH locator of the form)
usage: submits a HTML form found through the locator
example: selenium.submit("//form[@id='HTMLFormElements']");
selenium.check(XPATH locator of the checkbox)
usage: checks a checkbox found through the locator
example: selenium.check("//input[@name='checkboxes[]' and @value='cb2']");
selenium.uncheck(XPATH locator for the checkbox)
usage: un-checks a checkbox found through the locator
example: selenium.uncheck("//input[@name='checkboxes[]' and @value='cb3']");
selenium.getXPathCount(XPATH locator)
usage: returns the number of the HTML elements matched by the XPATH locator
ASSERTIONS
The most important assertions for Selenium are assertTrue and assertEquals.
assertTrue(text displayed if the condition is false, condition)
usage: returns true if the condition returns true
example: assertTrue("No homepage URL found ",matchingCountTotal>0)
assertEquals(text displayed if expected value <> actual value, expected value, actual value)
usage: returns true if the expected value is equal with the actual value
example: assertEquals("the title is not correct", "HTML Form Elements",selenium.getTitle());
The following annotations are used frequently in Selenium scripts:
@Ignore - test methods that use this annotation will be ignored at run time
@Test - identifies a test method; methods that don't have @Test won' be executed at run time
@Before - method will be run before every JUnit @Test method
@After - method will be run after every JUnit @Test method
@BeforeClass - method will be run once before any methods in that class
@AfterClass - method will be run once after all methods in the class
Commands
Some of the commands may return one or more results depending on the number of HTML elements matched by the XPATH locator.
selenium.open(page's relative path)
usage: opens the page that has the relative path provided as argument
example: selenium.open("/selenium/search.php");
selenium.type(XPATH locator of the HTML element, value)
usage: types the value in the HTML element found through the XPATH value
example: selenium.type("xpath=//input[@name='q']", value);
selenium.click(XPATH locator of the HTML element)
usage: clicks the HTML element found through the XPATH value
example: selenium.click("//a[@title = 'a12345']");
selenium.waitForPageToLoad("30000")
usage: wait for some time for the page to load
selenium.getTitle()
usage: gets the value of the title of the current page
selenium.getText(XPATH locator of the HTML element)
usage: gets the text of the HTML element found through the locator
example: selenium.getText("//p[@class = 'abcdef']");
selenium.submit(XPATH locator of the form)
usage: submits a HTML form found through the locator
example: selenium.submit("//form[@id='HTMLFormElements']");
selenium.check(XPATH locator of the checkbox)
usage: checks a checkbox found through the locator
example: selenium.check("//input[@name='checkboxes[]' and @value='cb2']");
selenium.uncheck(XPATH locator for the checkbox)
usage: un-checks a checkbox found through the locator
example: selenium.uncheck("//input[@name='checkboxes[]' and @value='cb3']");
selenium.getXPathCount(XPATH locator)
usage: returns the number of the HTML elements matched by the XPATH locator
ASSERTIONS
The most important assertions for Selenium are assertTrue and assertEquals.
assertTrue(text displayed if the condition is false, condition)
usage: returns true if the condition returns true
example: assertTrue("No homepage URL found ",matchingCountTotal>0)
assertEquals(text displayed if expected value <> actual value, expected value, actual value)
usage: returns true if the expected value is equal with the actual value
example: assertEquals("the title is not correct", "HTML Form Elements",selenium.getTitle());
0 Response to "JUNIT Annotations, Commands and Assertions"
Post a Comment