Automation testing:
What is Automation testing ?
Automation Testing is the process of testing the application using any Automation Tool.
Testing an application feature with the help of Automation tool & executing test script is called as Automation testing
When we should do Automation Testing
when you want to run the same test cases multiple times
when you want to run the same test cases across multiple machines at the same time
when functionality of application is stable
What are the Advantages of Automation Testing ?
Re usability of test script
Compatibility testing is easy and possible
Less Human efforts are required
Project duration is reduced
Cost of project is reduced
Improve Accuracy
Some Automation tools used in Organisation are as below:
Selenium
QTP
Appium
Cucumber
Katalon
What are the Dis-Advantages of manual testing ?
Compatibility testing is difficult
Test Cycle duration will be increased
More efforts are required
Regression testing is time consuming
Selenium Automation Tool
What is Selenium?
Selenium is open source automation testing suite to test web application.
It supports different platform and browser.
It has gained a lot of popularity in terms of web based automation testing.
Selenium is a set of different software tools. Each tool has a different approach in supporting web based automation testing What are the component in Selenium?
It has four Component namely:
Selenium Integrated Development Environment (IDE)
Selenium Remote Control (Now Deprecated)
WebDriver
Selenium Grid
Advantages of Selenium are as below:
Selenium is an Open Source software
Selenium supports various operating system (Windows, Linux, Mac)
Selenium Supports various programming languages (like Java, Python, Ruby, C#)
Selenium supports various Browsers (Chrome, IE, Opera, Safari)
Disadvantages of Selenium are as below:
We can automate web based application only
We cannot automate standalone application
We cannot automate Captcha
Selenium does not support file uploading
Adhoc test cases cannot be automated
Cannot read barcode
What are the Java Concepts used in Automation Testing:
Inheritance
Interface
Polymorphism
Casting (Upcasting)
Encapsulation
Abstraction
Arrays
Collection
Foe Loop, For Each Loop, While loop , Iterator
Control statement
String Class
Selenium Architecture:
Search context is a super most interface which contains abstract methods and inherited to webdriver.
Webdriver is an interface which contains abstract method of search context and its own abstract method.
All the abstract methods are overridden or implemented in selenium remote webdriver class.
Selenium remote webdriver :-
It is a class which implements all the abstract methods of both interface.
Selenium remote webdriver class is extended to browsers such as firefox driver, chrome driver etc.
To run application in multiple browsers (C.T.) i.e. writing test script by using single browsers but run the some script in multiple browsers we need to use runtime polymorphism by using upcasting in selenium.
WebDriver drive = new ChromeDriver
Create on object of ChromeDriver class with reference of WebDriver interface.
Different type of locators in selenium
We have 8 types of locators in Selenium Webdriver to find elements on web pages.
1. id is a Fastest locator in all 8 locators
Ex. driver.findElement(By.id(‘email’)).sendKeys("abc");
2. Name
Ex. driver.findElement(By.name(‘email’)).click();
3. ClassName
Ex.driver.findElement(By.className("inputtext 55r1 6luy")).sendKeys("abc");
4. TagName
Ex. driver.findElement(By.tagName("input")).sendKeys("abc");
5. LinkText
Ex. driver.findElement(By.linkText("facebook")).click();
6. PartialLinkText
Ex. driver.findElement(By.partialLinkText("book")).click();
7. x path
Absolute x path and Relative X path are the two main types of x path.
1. Absolute x path -
UN: /html/body/div[1]/input[1]
contact: /html/body/div[2]/input[3]
login: /html/body/div[3]/button
2. Relative X path -
UN: //div[1]/input[1] or //div[1]//input[1]
contact: //div[2]/input[3] or //div[2]//input[3]
login: //button
Ex.//input[@id='email']
Difference Between Absolute x path vs Relative x path :-
| Absolute Xpath | Relative Xpath |
1. | starts with the /(Single slash) symbol | starts with the //(Double slash) symbol |
2. | We need to start from the root Node(html) | We can start from any node |
3. | Absolute xpath is lengthy | relative xpath is short |
Sometimes web element on the web page keep changing so Dynamic X path came in picture.
What Is Dynamic Web Element?
A dynamic element is a Web Element whose IDs and not just IDs, but any attribute such as Class Name, Value, and so on, are not fixed.
Therefore, every time you reload the page, it changes. As a result, you cannot handle that element solely through the locator.
For example, the class name of Gmail Inbox elements changes with each login.
How to handle dynamic web element?
1.Using contains
driver.findElement(By.xpath("//button[contains(@id,'u_0_5_')]")).click();
2.Using starts with
driver.findElement(By.xpath("//button[starts-with(@id,'u_0_5_')]")).click();
3.Using xpath axes
driver.findElement(By.xpath("//form[@method='post']/descendant::button")).click();
4.using Text
driver.findElement(By.xpath("//button[contains(text(),'Log in']")).click();
5.Using Index
driver.findElement(By.xpath("//button[1]")).click();
8. CSS selector is a Fastest between CSS and x path
CSS (cascading style sheet)
Developer uses it Designing web pages in more attractive way,to apply any size,colour,font.
CSS locator
Css locator is a method provided in selenium through which we can locate element.
CSS locator is a collection of multiple attribute.
So its customised, so we can create our own CSS selector.
Most CSS selector are mainly use with the combination of tag name.
Suppose id attribute is available for element, then we can take id and tag name of that element.
Suppose name is available then we can take name and tag name of that element.
So we can say its a tag and attribute combination.
Mainly four ways are in CSS selector:-
· Tag and ID
· Tag and class
· Tag and attribute
· Tag, class, and attribute
Here input is tagname,email is id attribute value.
1)Tag and ID
Driver.findElement(By.cssSelector(“input#email”)).sendkeys(“john”);
Driver.findElement(By.cssSelector(“#email”)).sendkeys(“john”);
Here input is tagname,inputtext is classname attribute value.
2)Tag and class
Driver.findElement(By.cssSelector(“input.inputtext”)).sendkeys(“john”);
Driver.findElement(By.cssSelector(“.inputtext”)).sendkeys(“john”);
Here input is tagname,name=email is a attribute and its value.
3)Tag and attribute
Driver.findElement(By.cssSelector(“[name=email]”)).sendkeys(“john”);
Driver.findElement(By.cssSelector(“input[name=email]”)).sendkeys(“john”);
Here input is tagname, inputtext is classname attribute value,data-testid=royal-email is a attribute and attribute value
4)Tag, class, and attribute
Driver.findElement(By.cssSelector(“input.inputtext[data-testid=royal-email]”)).sendkeys(“john”);
Driver.findElement(By.cssSelector(“input.inputtext[data-testid=royal-pass]”)).sendkeys(“john”);