Friday, 31 October 2014

How to Test the data from captcha in selenium webdriver

How to Test the data from captcha in selenium webdriver


Captcha is coming from an environment under your control, you will likely need to implement some sort of method indicating you are in a test environment and have the captcha system return a known value or some indicator of what the expected value is.




NOTE

I feel the need to add some clarification to the ideas put forth in the question, answer and comments. Essentially you are dealing with one of the following situations (note that when I say 'your', I am referring to you, your company, client, etc):

-MY form, Your captcha system: If this is the case, your best solution is to work with your developers to add a 'test' mode to your captchas, returning either a known value, or additional information in the page that indicates what the expected value should be. If you are able to make use of a tool, either written by you, or by another, that can successfully 'read' the captcha image, your system is broken. If you can do it in test mode, what is to stop anyone else  from bypassing your captcha in exactly the same manner.

-MY form, 3rd Party captcha system: If this is the case, your best solution is again to see if the system has some 'test' mode that you can make use of. I have no experiance with these systems myself but in general would guess that test methods exist for the major systems out there. A Google search of {Captcha System Name} automated testing should return some good hints as to how to go about testing with the system. If nothing good comes from that, your next bet would be to implement your own, internal, test only, dummy captcha system that work with some known value and make your captcha provider configurable so that you can point to your test system in test/dev/etc and your real system in production.



-Other Form, Unknown captcha system: I am going to make a leap of faith here and assume this is not your case, but just for completeness I will include it. If this is your case, your not testing anything at all and are simply asking for help bypassing someone else's security mechanisms for your own reasons. If that is the case, please seek your assistance on less scrupulous sites.

Wednesday, 29 October 2014

Difference between webdriver.close() and webdriver.quit()

Difference between webdriver.close() and webdriver.quit()


close()

Close the current window, quitting the browser if it's the last window currently open.

quit()

Quits this driver, closing every associated window.

webDriver.Close() - Close the browser window that the driver has focus of

2. webDriver.Quit() - Calls dispose

3. webDriver.Dispose() Closes all browser windows and safely ends the session

Tuesday, 28 October 2014

Explicit and Implicit Waits

Explicit and Implicit Waits

Waiting is having the automated task execution elapse a certain amount of time before continuing with the next step. You should choose to use Explicit Waits or Implicit Waits. Mixing both will cause unintended consequences, namely waits sleeping for the maximum time even if the element is available or condition is true.

WARNING: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10s and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.

Explicit Waits

An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is Thread.sleep(), which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one way this can be accomplished.

WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));


Implicit Waits

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

Tuesday, 21 October 2014

Assertion or Verification?

Assertion or Verification?

Choosing between “assert” and “verify” comes down to convenience and management of failures. There’s very little point checking that the first paragraph on the page is the correct one if your test has already failed when checking that the browser is displaying the expected page. If you’re not on the correct page, you’ll probably want to abort your test case so that you can investigate the cause and fix the issue(s) promptly. On the other hand, you may want to check many attributes of a page without aborting the test case on the first failure as this will allow you to review all failures on the page and take the appropriate action. Effectively an “assert” will fail the test and abort the current test case, whereas a “verify” will fail the test and continue to run the test case.
The best use of this feature is to logically group your test commands, and start each group with an “assert” followed by one or more “verify” test commands. An example follows:
Command Target Value
open /download/
assertTitle Downloads
verifyText //h2 Downloads
assertTable 1.2.1 Selenium IDE
verifyTable 1.2.2 June 3, 2008
verifyTable 1.2.3 1.0 beta 2
The above example first opens a page and then “asserts” that the correct page is loaded by comparing the title with the expected value. Only if this passes will the following command run and “verify” that the text is present in the expected location. The test case then “asserts” the first column in the second row of the first table contains the expected value, and only if this passed will the remaining cells in that row be “verified”.

verifyTextPresent

The command verifyTextPresent is used to verify specific text exists somewhere on the page. It takes a single argument–the text pattern to be verified. For example:
Command Target Value
verifyTextPresent Marketing Analysis
This would cause Selenium to search for, and verify, that the text string “Marketing Analysis” appears somewhere on the page currently being tested. Use verifyTextPresent when you are interested in only the text itself being present on the page. Do not use this when you also need to test where the text occurs on the page.

verifyElementPresent

Use this command when you must test for the presence of a specific UI element, rather than its content. This verification does not check the text, only the HTML tag. One common use is to check for the presence of an image.
Command Target Value
verifyElementPresent //div/p/img
This command verifies that an image, specified by the existence of an <img> HTML tag, is present on the page, and that it follows a <div> tag and a <p> tag. The first (and only) parameter is a locator for telling the Selenese command how to find the element. Locators are explained in the next section.
verifyElementPresent can be used to check the existence of any HTML tag within the page. You can check the existence of links, paragraphs, divisions <div>, etc. Here are a few more examples.
Command Target Value
verifyElementPresent //div/p
verifyElementPresent //div/a
verifyElementPresent id=Login
verifyElementPresent link=Go to Marketing Research
verifyElementPresent //a[2]
verifyElementPresent //head/title
These examples illustrate the variety of ways a UI element may be tested. Again, locators are explained in the next section.

verifyText

Use verifyText when both the text and its UI element must be tested. verifyText must use a locator. If you choose an XPath or DOM locator, you can verify that specific text appears at a specific location on the page relative to other UI components on the page.
Command Target Value
verifyText //table/tr/td/div/p This is my text and it occurs right after the div inside the table.

Locating Elements

Thursday, 16 October 2014

Selenium Interview Questions :by Sonata

Selenium Interview Questions :by Sonata

First Round Written Exam questions:
1)    Define checked and unchecked exception?
2)    Define Stale Element Exception?
3)    Different ways to identify web elements using selenium?
4)    List names of few maven phases?
5)    Define singleton class?
6)    What is Application Server and Web server?
7)     To reverse an integer?
8)    How to test private method in java?
9)    Define Priority and Severity?
10)    What is the difference between Implicit and Explicit wait ?
11)    Create Test plan to reverse function and generate Test cases?
12)    Explain Bug life cycle?
13)    What is inner join and outer join?
14)    Difference between smoke and sanity testing?
15)    Different Asserts in selenium?
Second Face to Face interview:
1)    Array list
2)    Hashtable
3)    Hashmap
4)    This
5)    Super
6)    This()
7)    Super()
8)    How to handle multiple windows in webdriver?
9)    How to count multiple windows in webdriver?
10)    How to handle alert messages or pop up windows?
11)    How to retrieve the data from alert message?
12)    What locator u frequently used to identify element?
13)    Why Xpath only to identify webelement?
14)    How to identify an web elements having with  the same  name?
15)    What are the different annotations used in TestNG framework?
16)    Explain about ur project Architecture?
17)    What is the difference between Selenium R.C and Webdriver?

Wednesday, 15 October 2014

How to get Text Box value

//How to get Text Box value

public class gettextvalue
{
  public static void main(String[] args) throws InterruptedException
  {
    WebDriver driver = new FirefoxDriver();

    //Puts a Implicit wait, Will wait for 10 seconds before throwing

exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //Launch website
    driver.navigate().to("http://seleniumguru.blogspot.in/");
   
    //Maximize the browser
    driver.manage().window().maximize();

    // Enter value "selenium" in the first n
        driver.findElement(By.xpath("//*[@id='CustomSearch1_form']/form/table[1]/tbody/tr/td[1]/input  [1]")).sendKeys("selenium");

    // Get the text box from the application
    String result = driver.findElement(By.xpath("//*[@id='CustomSearch1_form']/form/table[1]/tbody/tr/td[1]/input[1]")).getAttribute("value");

    //Print a Log In message to the screen
    System.out.println(" The Result is " + result);
   
    //Close the Browser.
    driver.close();   
  }
}

Monday, 13 October 2014

Selenium - java syntax for locating elements in selenium Webdriver

Selenium - java syntax for finding elements in selenium Webdriver

1.Method : By ID
Syntax: driver.findElement(By.id(<element ID>))
Description: Finds an element the using ID attribute

2.Method : By name
Syntax: driver.findElement(By.name(<element name>))
Description: Finds an element the using Name attribute

3.Method : By By tag name
Syntax: driver.findElement(By. By tag name (<element ID>))
Description: Finds an element the using tag name attribute

4.Method : By link text
Syntax: driver.findElement(By. link text (<element link text >))
Description: Finds an element the using link text  attribute

5.Method : By partial link text
Syntax: driver.findElement(By. partial link text (<element ID>))
Description: Finds an element the using partial link text attribute

6.Method : By CSS
Syntax: driver.findElement(By. cssSelector (<element ID>))
Description: Finds an element the using cssSelector attribute

7.Method : By xpath
Syntax: driver.findElement(By. xpath (<element ID>))
Description: Finds an element the using xpath attribute



Thursday, 9 October 2014

Program to send hello world in google search

//Program to send hello world in google search
// package name com.test.selenium
package com.test.selenium;
//importing packages
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//creating class
public class FirtExampleSelenium {

    public static void main(String[] args) {
     //Invoke firefox browser
     WebDriver driver = new FirefoxDriver();

    //Goto google search
     driver.get("https://www.google.co.in/");
     //type hello world
     driver.findElement(By.id("gbqfq")).sendKeys("hello world");
    //quit firefox browser
     driver.quit();

  )
}


Introduction



Introduction
Selenium is an open source and a portable automated software testing tool for testing web applications that has capabilities to operate across different browsers and operating systems. Selenium is just NOT a single tool but a set of tools that helps testers to automate web based applications more efficiently.
Let us now understand each one of those tools in the selenium suite and its uses. We will look at eac
Tool

Selenium IDE:

Selenium Integrated Development Environment (IDE) is a Firefox plugin that lets testers to allows testers to record their actions as they follow the workflow that they need to test.

Selenium RC:

Selenium Remote Control(RC) was the flagship testing framework that allowed more than simple browser actions and linear execution.It makes use of the full power of programming languages such as Java,C#,PHP,Python,Ruby and PERL to create more complex tests.

Selenium WebDriver:

Selenium WebDriver is the successor to Selenium RC which sends commands directly to the browser and retrieves results.

Selenium Grid:

Selenium Grid is a tool used to run parallel tests across different machines and different browsers simultaneously which results in minimized execution time.

Selenium Advantages
QTP and Selenium are the most used tools in the market for software automation testing purposes. Hence it is making more sense to now compare the pros of selenium over QTP/UFT.
Selenium
Selenium is an Open source tool.
Can be extended for various technologies which exposes DOM.
Has capabilities to execute the scripts across different browsers.
Can execute scripts on various Operating Systems.
Supports mobile devices.
Executes tests within the browser, so focus is NOT required while script execution in progress.
QTP
QTP is a Commercial tool and cost involved in each one of the license.
Limited Add-ons and needs Add-ons for each one of those technologies.
Can run tests in specific versions of Firefox ,IE and Chrome.
Works only with Windows.
Supports mobile devices with the help of third party tools.
Needs Focus during script execution as the tool acts on the browser(mimics user actions)
QTP cannot execute tests in parallel but integrating QTP with QC allows testers to execute in parallel. QC is also a commercial tool.
Selenium Disadvantages
Let us now discuss the pitfalls of selenium over QTP.
Selenium
Supports only Web Based Applications.
No Feature such as Object Repository/Recovery Scenario
No IDE so the script development won't be as fast as QTP.
Cannot access controls within the browser
No Default test report generation.
For Parameterization, users has to rely on the programming language


QTP
Can test both Web and desktop applications.
QTP has OR and Recovery Scenarios built-in.
More Intuitive IDE, Automation can be achieved faster.
Can access controls within the browser such as favorites bar, backward and forward buttons.
Default test result generation within the tool.
Parameterization is builtin and easy to implement.
Selenium - IDE
The Selenium-IDE (Integrated Development Environment) is an easy-to-use Firefox plug-in for develop Selenium test cases. It provides a Graphical User Interface for recording user actions using Firefox which is used to learn and use Selenium, but it can only be used only with Firefox browser as other browsers are not supported.
However, The recorded scripts can be converted into various programming languages supported by Selenium and the scripts can be executed on various other browsers as well.