Selenium Notes
Selenium Notes
>>isMultiple(): boolean
>>getOptions(): list<WebElement>
if (allOptions.get(i).get(i).getText().equals("misalpaav"))
Thread.sleep(2000);
allOptions.get(i).click();
break;
>>getAllSelectedOptions():
>>getFirstSelectedOption():
>>getWrappedElement():
It is used to get all the options from dropdown by considering as a single webelement
ACTIONS CLASS:
Actions class has total 21 method but we use only the methods that are used commonly required
PERFORM:
BUILD:
driver.get ScreenshotAs();
TakeScreenShot ts =( TakeScreenShot)driver;
ts.ScreenshotAs();
JAVASCRIPT EXECUTOR
-Javascript executor is used to handle scrolling options such as scroll down, scroll up, scroll right,
scroll left as well as it is used to handle disable webelement, hidden webelement, generate a alert
pop up
-IT IS A INTERFACE
-It has two method
1. executeScript()
2. executeAsynScript()
-to call the method of java script executor we do explicit typecasting into java script executor
25/08/23
jse.executeAsyncScript("arguments[0].scrollIntoView(false)",newsElement);
27/08/23
FRAME :
if frame is not present in main page and we try to handle frame then we get NoSuchFrameException
driver.switchTo().defaultContent();
driver.switchTo().parentPage();
28/08/23
getWindowHandle()
getWindowHandles():
it is used to get the address of parent as well as child browser and window.
QUE.
29/08/23
POP UP HANDLING
Types of pop up :
1. script pop up
- Alert
- Confirmation
2. Hidden division pop up
3. Notification pop up
1. print pop up
2. file upload pop up
3. Download pop up
1] SCRIPT POP UP
it is not inspectable
it is colorless
it is not movable
al .dismiss();
al .getText();
al .sendKeys();
It is not movable
It is colorless
It is not inspectable
We use switchT0();
al.accept();
al .dismiss();
al .getText();
It is not movable
It is colorful
It can be inspectable
It is colorless
It is not movable
It is not inspectable
that means if the pop up is there in Chrome or Firefox or Edge we need to create object of the
options class according to browsers.
Co.addArguments(“—disable-notifications”);
Co.addArguments(“—disable-notifications”);
1/09/23
AUTOMATION FRAMEWORK
Automation framework is a set of rules and guidelines, files and folders, (standard folder templates)
That has to be followed by every automation test engineer to automate application.
OR
automation framework is collection of generic reusable methods which makes automation test
engineer life easy and achieve code efficiency
Types of framework
TestNG
Storing the test data into external files such as excel , xml, .csv, property and data base ,fetch that
data through the generic reusable method and test the application is known as data driven
framework.
Why Data-Driven???
As a part of functional testing, we test each and every component of the
application with both valid and invalid data...
And since there will be many components, the test data is huge...
And if we hard-code test data then code size will be more...
Also difficult to maintain the test data...
Hence we keep it in external files and fetch them from there...
Why we prefer to store test data in Excel ???
1. Maintaining the test data in Excel is very Easy
(Adding, Modifying and deleting)
2. ALready Manual Test Engineers would have used excel to store
test data, So we just write generic reusable codes to fetch them.
Create a folder called 'data' under the project and create an excel under data folder
Right click on Project-->New-->Folder(name as 'data')
Right click on data folder-->Properties-->copy path-->open window explorer-->
paste it in the address bar...
Right click inside folder-->New-->Excel Sheet(name as inputData)
To read multiple data, use loop to get data one after another
2] KeywordDriven Framework
Storing the test data which is commonly or frequently used, as key-value pair
and reading it by using generic reusable method is known as KeywordDriven Framework
Here we store test data which we use very frequently like browserName,
url, valid username and password to login etc, in every test case
as key-value pair in property file and We use a java class called
'Properties' class and its method called getProperty to get the data.
getProperty() takes key as argument and returns its corresponding value
key value
browser Chrome
url https://www.actitime.com
username admin
password manager
StaleElementReferenceException
What is StaleElementReferenceException???
The Reference or Address of the element is old...
Modular Framework:
For each and every module in the application we create a separate package
in the framework and we write all the test scripts related to
that module inside that package.
TimeTrack com.actitime.timeTrack
Tasks com.actitime.tasks
Reports com.actitime.reports
Users com.actitime.users
Settings com.actitime.settings
There are few things which will never change throughout the whole project.
Such Constants I have stored inside IAutoConsts interface.
e.g., path of excel file and property file, key and value of the driver
executable files.
There are few things which are repeated like open browser, enter url,
verify loginPage and closeBrowser etc
These repeated actions I am storing inside a common class for all the
test scripts called as BaseTest, and I ensure that all the test scripts
extends this BaseTest.(Inheriting common properties from same place)
All the elements on the webpage are stored in one place called object repo(POM)
wherein we declare, initialize and utilize the elements by writing public getters
setters and action methods.
In test scripts, we just call generic methods, getters, setters, action methods and
execute the automation scripts through these methods.(Test scripts become light weight)
Since We need to run all my scripts with one click We converted all the test scripts into
test suite(Batch executor) and run the suite.(testNG.xml file)
Also here since we are hiding the functionality but just providing the
public getters and setters, hence we use abstraction concept
Polymorphism: While selecting the browser, in the BaseTest, we provide if-else condition
wherein depending upon the browser value it decides whether to
load ChromeDriver Object or FirefoxDriver object into the same reference
variable called driver.
Interface: In my framework, there were few things which were never changing like
key and value of the driver exe files and excel path and property path
To indicate these are constants, We have created an interface and
stored it inside it
Method Overloading: In WebDriverCommonLib Class, we write overloaded methods for
selecting an option from the dropdown
Abstract Class: In BaseTest Class, though we have two methods, openBrowser() and
closeBrowser()[tearDown()] but they cannot run independently...
They are dependent on @Test methods for execution.
Since they cant run independently to denote that no automation engineer
should run BaseTest Class, We made BaseTest class as abstract class
Array: To store the data in databanks we create an object of two dimensional array
in DataProvider concept...
In BaseTest, once we declare driver as WebDriver and make sure every test script
inherits and understands this declaration from BaseTest
Hence to access it everywhere, we declare as public.
To load this declaration first, before every other class wants to access it
we make it as static.
TestNG (7.8 version)
testNG is used to cover wider range of testing categories such as unit testing, functionality testing,
integration testing and end to end testing.
Package: testNGPackage
@TestNG
TestNG
indexNG class most of the time we use reporter.log(String args, Boolean args); as a printing
statement.
After refreshing the project we will get folder i.e test-output which contains testNG reports in
format of emailable-report.html and index.html
2]execution in testNG
Select the testNG classes for which parallel execution is going to perform. Convert that classes into
testNG.xml suite file by selecting a parallel mode as classes/ test/methods.
Execute that testNG.xml suite file as a testNG suite so all the classes or tests / methods / started
executing at a same time.
By using parallel execution we execute multiple test cases at a same time and save the time of
execution also.
4]Q. with the help of testNG we can execute failed test Cases ?
-in a execution of testNG class or testNG.xml file if any method or test case got failed we can easily
track and execute that particular failed method or test case.
-for that we need to refresh the test output folder which has TestNG-failed.xml file
-if we execute that file as testNG suite it will execute only failed test case or method.
We can achieve parameterization for TestNG classes through the TestNG.xml suite file
For that in TestNG.xml file for that we must declare parameter tag with name and value attribute
Ex. <suite>
<test>
To read that parameter into testNG class we must need to use @parameters annotation followed by
a @test annotation.
Ex. @parameters(“browser”)
@test
P v method(String browser)
6] testNG provides annotations annotations are used to control the flow of methods
*sequence of annotations(imp)
5 @Test
4 BeforeMethod 6 AfterMethod
3 BeforeClass 7 AfterClass
2 BeforeTest 8 AfterTest
1 BeforeSuite 9 AfterSuite
@Test2
@Test 1
4 BeforeMethod 7 6 AfterMethod
3 BeforeClass AfterClass 10
2 BeforeTest AfterTest 11
1 BeforeSuite AfterSuite 12
7] testNG provides flags
Flags are used to control the flow of annotations or used along with the annotations
DESCRIPTION :
It is used to describe the annotation or method. It is asking for string values default values is empty
Q. How to use ?
> @Test(description = “Performs Login”)
P v method1()
ENABLED :
It is used to make the annotations or method as enables or disabled
It is asking for Boolean values
Default value is true
If the values is true that means test case is enabled and if it is false then it is disabled
Q. HOW TO USE ?
@Test (description =”perform login”,enabled =true)
P v method1()
{
}
@Test (description =”perform login”,enabled =false)
P v method2()
{
}
INVOCATION :
It is used to execute annotation or method for multiple time.
It acts like for loop.
It is asking for integers value
Default count of invocation is 1
PRIORITY :
It is used to execute the test case and annotations according to the priority given
It is asking for integer values
Default values is 0
Lesser priority higher execution
Same priority methods always be executing in alphabetical orders
Always negative priority will execute first if it is declared
DEPENDSONMETHOD :
It is used to make the methods depends on each other
It is asking for string[] array values.
Default value is empty
ALWAYSRUN : FLAG NO 7
It is used to execute the method even if any previous method is failed or that are depend on each
other.
It acts like finally block of java
That means we use this flag along with methods that are important
It is asking for Boolean values default value is false
BaseTest (class)
@BeforeMethod
SetUp()
Screenshot_of_failedmethod()
@AfterMethod
tearDown()
____________________________________________________________________
CustomListener extends BaseTest implements ITestListener
____________________________________________________________________
@Listener(CustomListener.class)
TestCase extends BaseTest
10*] TestNG provides data provider annotations which is used to achieve data driver approach.