January 26, 2017

Locators in Selenium and How to Use


Selenium WebDriver uses 8 locators to find the elements on web page. The following are the list of locators supported by selenium.

I’ve listed all locators to be used when scripting.

Locator
Description
Usage
Id
Select the Element using @id attribute
By.id(<id of the tag>)
Name
Select first Element with the specified @name attribute
By.name(<name of the tag>)
ClassName
Select first element with the specified @class attribute
By.className(<class of the tag>)
LinkText
Select anchor tag which matches the text specified
By.linkText(“<text of the link”);
partialLinkText
Select anchor tag which contains the text specified
By. partialLinkText (“<text of the link”);
tagName
Select the first element with the specified tag
By.tagName(<tag name>)
cssSelector
Select the element using the CssSelector Provided
By.cssSelector(“cssSelector”)
xPath
Select the element using the xpath expression
By.xPath(“xpath of the element”)

Locating an Element by ID:

The most efficient way and preferred way to locate an element on a web page is by ID. ID will be the unique on web page which can be easily identified.
IDs are the safest and fastest locator option and should always be the first choice even when there are multiple choices, it is like an unique identification number.
Examples:
  1. <div id="mainMenu">menu items</div>
  2. <input id="email" class="emailAddress" type="text"/>

How?
  • WebElement Ele = driver.findElement(By.id("mainMenu "));

Unfortunately, there are many cases where an element does not have a unique id (meaninge ids are being dynamically generated). In these cases, we need to choose an alternative locator strategy, however if possible we should ask development team of the web application to add few ids to a page specifically for automating the application.

Locating an Element by Name:

When there is no Id to use, the next worth seeing if the desired element has a name attribute. But make sure there the name cannot be unique all the times. If there are multiple names, Selenium will always perform action on the first matching element
Examples:
  1. <input name="login" class="loginClass" type="submit"/>
  2. <label name="login">

How?
  • WebElement loginButton= driver.findElement(By.name("login"));

As I said, from the above example if you observe both label and input tags are having the same value for ‘Name’ attribute. If you try to find the element using name locator, input tag will be considered as it is the first tag which matches the specified name

Locating an Element by LinkText:

Finding an element with link text is very simple. But make sure, there is only one unique link on the web page. If there are multiple links with the same link text (such as repeated header and footer menu links), in such cases Selenium will perform action on the first matching element with link.
Examples:
  1. <a href="/html/default.asp">Learn HTML</a>

How?
  • WebElement linkHtml = driver.findElement(By.linkText("Learn HTML "));

Locating an Element by Partial LinkText:

In the same way as LinkText, PartialLinkText also works in the same pattern, but the only difference here is you not required provide exact name of the link.
Examples:
  1. <a href="/html/default.asp">Learn HTML</a>
  2. <a href="/css/default.asp">Learn CSS</a>

How?
  • WebElement download = driver.findElement(By.PartialLinkText("Learn"));

Locating an Element by TagName:

TagName can be used with Group elements like, Select and check-boxes / dropdowns.
Examples:
                <select name=’Weekends’>
                        <option>Saturday</option>
     <option>Sunday</option>
                </select>
How?
  • WebElement selectTag = driver.findElement(By.tagName("select"));

Locating an Element by Class Name:

There may be multiple elements with the same name, if we just use findElementByClassName,m make sure it is only one. If not the you need to extend using the classname and its sub elements.
Example:
  1. <input name="login" class="loginClass" type="submit"/>

How?
  • WebElement loginClass =driver.findElement(By.className(“loginClass”));

Locating an Element by CSS Selector:

CSS mainly used to provide style rules for the web pages and we can use for identifying one or more elements in the web page using css.
cssSelector is faster than xpath expression. We can you use Css Selectors to make sure scripts run with the same speed in IE browser. CSS selector is always the best possible way to locate complex elements in the page.
Important point in cssSelector:
  1. Immediate child is defined as > Ex: div>input
  2. Child of child is defined as white space Ex: div input
  3. Id will be represented as # Ex: input#loginTest
  4. Class will be represented as dot(.) Ex: input.loginClass
  5. Next sibling will be represented as +
  6. Attribute Values will be represented as input[name=’sample’]
  7. String matchers
    1. Equals: input[id=’user_name’]
    2. Starts with: Input[id^=’user_’]
    3. Ends with: Input[id$=’_name’]
    4. Sub string: input[id*=’ser_na’]
  8. Inner Text will be represented as input.contains(‘mailAddre’)

How?:
  • WebElement emailAddress = driver.findElements(By.cssSelector("input[id=’email']"));

Locating an Element by XPath:

XPath is designed to allow the navigation of XML documents, with the purpose of selecting individual elements, attributes, or some other part of an XML document for specific processing
There are two types of xpath
  • Native Xpath, it will start from the root tag normally it is html
    • Here the advantage of specifying native path is, finding an element is very easy as we are mention the direct path. But if there is any change in the path (if something has been added/removed) then that xpath will break.

  • Relative Xpath, it we will be the relative path, it is like we will tell the xpath to find an element by telling the path in between.
    • Advantage here is, if at all there is any change in the html that works fine, until unless that particular path has changed. Finding address will be quite difficult as it need to check each and every node to find that path.

Example:
<html>
    <head>
        <title>…</title>
    </head>
    <body>
       <div>
          <input>…</input>
          <span>…</span>
       </div>
    </body>
</html>
How?
  • Native xpath = html/body/div/input
  • Relative xpath = //div/input

Other Example:
  1. Image: //img[@alt='image alt text goes here']
  2. Table: //table[@id='table12']/td[4]
  3. Anchor Tag:  //a[contains(@href,'href goes here')]
  4. Input: /input[@name='name2' and @value='yes']
Please find the above information in the attached file Locators

October 4, 2016

Software Development Life Cycle (SDLC)

What is SDLC?

                There are various software development approaches defined and designed which are used during development process of software, these approaches are we normally called as “Software Development Process Models” (e.g. Waterfall model, incremental model, V-model, iterative model, RAD model, Agile model, Spiral model, Prototype model etc.). Each process model follows a particular life cycle in order to ensure success in the process of software development.
Software life cycle models describe phases of the software cycle and the order in which those phases are executed. Each phase produces deliverables required for the next phase in the life cycle. i.e., the output of one phase will be the input for the next phase. For example once the requirements are collected we start the design phase and once the design phase is completed we will start developing/Code the application. Once the code is developed it will be assigned to the tester to test the application. If everything is properly developed we will deploy the code.
There are six phases in every Software development life cycle model:
  1. Requirement gathering and analysis
  2. Design
  3. Implementation OR coding
  4. Testing
  5. Deployment OR Installation
  6. Maintenance


 Requirement gathering and analysis
Business requirements are gathered in this phase. This phase is the main focus of the project managers and stake holders. Meetings with managers, stake holders and users are held in order to determine the requirements like: who is going to use the system? How will they use the system?  What data should be input into the system?  What data should be output by the system?  These are general questions that get answered during a requirements gathering phase. After requirement gathering these requirements are analyzed for their validity and the possibility of incorporating the requirements in the system to be development is also studied.
Output: Requirement Specification document is created which serves the purpose of guideline for the next phase of the model
Design
In this phase the system and software design is prepared from the requirement specifications which were studied in the first phase. System Design helps in specifying hardware and system requirements and also helps in defining overall system architecture.
Output: The system design specifications serve as input for the next phase of the model.
In this phase the testers comes up with the Test strategy, where they mention what to test, how to test.
Implementation / Coding
On receiving system design documents, the work is divided in modules/units and actual coding is started. Since, in this phase the code is produced so it is the main focus for the developer. This is the longest phase of the software development life cycle.
Output: Developed code/system as per the requirements in the system design and FRD for that release
Testing
After the code is developed it is tested against the requirements to make sure that the product is actually solving the needs addressed and gathered during the requirements phase. During this phase all types of functional testing like unit testing, integration testing, system testing, acceptance testing are done as well as non-functional testing are also done.
Output: Feedback on the developed code. Here there are two directions.
  • One is if the requirements are satisfied and the application is behaving as it is intended to then it will deployed to the production
  • Second is if many of the requirement are not satisfied or the application is not behaving as it is expected then it will be go the Coding phase
Deployment
After successful testing the product is delivered / deployed to the customer for their use.
As soon as the product is given to the customers they will first do the beta testing. If any changes are required or if any bugs are caught, then they will report it to the engineering team. Once those changes are made or the bugs are fixed then the final deployment will happen.
Output: End user experience on the deployed system, if he is facing any problem it will go to Maintenance Phase
Maintenance

Once when the customers starts using the developed system then the actual problems comes up and needs to be solved from time to time. This process where the care is taken for the developed product is known as maintenance.

Please find the below article to learn about the Agile software development guide 

Software Testing Life Cycle (STLC)

What is Software Testing Life Cycle (STLC)
Software Testing is not a single activity. It consists of several activities carried out in a systematic way to deliver an efficient software product. All these Activities /Phases constitute STLC.

Below are the Activities /Phases of STLC:
  1. Requirements Gathering phase
  2. Test Planning Phase
  3. Test Case Development Phase
  4. Environment Setup Phase
  5. Test Case Execution Phase
  6. Test Conclusion Phase
  7. Test Cycle Closure Phase
Each of these activities have a definite Activities & Deliverables associated with it

1. Requirement Phase: During this phase of STLC, we will analyze and study the requirements. Here in this phase we will discuss with stakeholders to understand the requirements clearly and try to find out whether the requirements are testable or not. This phase helps to identify the scope of the testing. If any feature is not testable, communicate it during this phase so that the mitigation strategy can be planned.
Activities
o    Identify types of tests to be performed (Smoke, Sanity, Regression and Automation testing etc.,).
o    Prioritize the requirements.
o    Prepare Requirement Traceability Matrix (RTM).
o    Identify test environment details where testing is supposed to be carried out.
o    Automation feasibility analysis (if required).
Deliverables 
o    RTM
o    Automation feasibility report. (if applicable)
2. Test Planning Phase: Infact, Test planning is the first step of the testing process. In this phase we identify the activities and resources which would help to meet the testing objectives. Typically this will done by Sr. QA Manager.
Activities
o    Preparation of test plan/strategy document for various types of testing
o    Test tool selection
o    Test effort estimation
o    Resource planning and determining roles and responsibilities.
o    Training requirement
Deliverables 
o    Test plan /strategy document.
o    Effort estimation document.
3. Test Case Development PhaseThe major task in this STLC phase is of creation of the detailed test cases. Prioritize the test cases also identify which test case will become part of the regression suite. Before finalizing the test case, It is important to carry out the review to ensure the correctness of the test cases. And it is also important to take the confirmation of the the test cases created before the actual execution starts. If automation testing is required, identify the test cases for automation and proceed for scripting the test cases and make sure that you sent them fro review and got confirmation.
Activities
o    Create test cases, automation scripts (if applicable)
o    Review and baseline test cases and scripts
o    Create test data (If Test Environment is available)
Deliverables 
o    Test cases/scripts
o    Test data
4. Test Environment Setup PhaseTest environment includes software and hardware conditions under which product is to be tested. Test environment set-up is one of the critical aspects of testing process and can be done in parallel with Test Case Development Stage. Test team may not be involved in this activity if the customer/development team provides the test environment. In this case test team is required to do a readiness check (smoke testing) of the given environment.
Activities 
o    Setup test Environment and test data
o    Perform smoke test on the build
Deliverables 
o    Environment ready with test data set up
o    Smoke Test Results.
5. Test Execution PhaseDuring this phase test team will carry out the testing based on the test plans and the test cases prepared. Bugs will be reported back to the development team for correction and once the bug is fixed by the development team, retesting/regression will be performed.
Activities 
o    Execute tests as per plan
o    Document test results, and log defects for failed cases
o    Map defects to test cases in RTM
o    Retest the defect fixes
o    Track the defects to closure
Deliverables 
o    Completed RTM with execution status
o    Test cases updated with results
o    Defect reports
6. Test Conclusion Phase: This phase concentrates on the exit criteria and reporting. We've to know the reporting persons. Depending on your project and stakeholders choice, you can decide on reporting whether you want to send out a daily report or weekly report etc.
There are different types of reports
o    DSR – Daily status report
o    WSR – Weekly status reports
The important point is, the content of the report changes and depends upon whom you are sending your reports.
o    If you are reporting to Project managers belong to testing background then they are more interested in the technical aspect of the project, so include the technical things in your report ( number of test cases passed, failed, defects raised, severity 1 defects etc.).
o    If you are reporting to upper stakeholders, they might not be interested in the technical things so report them about the risks that have been mitigated through the testing.
Activities
o    Provide the accurate figures and result of testing
o    Identify the risks which are mitigated
Deliverables 
o    Updated Taceability Metrics
o    Test Status report
o    Risk management report
7. Test Cycle Closure Phase: Testing team will meet , discuss and analyze testing artifacts to identify strategies that have to be implemented in future, taking lessons from the current test cycle.
The following are the tasks for the Test Closure:
o    Check for the completion of the test. Whether all the test cases are executed or mitigated deliberately. Check there are no severity 1 defects opened.
o    Do lessons learnt meeting and create lessons learnt document.( Include what went well, where are the scope of improvements and what can be improved)
Activities
o    Evaluate cycle completion criteria based on Time,Test coverage,Cost,Software,Critical Business Objectives , Quality
o    Prepare test metrics based on the above parameters.
o    Document the learning out of the project
o    Prepare Test closure report
o    Qualitative and quantitative reporting of quality of the work product to the customer.
o    Test result analysis to find out the defect distribution by type and severity.
Deliverables 
o    Test Closure report
o    Test metrics