120 likes | 290 Views
CSCE 747 Software Testing and Quality Assurance. Lecture 19 Selenium Web Driver. Last Time GUI testing 2 Chapter 19. Today Test 1 take-home TestingGeek Testing Web Applications Selenium. Chapter 2. Working with Selenium API. Checking an element's text
E N D
CSCE 747 Software Testing and Quality Assurance Lecture 19 Selenium Web Driver
Last Time • GUI testing 2 • Chapter 19 Today • Test 1 take-home • TestingGeek • Testing Web Applications • Selenium
Chapter 2. Working with Selenium API • Checking an element's text • Checking an element's attribute values • Checking an element's CSS values • Using Advanced User Interactions API for mouse and keyboard events • Performing double-click on an element • Performing drag-and-drop operations Selenium Testing Tools Cookbook by Gundecha – 2012
Executing JavaScript code • Capturing screenshots with Selenium WebDriver • Capturing screenshots with RemoteWebDriver/Grid • Maximizing the browser window • Automating dropdowns and lists • Checking options in dropdowns and lists • Checking selected options in dropdowns and lists • Automating radio buttons and radio groups • Automating checkboxes Selenium Testing Tools Cookbook by Gundecha – 2012
Controlling a Windows process • Reading a Windows registry value from Selenium WebDriver • Modifying a Windows registry value from Selenium WebDriver Selenium Testing Tools Cookbook by Gundecha – 2012
Checking an element's text • While testing a web application, we need to verify that elements are displaying correct values or text on the page. • Selenium WebDriver'sWebElement API provides various ways to retrieve and verify text. • Sometimes, we need to retrieve text or value from an element into a variable at runtime and later use it at some other place in the test flow. • using the WebElement class' getText() method . Selenium Testing Tools Cookbook by Gundecha – 2012
@Test public void testElementText() { //Get the message Element WebElementmessage = driver.findElement(By.id("message")); //Get the message elements text String messageText = message.getText(); //Verify message element's text displays … assertEquals("Click on me and my color will change", messageText); Selenium Testing Tools Cookbook by Gundecha – 2012
assertTrue(messageText.contains("color")); assertTrue(messageText.startsWith("Click on")); assertTrue(messageText.endsWith("will change")); Selenium Testing Tools Cookbook by Gundecha – 2012
Checking an element's attribute values @Test public void testElementAttribute(){ WebElementmessage = driver.findElement( By.id("message")); assertEquals("justify", message.getAttribute("align")); } Selenium Testing Tools Cookbook by Gundecha – 2012
Checking an element's CSS values @Test public void testElementStyle() { WebElementmessage = driver.findElement( By.id("message")); String width = message.getCssValue( "width"); assertEquals("150px",width); } Selenium Testing Tools Cookbook by Gundecha – 2012