Monday, 5 September 2011

Selenium - Basics

1. Selenium supported browsers include:
 
*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom
2. TestNG - Eclipse plug-in

Select Help / Software updates / Find and Install.
• Search for new features to install.
• New remote site.
• For Eclipse 3.4 and above, enter http://beust.com/eclipse.
• For Eclipse 3.3 and below, enter http://beust.com/eclipse1.
• Make sure the check box next to URL is checked and click Next.
• Eclipse will then guide you through the process.

3. Sample TestNG script

package testing;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;

public class TestNGtest {
xxxxxx;
yyyyyy;
zzzzzz;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");
seleniumserver.start();
selenium.start();
}
@Test
public void testDefaultTNG()throws Exception {
selenium.open("http://www.hotmail.com/");
selenium.windowMaximize();
}
@AfterClass
public void tearDown()throws Exception {
selenium.stop();
seleniumserver.stop();
}
}

4. Handle security exception in selenium

  a) create a firefox profile
- uncheck all “Security” options

 b) add the profile to selenium start command as ;

java -jar selenium-server.jar -firefoxProfileTemplate "C:\FireFoxCust"

5. Some commanly used selenium commands

verifyText- verifies expected text and it’s corresponding HTML tag are present on the page.

verifyTable - verifies a table’s expected contents.

verifyTitle/assertTitle - verifies an expected page title.

verifyElementPresent- verifies an expected UI element, as defined by its HTML tag, is present on the page.

open - opens a page using a URL.

waitForPageToLoad - pauses execution until an expected new page loads. Called automatically when clickAndWait is used.

waitForElementPresent - pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.

click/clickAndWait - performs a click operation, and optionally waits for a new page to load.

verifyTextPresent - verifies expected text is somewhere on the page.

storeElementPresent - This corresponds to verifyElementPresent. It simply stores a boolean value–”true” or “false”–depending on whether the UI element is found.

storeText - StoreText corresponds to verifyText. It uses a locater to identify specific page text. The text, if found, is stored in the variable. StoreText can be used to extract text from the page being tested.

storeEval - This command takes a script as its first parameter. Embedding JavaScript within Selenese is covered in the next section. StoreEval allows the test to store the result of running the script in a variable

  

 

No comments:

Post a Comment