Tuesday 17 March 2020

Find element and Findelements


What are Find Element and Find Elements in Selenium?
The pre requisite of Find Element and Find Elements, we need to understand what is a WebElement. WebElement is an interface, and it represents an HTML element on a web page. We can find the WebElement by searching it in the DOM source. The WebDriver API provides built-in methods for it.
Find Element
The Find Element helps to find a web element(one) and returns the WebElement reference. It finds the first matching web element on the web page.

Syntax : webelement element = driver.findelement(by.locator(“value”));

Here, By is a class in WebDriver. It has the mechanism to locate a web element. It uses various locator strategies to locate the element. The locator strategy may include values like,
  •   Id
  •   Name
  •  Class Name
  •  Tag Name
  •   Link Text
  •   Partial Link Text
  •   Xpath

The locator value helps to identify a web element uniquely. These values are found by referring to the HTML source code of the element. Example of a web element command

Example : WebElement username = driver.findElement(By.name("user"));
Find Elements :
The Find Elements helps to find web elements(more than one) and returns a list of web elements

Syntax : list< webelement>  element = driver.findelements(by.locator(“value”));

Ex :  list<WebElement> links = driver.findElements(By.tagname("a"));

In the above example, it finds the list of all links present on the web page using the tag name, “a”.


Code for the better understanding :
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class findelements{
public  static void main (string args[])
{
                WebDriver driver = new ChromeDriver();
                driver.manage().window().maximize();
                driver.get("https://google.com/");
                List listOfLinks = driver.findElements(By.tagName("a"));
                WebElement thirdlink = listOfLinks.get(3);
                System.out.println(thirdlink.getText());
                for(int i=0;i<listOfLinks.size();i++) {
                WebElement link = listOfLinks.get(i);
                System.out.println(link.getText());
                }
     }
}
Difference between Find Element and Find Elements
                Find Element
                     Find Elements
1. It returns a single element on the web page.
1. It returns a list of elements on the web page.
2. It finds the first matched web element.
2. It finds all the web elements that match.
3. It doesn’t require indexing.
3. These elements are indexed from 0 and can be get using get().


Sunday 19 November 2017

Types of Testing

Types of Testing:

v  Sanity Testing:
Validating the major functionality of the application is called Sanity Testing.
As soon as application is required into testing environment we need to validate whether the        main functionality of the application is working fine or not. Because if the major functionality of the application is not working fine, we cannot conduct the complete testing on the application.
    In this case we need to report the defect to the development team immediately with urgent severity, we will reject the build. In this case the development team is also need to fix those defects immediately.

Factors to get sanity testing failed:
è Environmental issues
è Compatibility issues

v  Smoke Testing:
Validating the major functionality of the application by the development team,  in the development environment.

v  Usability (or) GUI (or) User interface:
Look and feel of the application
Verifying user friendliness of the application in terms of  logo’s, colors, fonts, alignments

v  Functional Testing:
Validating the overall functionality of the application, along with major functionalities with respect to the client business requirements.

v  Security Testing:
Validating the security of the application in terms of authentication & authorization.

Authentication: Verifying whether system is accepting valid user or not
Authorization: Verifying whether the system is providing right information to the right person or not.

We will give more preference to the security testing for web based applications.

v  Data base Testing:
Validating the database of the application is called database testing..Whatever we performed in the front end that should reflect in the back end database.

For performing DB testing most of the projects use TOAD or Query analyzer.

v  Compatibility Testing:
Performing testing on application in different browsers is called compatibility testing or browser compatibility testing.

v  Configuration Testing:
Performing testing on the application in different configuration is called configuration testing

v  Re Testing:
Testing conducting on the fixed defect is called retesting.

v  Regression testing:
Testing conducting on the fixed build or modified application is called regression testing.

(At the time of execution if we identify any defects, we need to report to the development team and once development team has fixed defect we need to perform Re-testing on fixed defect)

(Once the fixed defect is working fine, we need to thing for fixing defect. Developer might have changed other functionality. That is reason we are again performing the testing on the modified application)

v  Test data:
A data or a value which we are using to perform testing on the application is called test data.
Most of the project test data will provide by client and in some projects we need to create our own test data to perform testing.
In some projects we are maintaining one separate team called Test data management team.

v  Positive test data:
A positive data or value which we are using to perform testing on the application is called positive test data.
EX:- Valid UID, Valid PWD

v  Negative test data:
A negative data or value which we are using to perform testing on application is called negative testing.
EX:- Invalid UID, PSW

v  Positive testing:
Performing testing on the application with positive test data is called as Positive testing.

v  Negative testing:
Performing testing on the application with negative test data is called as negative testing.

v  Alpha Testing:
Performing testing on the application by the client directly, this testing we are performing in the projects, because in project after completion of testing in testing environment client will perform testing in UAT environment.

v  Beta Testing:
Performing testing on the application by the client like people, this testing we are performing in products, because we are not developing the product for the specific client. So client like people perform testing on the product.

v  Performance testing:
Validating the performance of the application in term of load and stress

Load testing: Validating the performance of the application with respect to client expected users.
EX: As per the client requirement application should work fine with 5000 users. After completion of developing the application need to validate the performance of the application.

Stress Testing: Validating the performance of the application by increasing the client expected users to the peak level an identifying the “Break point” or “Knee point
EX: As per the client requirement application should work fine with 5000 users, in stress testing we are validating the performance by increasing the expected users from 5000 to 10000 and 10000 to 30000. At some point of time application will be hanged.

Note: The break point or knee point information we need to provide to the client for appropriate us of application.

v  Recovery Testing:
In this we are verifying how much time application is taking to come back from abnormal state to normal state.
EX: sometimes application will be hanged or crashed in that case we need to check how much time application is taking to come back from down status to up status.

v  Random (or)Monkey(or) Gorilla Testing:
Performing testing on the application randomly

EX: If we have 20 functionalities in one application, we need to perform testing sequentially. But in random testing we are validating testing randomly like 1, 5, 8, 12 etc,.

We can prefer this testing if we don’t have enough time to complete the execution of the test cases. But in real time this testing is not applicable or suggestible.
       
                If we are not able to complete the testing in time w can follow two approaches
1.      Postpone the release
2.      Partial release

Postpone the release:
If we are not able to complete the testing in the project we can postpone the release to the mid release as per the client conformation.

Partial release:
If we are not able to complete the testing we can release the completed module now and incomplete modules we can release in the next release.

v  Exploratory Testing:
By learning the domain knowledge of the application we are performing testing on the application. This helpful when we are changing from one domain to other domain
EX: Healthcare domain to telecom domain.

v  Parallel Testing:
Performing testing on the application by comparing similar type of application in the market

This testing is not possible in projects because in RDP we can able to access only one project related applications. We cannot access other application so parallel testing is not possible.

v  Static testing:
Performing testing on the application without doing any action is called static testing.

v  Dynamic testing:
Performing testing on the application by doing some action is known as dynamic testing.

v  Mutation Testing:
Performing testing on the application by changing the source code of the testing is called mutation testing.

v  URL Testing:

Verifying whether we are able to navigate to the application when we enter URL(one of the security testing)

Software Development Life Cycle

SDLC (Software Development Life Cycle):
The process to complete software product or project that includes both testing and development.
        We have different models of SDLC in industry, based on the requirements of the client only we will choose anyone of te model to complete the project

Types of SDLC:
1.      V-Model
2.      Waterfall Model
3.      Spiral model
4.      Prototype Model
5.      RAD Model
6.      Agile Model
7.      Fish Model

(1.    V-Model)
Verification:
Verification is are we developing the application in Right manner or not
Validation is did we develop right application or not
Verification and Validation, in this model both development and testing activities goes parallel. This model suitable for large scale projects, which clients are having stable requirements. In this model new requirements are accepted in the middle of the project.



(2.    Water fall Model)
In this model after successful completion of development only testing activity will start. This model is suitable for small scale projects. New requirements are not accepted in the middle of the project. In this model project maintenance and monitoring is easy.

(3.    Spiral Model)
(100% Accuracy) in this model we will divide the total project into individual modules. And for each module we are implementing the SDLC process and develop the application. This model is suitable for scientific projects because they require 100% accuracy.

(4.    Prototype Model)
This model is suitable for projects in which clients are not having clear requirements and they do not have any idea about final application. In this case we analyses the client requirements and prepare a prototype of application.
     If client accepts that prototype, then we will write actual code for that application. If client not accepts then developer need to prepare another prototype... We need to continue this process till customer accepts.

(5.    RAD Model)
Rapid Application Development, in this model we will develop the application by using existing source code of the application. This model is suggestible for the project when clients are not having enough time.

(6.    Agile Model)

This model is suitable for project, if the requirements of the client changing very frequently. This model is suitable for banking domain projects.

Sunday 12 November 2017

How to create testNG Programme

1. Right click on Package folder, go to TestNG and select “TestNG Class“.

2) If your project is set up and you have selected the Test Case folder before creating TestNG class then the source folder and the package name will be prepopulated on the form. Set class name as ‘TestNG‘.
Under Annotations, check “@BeforeMethod”, “@AfterMethod” and click Finish.


3) Now it will display the newly created TestNG class under the Test Case package(folder). TestNG class will look like the image below with displaying three empty methods. One method f() by default and before & after method, as selected during the creation of the class.
Now it is the time to write the first TestNG test case.

5) Let’s take an example of First Test Case and divide the test case in to three parts
@BeforeMethod: Launch Firefox and direct it to the Base URL
@Test: Enter Username & Password to Login, Print console message and Log out
@AfterMethod: Close Firefox browser
                package automationFramework;

                import java.util.concurrent.TimeUnit;

                import org.openqa.selenium.By;

                import org.openqa.selenium.WebDriver;

                import org.openqa.selenium.firefox.FirefoxDriver;

                import org.testng.annotations.Test;

                import org.testng.annotations.BeforeMethod;

                import org.testng.annotations.AfterMethod;

                public class TestNG {

                public WebDriver driver;

                 @BeforeMethod

                  public void beforeMethod() {

                  // Create a new instance of the Firefox driver

                driver = new FirefoxDriver();

                      driver.get("http://www.Gmail.com");
               
                  }

                @Test
                public void main() {

                // Find the element that's ID attribute is 'account' And enter send keys

                   driver.findElement(By.id("Email")).sendKeys("malli.arjun440@gmail.com");
                // Click on Next Button

                driver.findelement(by.id("next")).click();

                // Find the element that's ID attribute is 'pwd' (Password)

                // Enter Password on the element found by the above desc.

                driver.findElement(By.id("Passwd")).sendKeys("Test@123");

                // Now Sign In. WebDriver will find the form for us from the element

                driver.findElement(By.id("signIn")).click();

                // Print a Log In message to the screen

                  System.out.println(" Login Successfully, now it is the time to Log Off buddy.");

                // Find the element that's ID attribute is 'account_logout' (Log Out)

                 driver.findElement(By.id("account_logout"));

                  }

                  @AfterMethod

                  public void afterMethod() {

                  // Close the driver

                  driver.quit();

                 } }
                 
6) Run the test by right click on the test case script and select Run As > TestNG Test.




Results of running the Testng:
7) Give it few minutes to complete the execution, once it is finished the results will look like this in theTestNg Result window.
It displayed ‘passed : 1′. This means test is successful and Passed.
There are 3 sub tabs. “All Tests”, “Failed Tests” and “Summary”. Just click “All Tests” to see what is there.
As you see, there is information of which test cases are executed and their duration. Take look to other tabs. Better than Junit right?







8) TestNG also produce HTML reports. To access those reports go to the Project directory and opentest-output folder.


9) Open ‘emailable-report.html‘, as this is a html report open it with browser.











10) TestNG also produce ‘index.html‘report and it resides in the same test-output folder. This reports gives the link to all the different component of the TestNG reports like Groups & Reporter Output. On clicking these will display detailed descriptions of execution. In the advance chapter of TestNG we will go through each of the TestNG topics.