Framework and Selenium
Framework and Selenium
1. Test Data
a. We read test data from Excel . For Excel we would be using Apache Poi.
i. Apache Poi Link,
ii. Reading Data from DataProvider
b. We also read the data from config. Properties (Data would be like url, browser,
timeouts etc). We we will calling Properties class and File Input Stream
i. Properties p = new Properties();
ii. FileInputStream file = new FileInputStream(Path of config )
iii. p.load(file);
iv. p.getProperty(“url”);
2. Reporter
a. We Use Extent report – Avent stack
1. Extent reports have 3 classes
a. ExtentHtmlReporter(creates rich standalone HTML File)
b. ExtentReports class(Where we need to store the reports)
c. ExtentTestClass(We can generate log in the report)
i. Methods are
1. StartTest(these method are to execute
precondition and postcondition of a
testcase)
2. EndTest
3. Log(logging status in HTML Report)
4. Flush(erase any previous Data and create a
new report)
ii. Generate Beautiful HTMLReports
iii. Capture logs
iv. We capture failed screenshots as well.
3. Utilities – Utility link
a. Which are going to have common methods like navigatetoURL() ,
NavigateBack(),GetPageTitle(), Get CurrentUrl(),getElement(), GetText(),
TotalCount(), ScrolltoElement(),SendKeys(),WaitforElement(),
sleep(),SelectIfOptionTextEquals(), getDropdownValues() etc
4. Base Class - Baseclasslink
a. Base class is the main class which takes care of Browser setup, loading configuration
file and other reusable methods like screenshot, handling sync issues and many
more. With base class you can avoid code duplication and can reuse the code as
much you want
5. Unit Testing Framework – Testng
a. (testing.xml – we can run the testcases from testing.xml)
b. We use testng for grouping , parallel, dataprovider,Parameters, iretry analyzer.
c. Listeners and Interface – Listener is nothing but its implements the interface, listen
to action of selenium and behaves accordingly.
i. Webdriver Listener
ii. TestNG Listner
1. Ireporter(Emailable reporter and failed reports)
2. ITestListener(Used in extent reports for attaching screenshots based
on failure)
3. etc
6. Testscripts (inside a class we have @Test Method)
7. Design Pattern
a. Page Object Model
i. We have maintained the class for every WebPage . so there are going to be
methods and locator inside it.
8. Build Tool
a. Maven
i. To run test we give mvn test
9. CI/CD – Jenkins
a. We execute the daily based testcase and nightly run based on the schedule
b. Jenkins once test execution is complete it will shared to team members
10. Version Control
a. Git -> To store our testcsript and access across the team
BDD Framework
In behavioral driven framework we use cucumber tool in that we use gherkin language it has 200
languages in that we use simple English so that non-technical persons can also read and understand
the test cases.
Feature file
In feature file we are going to write the test cases like summary that we are going to execute.
Background:
The Common steps in Scenario can be taken and placed under Background.
When there are multiple Scenario , by that time I will first execute the background then followed by
the first scenario then again the background then the second scenario.
Scenario
Examples:
|user|
|Admin|
|Non Admin|
@TestRunner
Test runner is the main class in cucumber. There are two annotations
1.@Runwith(cucumber.class)
2.@cucumberoptions
@cucumber options there are different properties
Feature – In feature we are going to give the path of the feature file.
Glue – In glue we give the package name of stepdefinition.
Tag – Tag is used to run the particular test cases.
Plugin – is used to generate reports.
Monochrome – It is used to remove the unwanted characters from console.
Dryrun – is used to generate snippets.
Format – Format is used to generate reports in what format we want.
StepDefinition
In stepdefinition package we are going to create a class and we will write the snippets.
Page Object
We have maintained the class for every WebPage. so there are going to be methods and locator
inside it.
App module
Then we will call the class name and method (that contains locators and actions) in the
stepdefinition and run the test cases in feature file.
Page factory
PROPERTIES
WEBDRIVER
System.setProperty (“WebDriver.Chrome.Driver”,p.getProperty(“chromepath”));
Webdriver driver = new ChromeDriver();
(OR)
System.setProperty (“WebDriver.Chrome.Driver”,”path of the browser/chromedriver.exe”);
Webdriver driver = new ChromeDriver();
SCREENSHOT
SELECT
WebElement a = driver.findelements(By.id(“yearbox”));
Select select = new Select(a);
select.selectbyindex(25);
select.selectbyvalue(“August”);
select.selectbyvisibletext(“1998”);
JavaScriptExecuter js = (JavaScriptExecuter)driver;
Js.ExecuteScript(“window.scrollBy(0, document.body.scrollHeight)”); BOTTOM
Js.ExecuteScript(“window.scrollBy(0, -document.body.scrollHeight)”); TOP
PARTICULAR ELEMENT
WebElement a = driver.findelement(By.xpath(“//”);
Js.ExecuteScript(“Arguments[0].scrollintoView();”,a);
FRAME
MOUSE OPERATIONS
driver.close();
driver.quit();
driver.switchto().newWindow(windowType.WINDOW);
driver.switchto().newWindow(windowType.TAB);
ALERT
WINDOWS HANDLING
(WINDOW HANDLE)
String pid = driver.getWindowHandle();
System.out.println(“parentid”+pid);
(WINDOW HANDLES)
Set <String> allid = driver.getWindowHandles();
System.out.println(“allid”+allid);
(ITERATOR)
Iterator<String> i = allid.iterator();
System.out.println(i);
(ITERATOR-LOOP)…
While(i.hasNext()) {
String x = i.next();
If(!pid.equals(x)){
Driver.switchto().window(x);
System.out.println(“After Switching”+ driver.getTitle());
}
}
driver.switchto().window(pid);
System.out.println(“after switching to parent”+driver.getTitle());
driver.manage().window().Maximize();
driver.manage().window().Minimize();
TO SLEEP BROWSER
Thread.sleep(mills:5000);
TITLE,TEXT,CURRENT URL,URL
driver.getTiltle();
driver.getText();
driver.getcurrentUrl();
driver.get(“https://www.google.com”);
WEB TABLE
WAITS
IMPLICIT WAIT
EXPLICIT WAIT
FLUENT WAIT
SQL
Collections
Exceptions