JUNIT Annotations, Commands and Assertions

AnnotationsThe 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

CommandsSome 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 argumentexample: 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 valueexample: selenium.type("xpath=//input[@name='q']", value);selenium.click(XPATH locator of the HTML element)usage: clicks the HTML element found through the XPATH valueexample: selenium.click("//a[@title = 'a12345']");selenium.waitForPageToLoad("30000")usage: wait for some time for the page to loadselenium.getTitle()usage: gets the value of the title of the current pageselenium.getText(XPATH locator of the HTML element)usage: gets the text of the HTML element found through the locatorexample: selenium.getText("//p[@class = 'abcdef']");selenium.submit(XPATH locator of the form)usage: submits a HTML form found through the locatorexample: selenium.submit("//form[@id='HTMLFormElements']");selenium.check(XPATH locator of the checkbox)usage: checks a checkbox found through the locatorexample: selenium.check("//input[@name='checkboxes[]' and @value='cb2']");selenium.uncheck(XPATH locator for the checkbox)usage: un-checks a checkbox found through the locatorexample: selenium.uncheck("//input[@name='checkboxes[]' and @value='cb3']");selenium.getXPathCount(XPATH locator)usage: returns the number of the HTML elements matched by the XPATH locatorASSERTIONSThe 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 trueexample: 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 valueexample: assertEquals("the title is not correct", "HTML Form Elements",selenium.getTitle());