Showing posts with label Selenium training classes. Show all posts
Showing posts with label Selenium training classes. Show all posts

Tuesday, 5 August 2014

Manual and Automated Testing

There are mainly two broad types of software testing – Manual Testing and Automated Testing.
Manual Testing
Manual Testing involves testing the software without any automation script or any tool. Testers check the application or software by taking up the role of an end user. They try to find out if there is any unexpected behavior or failure in the application. Test Management can be taken care of by using test plans and test cases.

Automation testing

Automation testing process involves testing with the help of automation scripts and executing the scripts to run the application with the help of some automation tool. Once the script is ready then these tests can run quickly and efficiently.
Since the cost of automated testing is in the form of efforts and time required to create the scripts, not all tests can be converted to automated test. There should be a valid reason to pay that cost.
Reasons for Automation
1. Regression testing to confirm that new changes have not affected the application adversely. It considers already existing test cases for execution. This is an efficient process when we need to provide feedback to the developer immediately.
2. The test cases need to be iterated multiple number of times often with varying datasets to cover multiple workflow paths.
3. When we require support for agile methodologies.
4. Customized reports are required for monitoring.

Getting Started with Automated Testing

Once the need for automated testing has been established, it involves creation of relevant test scripts. Test script creation can be done only by a skilled testers having knowledge of testing, the suite of tools as well functionality under development. Such resources are costly and their time is a premium. Considering this fact, it is often not possible to budget the automation of all tests. Some of the major decision points while identifying cases for testing automation are
1. System modules where requirements do not change frequently
2. Ample time is at hand to describe a test via scripts
3. The application/software module is critical enough to justify the upfront cost of automation
4. After functional testing we want to do performance testing with multiple virtual users using the same test script.
With the scope of automation decided, next step is to pick the testing tool. The following checklist can help with the selection.
1. The tool should be able to easy to work with. It should execute test cases in unattended manner. It should provide interface to write scripts, efficient IDE and ease of test execution.
2. The tool should provide support to various technologies. It should support testing using different browsers, languages, and types of applications.
3. It should integrate with a software that does Application Lifecycle Management so that it can be used for running automated Build Verification Tests as well as the reports can be integrated with other reports created by ALM software

Automated testing frameworks

There are three automated testing tools namely Selenium, QTP (Quality Test Professional) and Coded UI Test (CUIT) .We will consider above mentioned main aspects of automation and see how these tools provide the support for each category.
Ease of Use
- Recording and Playback Functionality
Each of the testing tools has the ability of recording the actions and playback the recorded actions. Selenium provides the plug-in named Selenium IDE with Mozilla Firefox with which the actions can be recorded. QTP provides record button to record a new test. Recording for
- IDE and tools with which the tester can write the scripts
With Selenium IDE there is no special tool and specific technology to write the script. We can insert commands with ‘Table or Source View’ when required.
QTP provides Keyword View to display test steps graphically or Expert View which shows VB Script lines.
Selenium IDE comes as a plug-in with Mozilla Firefox. With this we can create a test suite which comprise of various test cases. With Selenium IDE is, you can convert recorded Selenium IDE scripts into different languages and after conversion you can run it in Selenium RC. Selenium RC has two components, one is “Selenium Server” and another is “Selenium Client”.
With QTP IDE for the first time 3 add-ins are provided ActiveX, Visual Basic and Web. Various links to best practices, new features for the current version are available with start page. We can either open existing test case or create a new one.
- Ease of Test Case execution
With Selenium IDE we have the option of executing the entire test suite already recorded or a test case at a time.
Depending upon the add-ins loaded in QTP IDE the record and run window shows tabs. Windows Application tab is always available. The tests can be executed with run button which in turn opens the run dialog box. We can specify the location for run specific results and provide parameters if any.
These tools can execute test cases without human intervention.

Selenium WebDriver – Interview Questions

1: What is Selenium Web Driver?
Answer:  Selenium Web driver uses accessibility API to drive the browser and recognizes the object in web-based application. It allows writing automated tests replicating the behavior of real user, e.g. Clicking on a link or feeding data in an edit box. Using Selenium Web Driver together with any programming language and other testing framework like TestNG and JUnit, automation test framework to execute tests on different browsers can be created. We can use the robust features of the programming language to interact with other components of application like database interaction, files interaction to create a robust and reliable framework.
 2: What are the various browsers supported by Selenium WebDriver?
Answer: WebDriver available for automation in different browsers are ChromeDriver, InternetExplorerDriver, FirefoxDriver, OperaDriver and HtmlUnitDriver.
 3: What are the programming languages supported by WebDriver?
Answer: Python, Ruby, C#, Java, Perl, php and javascript are supported.
 4: What are the necessary steps required, before I start creating selenium tests on java using eclipse?
Answer: We require following configuration to be set up before creating test in eclipse:
  1.  Java needs to be installed in the machine.
  2.  Eclipse IDE needs to be installed.
  3.  Selenium Libraries for WebDriver should be available.
 5: Do we need to install some additional executable files working with Selenium WebDriver?
Answer: For Firefox driver, we do not require any additional executable as it is bundled with Java client bindings, For IE driver, Chrome driver, and Opera driver, we require additional executable that can be downloadable from Selenium Official website.
An example of how to create an instance of Internet Explorer Web Driver is shown in below example.
6: Is there any specific pre-condition before executing a selenium script on Internet Explorer?
Answer: Yes, Protected Mode settings should be same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.
 7: What are Firefox profile preferences?
Answer: Using Firefox Profile, we can set the preferences for the Firefox in the profile.
The steps to define profile in Selenium are:
1.  Create an object of firefox profile
FirefoxProfile profile = new FirefoxProfile();
2.   Set the required preference of the firefox :
profile.setPreference(“browser.startup.homepage”,”http://www.google.com”)
3.  Create the driver object with profile as defined above.
WebDriver driver = new FirefoxDriver(profile);
8: What is the use of using TestNG with selenium in Java?
Answer: TestNG is a unit testing framework used for java programming language. Test Cases using Selenium Webdriver to identify webelement in the web application can be integrated/created on TestNG framework. Some of the useful features TestNG provides are as follows:
1.  Using Annotation to describe order of test cases, defining start conditions and end condition using  @after and @before annotations.

How to Configure Eclipse to work with Selenium

Before starting working with Selenium using Eclipse IDE, we did some configuration that needs to be done for starting and understanding Selenium. This post will explain step wise, how to start working with selenium using Eclipse:

Pre- Conditions: We will require following before beginning the configuration:

1. Java needs to be installed in the machine.
2. Eclipse IDE needs to be installed .
3. Standalone libraries of selenium, at the time of writing this post, I am using selenium-server-standalone-2.33.0.jar
4. Verify in Path variable in User defined variable for machine, is set to the path where standalone libraries is placed as shown below



Configuration Steps: 


Step 1: In eclipse, create a new java project as shown below from File>New Java Project

Create a new Java Project

Step 2: Once a java project is created, right click on project and select option “Build Path>Configure build path
Configure build path of project
Step 3: Click on Add External JAR’s and add the selenium standalone jar as shown below.
 Step 4: Now in src for the project, Add a new package, and add a new class as shown below.

Select methods stubs to create as public static void main(String[] args)

                                         
Step 5: Write the code in the class created above and execute. This will open Google in internet explorer . Write selenium in search and click on search.

Code to be placed in void main:

WebDriver ieDriver = new InternetExplorerDriver();
ieDriver.get(“http://www.google.com”);
WebElement element = ieDriver.findElement(By.name(“q”));
element.sendKeys(“selenium”);
element.submit();

Design Patterns in Selenium

Before creating tests in Selenium, we should look for design patterns to be followed in the test. Defining Design pattern to be used in automation helps in easier maintenance of the project once the number of tests increases. Design Pattern should be used in such a manner that rework due to of any code changes are minimum, creating new test uses the existing code.
Following are a few strategies or design patterns used in Selenium for making tests easier to create and maintain:
1.       Page Object Model
2.       Using Page Factory in Page object
3.       Loadable components
When we write code for tests in Selenium, we can break down the code in such a manner that code maintenance is better. Suppose we have two tests. One tests for an image visible on home Page post login and another verifies welcome text post logging in the application. Writing the same code in two different tests will require code to be changed in two different places in case object property changes in login Page and at times in case we have large number of tests in the test suite, it will take considerable time to fix the automation code. We should refactor the code and create smaller private methods that are used in different tests.
So now, we can make change at one place and it will be reflected in many tests by refactoring the tests.
In Page Object Model, we create individual classes for each of the pages with all the methods pertaining to the Page. These methods specific to a page covers both positive and negative scenarios specific to page.
Page Object Model reduces the duplication of code, improves readability and increases robustness of the test. Also the code is lot more maintainable, which is specifically useful in case properties of objects in the application changes frequently.
Page Factory uses the factory class from web driver’s support library to define objects in the page in a better and simpler manner. We declare some fields on a PageObject that are Web Elements or List<Web Element>.initialize the page objects.
We can use Loadable components in the Page design providing a standard way of ensuring that pages are loaded successfully.
Together with this, we can use best practices to ensure the quality of code is highly robust, reusable and maintainable.

Selenium Remote Control

Selenium Remote Control (RC)

 Overview

  • While Selenium IDE may seem a productive and efficient tool for writing test-cases, it lacks many essential features of a testing tool:
    • Conditional statements
    • Loops
    • Logging
    • Exception handling
    • Reporting
    • Test fixtures and data-driven tests
    • Test dependencies
    • Taking screenshots
  • Selenium RC is the answer to a more powerful test-suite for your applications.
  • It follows a client/server model allowing client libraries to execute tests on a browser controlled by the server.
images/selenium_rc_overview.png

Selenium Server

  • Selenium server is the program that drives the browser
  • It embeds Selenium Core framework and injects it into the browser
  • It communicates with the running test client and drives the browser
  • Client tests sends commands that the server interpretes in order to drive the browser
  • The server sends back results to the client
  • Client and server communicates via HTTP GETs and POSTs so you can easily plug into
  • Server is configurable at startup via command-line options. use java -jar selenium-server.jar -h to see the list of options

Client libraries

  • Client libraries provides the API to program tests and execute them on the server
  • Each implementation provides access to all Selenium commands
  • Supported API implementation exists in:
    • Java (also accessible via Groovy)
    • .Net
    • PHP
    • Python
    • Perl
    • Ruby

Locators In Selenium

Locators
Selenium uses what is called locators to find and match the elements of your page that it needs to interact with. There are 8 locators strategies included in Selenium:
  • Identifier
  • Id
  • Name
  • Link
  • DOM
  • XPath
  • CSS
  • UI-element
 Identifier
Works with the ID and name attributes of your html tags. Let’s consider the following example:
<html>
<body>
<form id=”login”>
<input name=”username” type=”text”/>
<input name=”password” type=”password”/>
<input name=”submit” type=”submit” value=”Continue!”/>
</form>
</body>
</html>
Valid locators for this snippet are :
  • identifier=login
  • identifier=username
  • submit
Id
The Id strategy looks for an element in the page having an id attribute corresponding to the specified pattern. <label id=”my_id” /> will be matched by a locator like id=my_id or just my_id
 Name
Like the Id strategy, but on the name attribute. You can also specify a filter to refine your locator. Currently, there are two filter types :
  • Value : matches elements with a name attribute and where the value follows a pattern. The following example illustrates the interest of filters :
  • <html>
  •  <body>
  •    <div id=”pancakes”>
  •      <button type=”button” name=”pancake” value=”Blueberry”>Blueberry</button>
  •      <button type=”button” name=”pancake” value=”Banana”>Banana</button>
  •      <button type=”button” name=”pancake” value=”Strawberry”>Strawberry</button>
  •    </div>
  •  </body>
</html>
Link
This strategy is intended to select links only and selects the anchor element containing the specified text: link=The text of the link
DOM
The DOM strategy works by locating elements that matches the javascript expression refering to an element in the DOM of the page.
  • dom=document.div['pancakes'].button[0]
  • document.div[0].button[2]
  • dom=function foo() { return document.getElementById(“pancakes”); }; foo();
XPath
While DOM is the recognized standard for navigation through an HTML element tree, XPath is the standard navigation tool for XML; and an HTML document is also an XML document (xHTML). XPath is used everywhere where there is XML. Valid XPath locators can be:
  • xpath=//button[@value="Blueberry"]: matches the Blueberry button
  • //div[@id="pancakes"]/button[0]: same thing
CSS
The CSS locator strategy uses CSS selectors to find the elements in the page. Selenium supports CSS 1 through 3 selectors syntax excepted CSS3 namespaces

Commands In Selenium

Commands

The Selenium API defines dozens of commands that can be categorized into the following:
  • Actions
  • Accessors
  • Assertions

 Actions

  • Actions are commands that change the state of the application like clicking links or buttons, select an option in a <select> or type a character sequence in a given textbox.
  • Actions are available in different flavors. For instance, click(locator) will trigger a click on an element locator but you can also find:
    • clickAndWait(locator) command which will trigger a click and stop the test until the browser has finished loading a new page.
    • clickAt(locator, offset) command that also triggers a click but takes another argument: a X and Y tuple that offset the actual clicking location by X and Y pixels.
    • A combination of the above : clickAtAndWait(locator,offset) that combines the specification of an offset for the click location and waits for a new page to load.
    test with actions
    ?
    type id=search Donuts near my home
    ?
    • type modifies the state of the application (it modifies a test field) and so is considered as an action

    Accessors

    • Accessors inspect the state of the application and store values in variables.
    • For instance, storeCookies(variableName) stores all the cookies in use in the current page in the variable variableName.
    • To use stored variables, the syntax is ${variablename} (or storedVars['variableName'] if in a JavaScript context):
      Test with variables
      store my_search_string searchString
      ?
      type id=search ${searchString}
      ?
      and if in a JavaScript code section:
      if (storedVars['variableName'] == '') {
        ...
      }

     Assertions

    • Assertions are also able to inspect the current page but:
      • They are made to return a boolean value
      • This boolean represents the conformity of the element to a desired pattern
      • Usually, the pattern represents the state of an element.
    • Assertions come into 3 flavors:
      • assert : if assertion fails, test is aborted and marked as failed : assertTitle(pattern) will fail if the title of the page doesnot correspond to the pattern argument.
      • verify : if a verification fails, the test doesnot stop but a trace will be printed in the log.
      • waitFor : these commands pause the test until a condition is satisfied or a timeout is reached.

Friday, 4 July 2014

Selenium Interview Questions

Below are the few commonly asked Selenium Interview Questions
What is Selenium?
Selenium is a suite of tools for browser automation. It is composed of “IDE”, a recording and play back mechanism, “WebDriver” and    remote control “RC” which provides APIs for browser automation in variety of languages and “Grid”, which allows many tests using APIs to be run in parallel. The recorded tests can be imported in most languages like html, Java , .net , perl , ruby etc. The exported test can be run in any browser and any platform using selenium remote control “RC”
 What are the components of selenium ?
Selenium IDE – Plugin to Firefox to record and play test in Firefox and also export tests in different languages. The most appealing format is the html test case which seems to be based on fit html
Selenium RC- Allows playing of exported test in different platform/OS
Selenium Grid – Allows to control lots of selenium machines(you typically don’t need this only for load test -and hence may ignore it).
What are the capabilities of Selenium WebDriver or Google WebDriver or Selenium 2.0? 
Capabilities of Selenium WebDriver or Google WebDriver or Selenium 2.0 are:
One should use WebDriver when requiring improved support for
  1. Mult-browser testing including improved functionality for browsers not well-supported by Selenium-1.0.
  2. Handling multiple frames, multiple browser windows, pop-ups, and alerts.
  3. Page navigation.
  4. Drag-and-drop.
  5. AJAX-based UI elements.
Which are the browsers supported by Selenium RC?
Browsers supported by Selenium RC are:
  1. Firefox
  2. Mock
  3. Firefoxproxy
  4. pifirefox
  5. iexploreproxy
  6. iexplore
  7. firefox3
  8. Safari proxy
  9. Google chrome
  10. conqueror
  11. firefox2
  12. safari
  13. piiexplore
  14. firefoxchrome
  15. Opera
  16. iehta
What are the Operating Systems supported by Selenium?
Operating Systems supported by Selenium are:
Selenium IDE
Works in Firefox 2+ Start browser, run tests Run tests
Operating Systems Supported:
  1. Windows
  2. OS X
  3. Linux
  4. Solaris
  5. Others whichever supports Firefox 2+
Selenium Remote Control:
Used for starting browser and run tests
Operating Systems Supported:
  1. Windows,
  2. OS X
  3. Linux
  4. Solaris
  5. Others
Selenium Core:
Used for running tests
Operating Systems Supported:
  1. Windows
  2. OS X
  3. Linux
  4. Solaris
  5. Others
What is the difference between assert and Verify Commands?
There are two mechanisms for validating elements that are available on the application under test. The first is assert: this allows the test to check if the element is on the page. If it is not available, then the test will stop on the step that failed. The second is verify: this also allows the test to check whether the element is on the page, but if it isn’t, then the test will carry on executing.
What is the price of Selenium license per server?
Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.
How much does Selenium license cost per client machine?
Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.
Where to download Selenium?
Selenium can be downloaded and installed for free from seleniumhq.org

Selenium Tutorial using C# and NUnit

We are pleased to supply a lot of information and a dozen of free hands-on tutorials. All the available tutorials are surrounded with screenshots and downloadable code samples. This blog is created and will be maintained by Quontra Solutions. Quontra solutions Trainers have many years of experience in automated testing. Quontra Solutions is particularly interested in web technology and new programming languages. We are always trying to find a way to transfer knowledge to Students who are interested in the automated testing of software.
A variety of topics will be covered on this blog. Starting with recording tests with Selenium IDE and locating web elements and furthermore the use of design patterns and performance measurement to create a robust testing framework.
Selenium Tutorial using C# and NUnit
In this tutorial we are going to learn how to create your first test script using the language that most commonly used, c#. Since most languages are semantically the same, if you do not use c# it shouldn’t be too difficult to translate the tutorial into your language of choice. You have to download Nunit and at least Visual Studio Express c# edition to complete this tutorial. They are free to download and use.
  1. Follow steps 1-4 of Selenium Remote Control HTML Suite Tutorial. This will get the Selenium Remote Control Running.
  2. In Visual Studio let’s create a new project. You will have to create a new class library by going New> New Solution> Class Library and call it TheAutomatedTester
  3. Add a reference to the NUnit Framework by rightclicking on the solution and clicking add reference. Click on the browse tab and navigate to <%nunithome%>\bin and select nunit.framework.dll . This allows you now to create your first NUnit test.
  4. Now in the *.cs file put the code below into it. The code below will call Selenium Remote and say that it needs an instance on Firefox Chrome.
  1.        [TestFixture]
  2.        public class TheAutomatedTester
  3.        {
  4.                private ISelenium selenium;
  5.            private StringBuilder verificationErrors;
  6. [SetUp]
  7. public void SetupTest()
  8. {
  9.        selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://localhost”);
  10. selenium.Start();
  11. verificationErrors = new StringBuilder();
  12.    }


  1. Now Lets create a test:
  1. [Test]
  2. public void AutomatedTester_Test()
  3. {
  4. selenium.Open(“/index.htm”);
  5. selenium.Click(“buttonName”);
  6. selenium.WaitForPageToLoad(“30000″);
  7. }
The code above would open the page index.htm for the root of your local web server then click on a button and wait for a page to load. If you want to see how to the other commands look I would suggest creating your command in Selenium IDE and then converting them to c# using the Options > Format commands.
  1. Once your test has run you will need to clean up Selenium object. The best way to do this is to create a teardown function in your test. It should look like something like the code below.
  1. [TearDown]
  2. public void TeardownTest()
  3. {
  4. try
  5. {
  6. selenium.Stop();
  7. }
  8. catch (Exception)
  9. {// Ignore errors if unable to close the browser
  10. }
  11. Assert.AreEqual(“”, verificationErrors.ToString());
  12. }
If you make sure that your code has this teardown then you will be able to reuse the Selenium Remote Control.
  1. Now compile the code into a DLL and Open it with NUnit. When you click the Run button in NUnit it will run your Selenium Test.
If you would like to make your test data driven put all the code to pull the data in the SetUp.

QTP vs Selenium

Features Selenium QTP
Cost Open Source & Comfortable User needs license for QTP which is very costly.
Efforts and Skill User needs to have good amount of Java skill and more coding effort is required to implement the functions It requires less effort to create a script, as it has a very good user friendly script development environment
Test Case Termed as Testcase. Each Testcase has block of coding statements Termed as Automation Script
Support for web browsers Supports IE, Firefox, Safari and Opera Supports IE & Firefox only
Support for File upload (system) Not available Supports all kinds of File upload
Database Support With the help of DSN (ODBC32 Interface) Requires Extensive Coding
Language Support VBScript Selenese, Java, Ruby, Perl, PHP, Python, C#, Groovy
Technical Support Since it is an open source, it has no official tech support QTP offers very good technical support via phone, mail, web forum
Application Type It can be used to test only web based applications It can test web-based as well as desktop applications