Wednesday, 25 February 2015

MY Notes on Selenium Web Driver

                



**WebDriver doesn't support record and playback feature.
**WebDriver is a purely object oriented tool.
**Captcha and Bar code readers cannot be tested using Selenium.
**windows pop up cannot be handled using Selenium.
**Single Slash “/” – Single slash is used to create Xpath with absolute path.
**Double Slash “//” - Double slash is used to create Xpath with relative path.
**find if an element in displayed on the screen?
isSelected()
isEnabled()
isDisplayed():
boolean buttonPresence = driver.findElement(By.id(gbqfba”)).isDisplayed();
**To get a text of a web element?
String Text = driver.findElement(By.id(“Text”)).getText();
**To select value in a dropdown?
selectByValue:
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(greenvalue”);

selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(“Lime”);

selectByIndex:
Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(2);
**Different types of navigation commands?
navigate().back(
navigate().forward()
navigate().refresh()
navigate().to()
driver.navigate().back();
**To click on a hyper link using linkText?
driver.findElement(By.linkText(“Google”)).click();
**When do we use findElement() and findElements()?
findElement():-first matching element would be fetched.
findElements():-It is used to find all the elements in the current web page.
**Difference between driver.close() and driver.quit command?
driver.close()- closes the web browser window that the user is currently working.
driver.quit()- closes down all the windows that the program has opened.
**How can we handle web based pop up?
void dismiss() – The dismiss() method clicks on the “Cancel” button as soon as the pop up window appears.
void accept() – The accept() method clicks on the “Ok” button as soon as the pop up window appears.
String getText() – The getText() method returns the text displayed on the alert box.
void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.
**How to assert title of the web page?
//verify the title of the web page
assertTrue(“The title of the window is incorrect.”,driver.getTitle().equals(“Title of the page”));
**How to retrieve css properties of an element?
driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);
driver.findElement(By.id(“id“)).getCssValue(“font-size”);
**How to capture screenshot in WebDriver?
    @Test
      public void test() throws IOException 
{
        // Code to capture the screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        // Code to copy the screenshot in the desired location
FileUtils.copyFile(scrFile, new File("C:\\CaptureScreenshot\\google.jpg"));                  
    }
}
**How to set test case priority in TestNG?
package TestNG;
import org.testng.annotations.*;
public class SettingPriority {
      @Test(priority=0)
      public void method1() {   
      }
      @Test(priority=1)
      public void method2() {  
      }
      @Test(priority=2)
      public void method3() {  
}
}
**Advantage of Test Automation framework

Reusability of code
Maximum coverage
Recovery scenario
Low cost maintenance
Minimal manual intervention
Easy Reporting
**What are the different types of frameworks?

Module Based Testing Framework: The framework divides the entire “Application Under Test” into number of logical and isolated modules. For each module, we create a separate and independent test script. Thus, when these test scripts taken together builds a larger test script representing more than one module.
Library Architecture Testing Framework: The basic fundamental behind the framework is to determine the common steps and group them into functions under a library and call those functions in the test scripts whenever required.
Data Driven Testing Framework: Data Driven Testing Framework helps the user segregate the test script logic and the test data from each other. It lets the user store the test data into an external database. The data is conventionally stored in “Key-Value” pairs. Thus, the key can be used to access and populate the data within the test scripts.
Keyword Driven Testing Framework: The Keyword driven testing framework is an extension to Data driven Testing Framework in a sense that it not only segregates the test data from the scripts, it also keeps the certain set of code belonging to the test script into an external data file.
Hybrid Testing Framework: Hybrid Testing Framework is a combination of more than one above mentioned frameworks. The best thing about such a setup is that it leverages the benefits of all kinds of associated frameworks.
Behavior Driven Development Framework: Behavior Driven Development framework allows automation of functonal validations in easily readable and understandable format to Business Analysts, Developers, Testers, etc.

  Selenium IDE is missing certain vital features of a testing tool: conditional statements, loops, logging functionality, 
exception handling, reporting functionality, database testing, 
re-execution of failed tests and screenshots taking capability. 
Selenium IDE doesn't for IE, Safari and Opera browsers.

Selenium IPhone Driver/Android Driver for running tests on Mobile Safari & Android browsers.

Selenium is basically used for the functional/Regression/Integration testing of web based applications & also Selenium is used for UAT (User Acceptance Test)

**The following commands are available within Selenium for processing Alerts:
getAlert()
assertAlert()
assertAlertNotPresent()
assertAlertPresent()
storeAlert()
storeAlertPresent()
verifyAlert()
verifyAlertNotPresent()
verifyAlertPresent()
waitForAlert()
waitForAlertNotPresent()
waitForAlertPresent()
The AlertPresent() and AlertNotPresent() functions check for the existence or not of an alert – regardless of it’s content. The Alert() functions allow the caller to specify a pattern which should be matched. 
The getAlert() method also exists in Selenium RC, and returns the text from the previous Alert displayed.

**Assertions
assertTextPresent : This will assert if the text is present in the page.
assertText: This will assert if a particular element is having the particular text.
assertTitle: This will assert if the page is having a proper title.
assertValue: This will assert if a Text box or check box has a particular value
assertElementPresent: This will assert if a particular UI Element is present in the page.

**Selenium WaitFor Commands?
waitForPageToLoad : This command will make the script to wait till the page loads. Syntax is waitForPageToLoad(timeout); Time out is the maximum time the script will wait for the page to load.
waitForAlert : This command will wait for the alert message to appear
waitForTable: This command will wait for the Web table to completely load in the page
waitForTitle: This command will for the page Title to appear on the browser. 
Other waitFor commands : Selenium has several other wait command like waitForText, waitForPopup and so on. These commands are generically called Synchronization commands.

No comments:

Post a Comment