Professional Documents
Culture Documents
Fourteen-May Lecture
Fourteen-May Lecture
Fourteen-May Lecture
Navigation
Public static WebDriver driver;
driver.navigate().to("http://www.google.com");
-This navigate to given link
driver.navigate().forward();
-This navigate to next to google.com we should have to declare one mpre navigate to
driver.navigate().back();
-This navigate to back page i.e.google.com
driver.get(“http://www.google.com”);
-this work as navigate.to();
Assignment question
Have to give choice to user, which browser you want to open, give 4 options.
---------------------------------------15-may-2021------------------------
Login to webpage by selenium-
1. Locating webelements
driver.findElement(By.id("txtUsername")).sendKeys("Admin");
Assignment No.2-
What is Xpath?
Relative
The path starts from the middle of the HTML DOM structure
Its start with the double forward slash (//), which means it can search the element
anywhere at the webpage
e.g. on web page www.google.com Gmail hyperlink can be located with
//*[@id='gbw']/div/div/div[1]/div[1]/a
or
//a[@data-pid='23']
or
//a[contains(text(),'Gmail')]
notepad notes
- By Xpath
-> It stands for XML path
-> It is the path of DOM structure to locate your
element
-> 2 types
1. Absolute xpath [starts from the root node
i.e html . start with single slash /]
2. Relative Xpath [starts from the middle node and
it starts with double slash //]
"/html/body/div/div/div[10]/ul/li[3]/a"
//div[@id='divPassword']/input
17-05-2021
What is Alert?
Alert is a small message box which displays on-screen notification to give the user
some kind of information
Ask for permission to perform certain kind of operation
It may be also used for warning purpose
Types of Alerts
Simple Alert
Simple alert displays some information or warning on the screen
Prompt Alert
Prompt Alert asks some input from user
selenium webdriver can enter the text using sendkeys(" input…. ")
Confirmation Alert
Confirmation alert asks permission to do some type of operation
Moving on to Alert
import org.openqa.selenium.Alert;
Import this package prior to the script creation
This package references to the Alert class which is required to handle the web
based alerts
Alert alert=driver.switchTo().alert();
We create a reference variable for Alert class and references it to the alert
The above command is used to switch the control to the recently generated pop up
window
3. Handling Alerts
- Use Alert class. It contains methods for
handling the alert.
- Alert alert = driver.switchTo().alert();
- Get the message on Alert
alert.getText();
- To click on OK button
alert.accept();
- To click Cancel button on alert
alert.dismiss();
- To send text on alert
alert.sendKeys();
19-05-21
What is checkpoint?
Checkpoint compares the expected values of object properties to the object's
current values captured at runtime
20-5-21
Various ways to compare
Comparing two screen shots of entire Page
Comparing two images
Taking screenshot of full page
TakesScreenshot indicates a driver to capture a screenshot and store it in
different ways
OutputType can be
File
Bytes
Base64
Class
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("PageScreenshotActual.png"));
Comparing 2 images
Toolkit object is an abstract class that provides an interface to platform-specific
details
The getDefaultToolkit() method returns the system’s default Toolkit object.
Toolkit.getDefaultToolkit().getImage(file1)
GetImage - Returns an image which gets pixel data from a specified file
The PixelGrabber class implements an ImageConsumer which can be attached to an
Image to retrieve a subset of the pixels in that image
Have to login by admin go to skill page and add skill and after that take
screenshot and compare with expected. crop the image which skill you have added
21-05-21
What is Alert?
Alert is a small message box which displays on-screen notification to
give the user some kind of information
Ask for permission to perform certain kind of operation
It may be also used for warning purpose
Types of Alerts
Simple Alert
Simple alert displays some information or warning on the screen
Prompt Alert
Prompt Alert asks some input from user
selenium webdriver can enter the text using sendkeys(" input…. ")
Confirmation Alert
Confirmation alert asks permission to do some type of operation
Moving on to Alert
import org.openqa.selenium.Alert;
Import this package prior to the script creation
This package references to the Alert class which is required to handle the web
based alerts
Alert alert=driver.switchTo().alert();
We create a reference variable for Alert class and references it to the alert
The above command is used to switch the control to the recently generated pop up
window
How to handle Alerts
Accept Alert
driver.switchTo().alert().accept();
The command accepts the alert thereby clicking on the Ok button
Dismiss Alert
driver.switchTo().alert().dismiss();
The command closes the alert thereby clicking on the Cancel button and hence the
operation should not proceed
Get Alert message
driver.switchTo().alert().getText();
Send data to Alert box
driver.switchTo().alert().sendKeys("Text");
notepad notes
1. What are Alerts?
- Alert is a message box that contains some
information with an ok button.
2. Types of Alerts
- Simple Alert
- Confirmation Alert
- Prompt Alert
- Simple Alert
-> It is a message box with an OK button.
- Confirmation Alert
-> It is an alert which confirms your action,
and has 2 buttons , OK and Cancel
- Prompt Alert
-> It is an alert which accepts input from
user.
3. Handling Alerts
- Use Alert class. It contains methods for
handling the alert.
- Alert alert = driver.switchTo().alert();
- Get the message on Alert
alert.getText();
- To click on OK button
alert.accept();
- To click Cancel button on alert
alert.dismiss();
- To send text on alert
alert.sendKeys();
Login by admin and add one skill manualy and you have to delete and handle pop up
Assignment
1
1. Single cell
2. Column headings
3. All names from table
4. all rows and count for number of rows
2.Search a particulare name inside table and if it present show the position or
else not present
24-05-2021
Frames-we can't directly switch frame to frame we should get back to parentframe
or default content first then switch to another frame.
Methods
build()
Generates a composite action containing all actions so far, ready to be performed
(and resets the internal builder state, so subsequent calls to build() will contain
fresh sequences)
clickAndHold()
Clicks (without releasing) at the current mouse location.
.
doubleClick()
Performs a double-click at the current mouse location.
perform()
A convenience method for performing the actions without calling build() first
release()
Releases the depressed left mouse button at the current mouse location
sendKeys(java.lang.CharSequence... keysToSend)
Sends keys to the active element
sendKeys(WebElement element, java.lang.CharSequence... keysToSend)
Equivalent to calling: Actions.click(element).sendKeys(keysToSend)
Method 1:
act.clickAndHold(From).build().perform();
act.moveToElement(To).build().perform();
act.release(To).build().perform();
Method 2:
dragAndDrop(Source, Target).build().perform();
25-05-2021
BufferedReader
BufferedReader class reads text from a character-input stream, buffering characters
so as to provide for the efficient reading of characters, arrays, and lines
String readLine()
This method reads a line of text
import java.io.BufferedReader;
BufferedWriter
The Java.io.BufferedWriter class writes text to a character-output stream,
buffering characters so as to provide for the efficient writing of single
characters, arrays, and strings
import java.io.BufferedWriter;
FileWriter
This class inherits from the OutputStreamWriter class
The class is used for writing streams of characters
import java.io.FileWriter;
FileReader
Class for reading character files
import java.io.FileReader;
BufferedReader br = new BufferedReader( new FileReader("datafile.csv"));
while((line=br.readLine())!=null)
{
String[] data=line.split(",");
driver.findElement(By.xpath(“”)).sendKeys(data[0]);
driver.findElement(By.xpath(“”)).sendKeys(data[1]);
}
Assignment-
edit skill= write script for editing skill and add skill manually one, add that
skill and description and enter on orange hrm using csv file and object repositery
31-05-2021
TestNG is a testing framework inspired from JUnit and NUnit but introducing some
new functionalities that make it more powerful and easier to use
Selenium tests do not generate the Test Results in proper format
Hence user use TestNG for grouping test cases, parallel testing and getting
meaningful test reports
TestNG Annotations
@Test
The annotated method is a part of a test case
@BeforeMethod
The annotated method will be run before each test method
@AfterMethod
The annotated method will be run after each test method
@BeforeClass
The annotated method will be run before the first test method in the current class
is invoked
@AfterClass
The annotated method will be run after all the test methods in the current class
have been run
@BeforeTest
The annotated method will be run before any test method belonging to the classes
inside the tag is run
@AfterTest
The annotated method will be run after all the test methods belonging to the
classes inside the tag have run
@BeforeSuite
The annotated method will be run before all tests in this suite have run
@AfterSuite
The annotated method will be run after all tests in this suite have run
Annotations execution
Testsuit
Test
Class
Method
Test
Method
Class
Test
Testsuit
01-06-2021
Cronological order
BeforeTest
BeforeMethod
Test
AfterMethod
BeforeMethod
Test2
AfterMethod
AfterTest
Dependent Tests
TestNG allows to specify dependencies with attributes dependsOnMethods
@Test(dependsOnMethods={'openBrowser'})
public void closeBrowser()
{ driver.close();
}
@Test
Public void openBrowser()
{ driver = new FirefoxDriver();
}
whenever we include groups that time alwayRun=true is used to run before and after
methods
03-06-2021
What is POM?
Page Object Model is a design pattern to create Object Repository for web UI
elements
Under this model, for each web page in the application there should be
corresponding page class
Page class will find the WebElements of that web page and also contains Page
methods which perform operations on those WebElements
Advantages of POM
In Page Object Model, operations and flows in the UI is separated from verification
This concept makes our code cleaner and easy to understand
Object repository is independent of testcases, so we can use the same object
repository for a different purpose with different tools
We can integrate POM with TestNG/JUnit for functional testing and at the same time
with JBehave/Cucumber for acceptance testing
Code becomes less and gets optimized because of the reusable page methods in the
POM classes.
Me
Methods get more realistic names which can be easily mapped with the operation
happening in UI
POM Structure
Configuration
Contain configuration parameters like browser name, applicaiton url etc
Driver class will have main method which calls various methods from specs
Common
Contain common methods
Specs
Contain methods which operate on UI elements
Pages
Will maintain object repository of all objects on respective Web Pages of AUT
Test data
Will contain all test data sheets to be used
pacakge-POM.TESTDATA
inside New file loginData.csv
enter Admin and admin123