FrameWork Features:
1)reusability of the Code
2)Maintenance of code is very eay
3)It provides the Reports
4)It provides the logs and screenshots
5)any non technical/novice resources can understand the code easily
Differenet FrameWorks:
1)DataDriven Framework
2)keyword driven framework
3)Hybrid Framework
4)BDD
What is the difference in keyword driven vs data driven vs behavior driven frameworks?
Keyword-Driven Testing Framework:
- Focus: Keyword-driven testing, also known as table-driven testing, focuses on separating test automation logic from test data and test scripts.
- Components:
- Keywords: Actions or operations that represent test steps (e.g., "click," "type," "verify").
- Test Data: Input and expected output data.
- Test Scripts: A set of instructions that use keywords and test data to execute test cases.
- Advantages:
- Promotes reusability of keywords.
- Easy to maintain as test data and logic are separated.
- Non-technical team members can write and understand test cases.
- Example: A keyword-driven framework might have keywords like "login," "search," and "add to cart," which are combined with test data to create test scripts.
Data-Driven Testing Framework:
- Focus: Data-driven testing focuses on testing the same functionality with multiple sets of data to ensure the application behaves correctly across various inputs.
- Components:
- Test Data: Multiple sets of input and expected output data.
- Test Scripts: A single set of test scripts that can iterate over different sets of test data.
- Advantages:
- Efficient for testing multiple scenarios with minimal test script duplication.
- Easily extends test coverage by adding new data sets.
- Example: In a data-driven framework, you might have a single login test script that is executed with different username and password combinations from a data source (e.g., spreadsheet or database).
Behavior-Driven Testing Framework (BDD):
- Focus: Behavior-driven testing focuses on describing the expected behavior of an application in natural language terms, making it more accessible to non-technical stakeholders.
- Components:
- Feature Files: Text files written in a structured language (e.g., Gherkin) that describe features, scenarios, and steps.
- Step Definitions: Code that maps the steps in feature files to automation logic.
- Advantages:
- Encourages collaboration between technical and non-technical team members.
- Provides a clear understanding of the expected behavior of the application.
- Promotes test automation using a human-readable format.
- Example: In a BDD framework, you might have a feature file that describes a user registration feature with scenarios like "Register with valid credentials" and "Register with invalid credentials."
In summary, these testing frameworks differ in their approach and focus:
- Keyword-Driven Framework focuses on reusability and separating test logic from data.
- Data-Driven Framework focuses on testing the same functionality with different sets of data.
- Behavior-Driven Framework (BDD) focuses on describing expected behavior using natural language and encourages collaboration between technical and non-technical team members.
The choice of framework depends on your project's requirements, the team's expertise, and the level of collaboration needed between technical and non-technical stakeholders. Some projects may even combine elements from multiple frameworks to create a custom solution that best fits their needs.
HybridFramework:
It is combination of TestNG+Datadriven/KeywordDriven and Page Object Model Design Pattern.
TestNg is used to design the TestCases
Datadriven is used to test the same scenario with multiple sets of data
POM: how you we can design our page Elements/Objects
What is Page Object Model in Selenium?
Page Object Model, also known as POM, is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and improves test case maintenance.
In Page Object Model, consider each web page of an application as a class file. Each class file will contain only corresponding web page elements. Using these elements, testers can perform operations on the website under test
Advantages of Page Object Model- Helps with easy maintenance: POM is useful when there is a change in a UI element or there is a change in an action. An example would be: a drop-down menu is changed to a radio button. In this case, POM helps to identify the page or screen to be modified. As every screen will have different java files, this identification is necessary to make the required changes in the right files. This makes test cases easy to maintain and reduces errors.
- Helps with reusing code: As already discussed, all screens are independent. By using POM, one can use the test code for one screen, and reuse it in another test case. There is no need to rewrite code, thus saving time and effort.
- Readability and Reliability of scripts: When all screens have independent java files, one can easily identify actions that will be performed on a particular screen by navigating through the java file. If a change must be made to a certain section of code, it can be efficiently done without affecting other files.
Implementing POM in Selenium Project
1)Plain page object model
public static final By elementname=By.locator("locator");
Respective methods developed for above elements like doing actions on the elements, verifying whether that element is present in that page or not, page title is present or not. This is all developed using webdriver methods
to do action you have to write syntax :
public void clickElement(){
driver.findElement(elementname).click();
}
2)Using PageFactory class
What is Page Factory in Selenium?
Page Factory is a class provided by Selenium WebDriver to support Page Object Design patterns. In Page Factory, testers use @FindBy annotation. The initElements method is used to initialize web elements.
- @FindBy: An annotation used in Page Factory to locate and declare web elements using different locators. Below is an example of declaring an element using @FindBy
@FindBy(id="elementId") WebElement element;
Similarly, one can use @FindBy with different location strategies to find web elements and perform actions on them. Below are locators that can be used:
- ClassName
- CSS
- Name
- Xpath
- TagName
- LinkText
- PartialLinkText
- initElements(): initElements is a static method in Page Factory class. Using the initElements method, one can initialize all the web elements located by @FindBy annotation.
- lazy initialization: AjaxElementLocatorFactory is a lazy load concept in Page Factory. This is used to identify web elements only when they are used in any operation or activity. The timeout of a web element can be assigned to the object class with the help of the AjaxElementLocatorFactory.
//create a Constructor
public classname(){
PageFactory.initElements(driver,this);
}
@FindBy(locator="locatorvalue")
private WebElement elementName;
@FindBy(locator="locatorvalue")
private WebElement elementName;
@FindBy(locator="locatorvalue")
private WebElement elementName;
Respective methods developed for above elements like doing actions on the elements, verifying whether that element is present in that page or not, page title is present or not. This is all developed using webdriver methods
public void clickElement(){
elementName.click();
}
=====================================================================
PageFactory is an inbuilt POM concept in Selenium WebDriver, used for initialising Page objects or instantiating the Page object itself without using “FindElement" or "FindElements"
1) It uses annotations @FindBy to find WebElement, with attributes like tagName, partialLinkText, name, linkText, id, css, className, XPath.
2) "initElements()" is a method provided by the Page Factory class to initialize elements defined in a Page Object.
The initElements() method takes two parameters: a WebDriver instance and a Page Object instance. It scans the Page Object for any fields that are annotated with the @FindBy annotation and initializes them.
3) "@CacheLookUp" The end goal of this annotation is to make the code execute faster. It’s used mostly for WebElements in a test case. For the specific element, it keeps the WebElement in the cache memory after the first time it’s run.
Page Object Model:
Page Object Model (POM)
POM is a design pattern creating an Object Repository for web UI elements, aiming to reduce code duplication and improve test maintenance.
Each web page has a corresponding Page Class containing methods that perform operations on WebElements.
POM separates operations and flows in the UI from validation, making the code cleaner and more understandable.
It supports the reuse of page methods and gives methods realistic names for easy mapping with UI operations.
Why Not to use Page Factory?
(Refer this KeyNote from Selenium Team for its limitations: https://lnkd.in/gGsh3pgE)
1) The @CacheLookup annotation in PageFactory, intended for caching elements, can lead to StaleElementException If the DOM changes, it makes the element stale.
2) PageFactory is considered a “cumbersome and problematic implementation” with no significant benefits over direct runtime code element finding.
onFinish(ITestContext context) Invoked after all the tests have run and all their Configuration methods have been called. | |
void | onStart(ITestContext context) Invoked after the test class is instantiated and before any configuration method is called. |
void | onTestFailedButWithinSuccessPercentage(ITestResult result) Invoked each time a method fails but has been annotated with successPercentage and this failure still keeps it within the success percentage requested. |
void | onTestFailure(ITestResult result) Invoked each time a test fails. |
void | onTestSkipped(ITestResult result) Invoked each time a test is skipped. |
void | onTestStart(ITestResult result) Invoked each time before a test will be invoked. |
void | onTestSuccess(ITestResult result) Invoked each time a test succeeds. |
JetBrains Aqua – An IDE for Writing Tests You Can Be Proud Of.
Why do you need Aqua?
Designed for test automation
Aqua is the first JetBrains IDE created specifically for test automation. It's an all-in-one workspace that will help you boost your quality engineering productivity.
Web Inspector
The embedded Web Inspector allows you to view web applications in Aqua and capture any page elements required for automated tests. Working like a built-in browser, the Web Inspector lets you stay inside the IDE without switching to another tool.
Aqua’s embedded Web Inspector generates a unique CSS or XPath locator for a selected element on a web page and adds it to the source code. When Web Inspector is active, CSS and XPath code completion suggests and highlights locators for the most important web page elements.
Support for popular testing frameworks
Aqua supports the Selenium, Cypress, and Playwright testing frameworks, enabling you to create and run automated UI tests using your preferred tools. With JetBrains Aqua, you can write, run, and debug unit tests using JUnit, pytest, Jest, and other tools.
Comprehensive feature set
Aqua boasts a rich feature set with our HTTP Client for API testing, support for popular databases, and integration for Docker and version control. This feature set is available out of the box.
Support for multiple languages
Aqua is an IDE that understands Java, Python, JavaScript, TypeScript, Kotlin, and SQL. Just like any other JetBrains IDE, Aqua has powerful code completion and refactoring capabilities, helpful on-the-fly inspections, and a user-friendly debugger and test runner.
Modern UI
A modern and intuitive user interface makes it easy for both beginners and experienced professionals to get started with Aqua
==============================================================Select Maven – Maven Project as below :
Different Ways to run Framework Tests:
1)Run tests through testNG.xml
java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException #295
java.lang.Error: Unresolved compilation problem: VERSION_2_3_29 cannot be resolved or is not a field #110
The isTraceEnabled()
method has been added to log4j 1.2.12, according to the Javadoc:
https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Logger.html#isTraceEnabled()
If you're using log4j (also if this is a transitive dependency on your project setup), please ensure that you take the latest version of log4j
Related link:https://github.com/jOOQ/jOOQ/issues/2085
2)Run tests through pom.xml
3)Run tests through command prompt
4)Run tests through batch file
5)Run tests through Jenkins CI tool
- Advantages of Jenkins include:
- It is an open source tool with great community support.
- It is easy to install.
- It has 1000+ plugins to ease your work. If a plugin does not exist, you can code it and share with the community.
- It is built with Java and hence, it is portable to all the major platforms.
- Anthill
- Bamboo
- Cruise Control
- Team City
STEP6)after setting username and password then login to jenkins
Click on Save and Apply buttons.
----------------------------------------------
12)give Root pom from github like below
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.