SlideShare una empresa de Scribd logo
1 de 15
Test Automation Services | Test Automation Framework
https://afourtech.com/
UI Automation Testing using Playwright with Java –
Afour Tech
A few common challenges with UI automation that increase maintenance and project cost are:
1. UI change, i.e., change in locators, e.g., Xpath, CSS
2. Flakiness due to loading issues
3. Cross-browser compatibility and maintenance
4. Debugging challenges
At AFour Technologies, we continuously try to address these issues by exploring new tools and
innovating/creating customized features that help customers build robust solutions and reduce
overall costs.
In this blog, we will explore Playwright to see how UI automation testing can be done using
Playwright with Java and handle a few of these common challenges.
Test Automation Services | Test Automation Framework
https://afourtech.com/
Introduction to Playwright
The Playwright is an open-source test automation library that Microsoft initially developed.
It supports multiple browsers like Chromium, Firefox, and Web Kit. It supports multiple languages
like Typescript, JavaScript, Java, Python, .Net, C#, and multiple platforms like Windows, Linux, Mac
OS, Android, and iOS.
Playwright aims to provide fast, reliable, user-friendly automation capabilities for web application
testing. It offers a wide range of features that make it useful for various tasks.
There are three main components of a playwright:
1. The browser driver—It controls the browser engine and executes commands from the
playwright API.
2. The browser context—Represents a single instance of a browser with its own cookies, cache, and
other settings. Playwright supports multiple browser contexts within the same browser instance,
which can be used for separate sets of tests or scenarios, and each browser context has its own set of
pages.
3. The page—Represents a single web page within a browser context with its own DOM tree, frame
hierarchy, and other content.
Example test:
Test Automation Services | Test Automation Framework
https://afourtech.com/
When writing tests with Playwright, it offers “assertThat” overloads that intelligently wait until the
expected condition is met.
There is a list of assertions such as:
.isChecked(), .isEnabled(), .isDisabled(), .isEditable(), .isVisible() & many more are there.
Locators are crucial in Playwright’s auto-waiting and retry mechanism, enabling efficient element
identification on web pages. They provide a means to locate elements and perform various actions
like click(), fill(), and many more. Additionally, Playwright allows creation of custom Locators using
the “page.locator()” method.
Also, Playwright provides multiple actions, for example ->
– To input text it provides fill() method,
– For checkboxes and radio buttons, it provides setChecked(),
– For selecting one or multiple options, it has selectOptions(),
– For clicking it has click(), dblClick() methods,
– It provides a method called type() which enters string character by character, and many more are
there.
Playwright offers several features that
make it an excellent choice for UI
automation testing
A. Auto-waiting:
Playwright performs thorough checks on elements to ensure that actions behave as expected. It
automatically waits for all necessary conditions to be met before executing the requested action. The
action fails if the required conditions are not met within the specified timeout. This approach
Test Automation Services | Test Automation Framework
https://afourtech.com/
guarantees that actions are performed at the right time, enhancing the reliability and accuracy of UI
automation.
For example: If we want to perform a click() action on an element, then Playwright ensures that
1. Is an element attached to the DOM or not
2. Element is visible or not
3. Is it stable or not
4. It is enabled, and it receives events or not
And after performing all required checks, it performs the click action.
B. Headless and Non-headless mode:
Run your automated tests in headless mode or non-headless mode.
C. Debugging Tests:
Test Automation Services | Test Automation Framework
https://afourtech.com/
The Playwright Inspector is a graphical user interface (GUI) tool that facilitates debugging your
Playwright tests. It allows you to live-edit locators, pick locators, and view logs. Additionally, you can
utilize the “page. pause()” method to debug your test cases effectively. This approach eliminates the
need to manually navigate through each test action to reach the desired debugging point,
streamlining the debugging process.
D. Test Generator:
Playwright includes a powerful test generation feature that allows you to perform actions in the
browser. Playwright figures out the best locator on the page; for that, it prioritizes role, text, and
testID locators.
If the element generator discovers multiple elements that match the same locator, it enhances the
locator to ensure uniqueness, enabling us to identify each component accurately.
Command:
mvn exec: Java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=” codegen demo.
Playwright.dev/todomvc”
Test Automation Services | Test Automation Framework
https://afourtech.com/
When running the Codegen command, two windows will open a browser window to interact with the
page element and a playwright inspector to record a test.
E. Emulation:
We can use a test generator to generate tests using emulation so that we can generate a test for a
specific viewport size, specific device, or specific color scheme; also, we can emulate geolocation,
language, or timeZone.
First, let’s see emulate viewport size:
Playwright allows you to open a browser window with a specific width and height using the
“viewport” option. This feature enables you to generate tests with different viewport sizes, providing
flexibility in emulating various screen resolutions and responsive designs.
Command:
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=”codegen—
viewport-size=800,600 playwright.dev”
Test Automation Services | Test Automation Framework
https://afourtech.com/
Emulate Device:
We can use the command mentioned below:
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=’codegen—
device=”iPhone 13″ playwright.dev’
We can use the —device option in the command, which sets the viewport size and user agent.
We can also write a script for this:
Playwright provides a helpful feature to emulate different devices and their characteristics, allowing
you to test your web application’s behavior on various devices without needing the physical device.
You can use the “setViewportSize” and “setUserAgent” methods to emulate the device properties.
Here’s an example:
F. Intercepting Network request
Playwright offers a powerful feature that enables us to modify seamlessly or block network requests
initiated by a web page. This can be useful for testing purposes like simulating slow network
conditions, mocking server responses, or testing the web application’s behavior under specific
conditions.
Test Automation Services | Test Automation Framework
https://afourtech.com/
Example:
So, in this example, we are setting up a network route for the requested URL. The lambda expression
is called when a matching request is made. We are setting custom messages, status codes, content
type, and body as our custom messages.
Because we have set up a network route for the URL, our custom response will be returned instead of
the regular page content, as shown below:
Test Automation Services | Test Automation Framework
https://afourtech.com/
G. Accessibility Testing
Accessibility testing is essential to ensuring that a web application is usable for all users, including
those with disabilities. Playwright provides built-in support for performing accessibility testing.
H. Authentication
Playwright provides an isolated environment called the browser context for executing tests. This
allows tests to load an existing authenticated state, eliminating the need to log in for each test. By
saving the authentication state in the context, it can be reused across all tests. This approach saves
time by avoiding redundant login operations and ensures complete isolation between independent
tests.
I. Downloads
With Playwright’s downloads feature, you can automate downloading files from a website. This
feature helps test scenarios that involve verifying the correct download of files or automating tasks
Test Automation Services | Test Automation Framework
https://afourtech.com/
that involve downloading files. Furthermore, Playwright allows you to customize the behavior of the
downloads feature by specifying the download path or filtering the types of files that can be
downloaded.
J. Trace Viewer
The Playwright trace viewer is a tool that allows you to analyze and visualize the recorded trace data
of a browser’s actions during test execution. Let’s see some options that provide detailed insights
into the sequence of events, network requests, and other relevant information.
Command:
mvn exec: Java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=” show-trace”
Actions:
Test Automation Services | Test Automation Framework
https://afourtech.com/
Once the trace is opened in the Playwright trace viewer, you will find a list of actions that the
Playwright performed on the left-hand side. Selecting each action from the list allows you to explore
detailed information such as the action snapshot, action log, network log, and more.
Metadata:
The Playwright trace viewer offers comprehensive information, including the timing of actions, the
browser engine utilized, viewport details, mobile device emulation, and the count of recorded pages,
actions, and events.
Screenshots:
Each trace records a screenshot and renders it as a film strip. This film strip provides a visual
representation of the recorded actions and states. Hovering over each frame in the film strip lets you
Test Automation Services | Test Automation Framework
https://afourtech.com/
view a magnified image corresponding to a specific action or state, allowing for detailed inspection
and analysis.
Call:
The call option includes details such as the action name, the timestamp when it was called, the
duration of the action’s execution, the parameters passed to the action, the return value, and any
associated log messages.
Console:
The Playwright’s trace viewer Console panel offers a view of the console output generated during the
recorded actions. It allows you to observe console logs, errors, warnings, and other relevant
messages produced during the test case execution.
Network:
Test Automation Services | Test Automation Framework
https://afourtech.com/
It provides a view of all network requests made by the browser, along with their corresponding
responses, headers, timings, and other relevant information.
Selenium And Playwright
Both are popular choices for web automation testing. There are some key differences.
A. Architecture:
In Selenium, each command is transmitted as an HTTP request, and the corresponding JSON
response is received. Every action, such as launching the browser, clicking an element, or entering
text into a textbox, is transmitted as a specific HTTP request. This approach results in the termination
of the connection between the server and client, which needs to be re-established for the
subsequent request.
Connection termination after each request can lead to slower execution, which also introduces a
layer of flakiness.
On the other hand, Playwright utilizes a single web socket connection to handle all requests during
the test execution. This architectural approach minimizes potential points of failure and enables
commands to be transmitted smoothly over a single connection. This makes Playwright a more
stable tool as compared to Selenium.
B. Speed:
Test Automation Services | Test Automation Framework
https://afourtech.com/
The Playwright is faster than Selenium when it comes to executing tests due to its architecture.
C. Flakiness:
Playwright is designed to be less flaky than Selenium again, thanks to its architecture that isolates
each test in a separate browser context. This means that tests do not interface, reducing the chances
of flakiness.
D. Cross-browser consistency:
Playwright is designed to provide a consistent API across multiple browsers, ensuring that the test
can be written once and run across different browsers. Selenium requires browser-specific drivers,
which may cause inconsistencies in behaviour and functionality across different browsers.
E. Debugging:
Both Selenium and Playwright provide good debugging capabilities, but Playwright offers additional
features that make debugging easier. Playwright provides an interactive mode that allows you to
interact with the browser as the test is running, which helps you to identify issues more quickly.
F. Testing framework:
Selenium and Playwright can be used with testing frameworks like Jest, Mocha, and Jasmine.
However, Playwright has its test runner, making it easier to start with testing without learning a
separate framework.
Conclusion:
In conclusion, Playwright, combined with Java, provides a robust and up-to-date solution for UI
automation. Its unified API, ability to work across different browsers, and wide range of features
Test Automation Services | Test Automation Framework
https://afourtech.com/
streamline the automation process and improve testing efficiency. As a result, it is a popular choice
for Test Automation Services and is often used as a foundation for Test Automation Framework.
The architecture of Playwright, which utilizes browser-specific binaries and maintains persistent web
socket connections, guarantees stability and reliability throughout test execution.
For detailed information and additional examples, please refer to the links in the references section.
About AfourTech
AFour is ideation and technology house. Product companies associate with AFour for its product
conceptualization and technology skills in wide range of technologies like Java, Python, .NET,
Javascript (MEAN), LAMP (Perl and PHP), Angular, React, C++.
The company is a hub of every cutting-edge technology in software product engineering services ─
Hyper-convergence, SDN, Virtualization, Next Generation Data Center Technologies, Networking,
Enterprise Mobility.
Till date, AFour Technologies has been able to bring together some of the best and brightest minds
in software engineering.

Más contenido relacionado

Similar a UI Automation Testing using Playwright with.docx

Less12 3 e_loadmodule_2
Less12 3 e_loadmodule_2Less12 3 e_loadmodule_2
Less12 3 e_loadmodule_2Suresh Mishra
 
Silk Performer Presentation v1
Silk Performer Presentation v1Silk Performer Presentation v1
Silk Performer Presentation v1Sun Technlogies
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing ApproachHarshJ
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing ApproachHarshaVJoshi
 
Cross browser testing using BrowserStack
Cross browser testing using BrowserStack Cross browser testing using BrowserStack
Cross browser testing using BrowserStack RapidValue
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalorerajkamal560066
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsAbhijeet Vaikar
 
Software Testing includes Performance testing with Load Runner and the JMeter
Software Testing includes Performance testing with Load Runner and the JMeter Software Testing includes Performance testing with Load Runner and the JMeter
Software Testing includes Performance testing with Load Runner and the JMeter Hima Bindu Kosuru
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaUsing HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaSandeep Tol
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answersGaruda Trainings
 
Performance testing and j meter
Performance testing and j meterPerformance testing and j meter
Performance testing and j meterPurna Chandar
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applicationsqooxdoo
 
Lecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptxLecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptxBalkrishanpatidar
 
Performance testing with loadrunner by kc
Performance testing with loadrunner by kcPerformance testing with loadrunner by kc
Performance testing with loadrunner by kckrishna chaitanya
 

Similar a UI Automation Testing using Playwright with.docx (20)

Less12 3 e_loadmodule_2
Less12 3 e_loadmodule_2Less12 3 e_loadmodule_2
Less12 3 e_loadmodule_2
 
Silk Performer Presentation v1
Silk Performer Presentation v1Silk Performer Presentation v1
Silk Performer Presentation v1
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing Approach
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing Approach
 
Cross browser testing using BrowserStack
Cross browser testing using BrowserStack Cross browser testing using BrowserStack
Cross browser testing using BrowserStack
 
Browser_Stack_Intro
Browser_Stack_IntroBrowser_Stack_Intro
Browser_Stack_Intro
 
Wap Tpresentation
Wap TpresentationWap Tpresentation
Wap Tpresentation
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalore
 
JMeter_ Cubet Seminar ppt
JMeter_ Cubet Seminar pptJMeter_ Cubet Seminar ppt
JMeter_ Cubet Seminar ppt
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
 
Software Testing includes Performance testing with Load Runner and the JMeter
Software Testing includes Performance testing with Load Runner and the JMeter Software Testing includes Performance testing with Load Runner and the JMeter
Software Testing includes Performance testing with Load Runner and the JMeter
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaUsing HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in Java
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answers
 
White paper ready api
White paper  ready apiWhite paper  ready api
White paper ready api
 
Performance testing and j meter
Performance testing and j meterPerformance testing and j meter
Performance testing and j meter
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Lecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptxLecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptx
 
Performance testing with loadrunner by kc
Performance testing with loadrunner by kcPerformance testing with loadrunner by kc
Performance testing with loadrunner by kc
 

Más de Afour tech

Front end Development Services - AfourTech.pdf
Front end Development Services - AfourTech.pdfFront end Development Services - AfourTech.pdf
Front end Development Services - AfourTech.pdfAfour tech
 
Understanding the Importance of Security Testing in Safeguarding Your Digital...
Understanding the Importance of Security Testing in Safeguarding Your Digital...Understanding the Importance of Security Testing in Safeguarding Your Digital...
Understanding the Importance of Security Testing in Safeguarding Your Digital...Afour tech
 
TestOps and its Role in Software Quality Management - AfourTech USA.docx
TestOps and its Role in Software Quality Management - AfourTech USA.docxTestOps and its Role in Software Quality Management - AfourTech USA.docx
TestOps and its Role in Software Quality Management - AfourTech USA.docxAfour tech
 
Best Practices, Types, and Tools for Security Testing in 2023.docx
Best Practices, Types, and Tools for Security Testing in 2023.docxBest Practices, Types, and Tools for Security Testing in 2023.docx
Best Practices, Types, and Tools for Security Testing in 2023.docxAfour tech
 
Top 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docxTop 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docxAfour tech
 
10 Most Important Strategies for Cybersecurity Risk Mitigation.pdf
10 Most Important Strategies for Cybersecurity Risk Mitigation.pdf10 Most Important Strategies for Cybersecurity Risk Mitigation.pdf
10 Most Important Strategies for Cybersecurity Risk Mitigation.pdfAfour tech
 
Top 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docxTop 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docxAfour tech
 
Bouncing Back Is Important.docx
Bouncing Back Is Important.docxBouncing Back Is Important.docx
Bouncing Back Is Important.docxAfour tech
 

Más de Afour tech (8)

Front end Development Services - AfourTech.pdf
Front end Development Services - AfourTech.pdfFront end Development Services - AfourTech.pdf
Front end Development Services - AfourTech.pdf
 
Understanding the Importance of Security Testing in Safeguarding Your Digital...
Understanding the Importance of Security Testing in Safeguarding Your Digital...Understanding the Importance of Security Testing in Safeguarding Your Digital...
Understanding the Importance of Security Testing in Safeguarding Your Digital...
 
TestOps and its Role in Software Quality Management - AfourTech USA.docx
TestOps and its Role in Software Quality Management - AfourTech USA.docxTestOps and its Role in Software Quality Management - AfourTech USA.docx
TestOps and its Role in Software Quality Management - AfourTech USA.docx
 
Best Practices, Types, and Tools for Security Testing in 2023.docx
Best Practices, Types, and Tools for Security Testing in 2023.docxBest Practices, Types, and Tools for Security Testing in 2023.docx
Best Practices, Types, and Tools for Security Testing in 2023.docx
 
Top 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docxTop 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docx
 
10 Most Important Strategies for Cybersecurity Risk Mitigation.pdf
10 Most Important Strategies for Cybersecurity Risk Mitigation.pdf10 Most Important Strategies for Cybersecurity Risk Mitigation.pdf
10 Most Important Strategies for Cybersecurity Risk Mitigation.pdf
 
Top 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docxTop 7 Benefits of DevOps for Your Business.docx
Top 7 Benefits of DevOps for Your Business.docx
 
Bouncing Back Is Important.docx
Bouncing Back Is Important.docxBouncing Back Is Important.docx
Bouncing Back Is Important.docx
 

Último

DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Onlineanilsa9823
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Delhi Call girls
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 

Último (20)

DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 

UI Automation Testing using Playwright with.docx

  • 1. Test Automation Services | Test Automation Framework https://afourtech.com/ UI Automation Testing using Playwright with Java – Afour Tech A few common challenges with UI automation that increase maintenance and project cost are: 1. UI change, i.e., change in locators, e.g., Xpath, CSS 2. Flakiness due to loading issues 3. Cross-browser compatibility and maintenance 4. Debugging challenges At AFour Technologies, we continuously try to address these issues by exploring new tools and innovating/creating customized features that help customers build robust solutions and reduce overall costs. In this blog, we will explore Playwright to see how UI automation testing can be done using Playwright with Java and handle a few of these common challenges.
  • 2. Test Automation Services | Test Automation Framework https://afourtech.com/ Introduction to Playwright The Playwright is an open-source test automation library that Microsoft initially developed. It supports multiple browsers like Chromium, Firefox, and Web Kit. It supports multiple languages like Typescript, JavaScript, Java, Python, .Net, C#, and multiple platforms like Windows, Linux, Mac OS, Android, and iOS. Playwright aims to provide fast, reliable, user-friendly automation capabilities for web application testing. It offers a wide range of features that make it useful for various tasks. There are three main components of a playwright: 1. The browser driver—It controls the browser engine and executes commands from the playwright API. 2. The browser context—Represents a single instance of a browser with its own cookies, cache, and other settings. Playwright supports multiple browser contexts within the same browser instance, which can be used for separate sets of tests or scenarios, and each browser context has its own set of pages. 3. The page—Represents a single web page within a browser context with its own DOM tree, frame hierarchy, and other content. Example test:
  • 3. Test Automation Services | Test Automation Framework https://afourtech.com/ When writing tests with Playwright, it offers “assertThat” overloads that intelligently wait until the expected condition is met. There is a list of assertions such as: .isChecked(), .isEnabled(), .isDisabled(), .isEditable(), .isVisible() & many more are there. Locators are crucial in Playwright’s auto-waiting and retry mechanism, enabling efficient element identification on web pages. They provide a means to locate elements and perform various actions like click(), fill(), and many more. Additionally, Playwright allows creation of custom Locators using the “page.locator()” method. Also, Playwright provides multiple actions, for example -> – To input text it provides fill() method, – For checkboxes and radio buttons, it provides setChecked(), – For selecting one or multiple options, it has selectOptions(), – For clicking it has click(), dblClick() methods, – It provides a method called type() which enters string character by character, and many more are there. Playwright offers several features that make it an excellent choice for UI automation testing A. Auto-waiting: Playwright performs thorough checks on elements to ensure that actions behave as expected. It automatically waits for all necessary conditions to be met before executing the requested action. The action fails if the required conditions are not met within the specified timeout. This approach
  • 4. Test Automation Services | Test Automation Framework https://afourtech.com/ guarantees that actions are performed at the right time, enhancing the reliability and accuracy of UI automation. For example: If we want to perform a click() action on an element, then Playwright ensures that 1. Is an element attached to the DOM or not 2. Element is visible or not 3. Is it stable or not 4. It is enabled, and it receives events or not And after performing all required checks, it performs the click action. B. Headless and Non-headless mode: Run your automated tests in headless mode or non-headless mode. C. Debugging Tests:
  • 5. Test Automation Services | Test Automation Framework https://afourtech.com/ The Playwright Inspector is a graphical user interface (GUI) tool that facilitates debugging your Playwright tests. It allows you to live-edit locators, pick locators, and view logs. Additionally, you can utilize the “page. pause()” method to debug your test cases effectively. This approach eliminates the need to manually navigate through each test action to reach the desired debugging point, streamlining the debugging process. D. Test Generator: Playwright includes a powerful test generation feature that allows you to perform actions in the browser. Playwright figures out the best locator on the page; for that, it prioritizes role, text, and testID locators. If the element generator discovers multiple elements that match the same locator, it enhances the locator to ensure uniqueness, enabling us to identify each component accurately. Command: mvn exec: Java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=” codegen demo. Playwright.dev/todomvc”
  • 6. Test Automation Services | Test Automation Framework https://afourtech.com/ When running the Codegen command, two windows will open a browser window to interact with the page element and a playwright inspector to record a test. E. Emulation: We can use a test generator to generate tests using emulation so that we can generate a test for a specific viewport size, specific device, or specific color scheme; also, we can emulate geolocation, language, or timeZone. First, let’s see emulate viewport size: Playwright allows you to open a browser window with a specific width and height using the “viewport” option. This feature enables you to generate tests with different viewport sizes, providing flexibility in emulating various screen resolutions and responsive designs. Command: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=”codegen— viewport-size=800,600 playwright.dev”
  • 7. Test Automation Services | Test Automation Framework https://afourtech.com/ Emulate Device: We can use the command mentioned below: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=’codegen— device=”iPhone 13″ playwright.dev’ We can use the —device option in the command, which sets the viewport size and user agent. We can also write a script for this: Playwright provides a helpful feature to emulate different devices and their characteristics, allowing you to test your web application’s behavior on various devices without needing the physical device. You can use the “setViewportSize” and “setUserAgent” methods to emulate the device properties. Here’s an example: F. Intercepting Network request Playwright offers a powerful feature that enables us to modify seamlessly or block network requests initiated by a web page. This can be useful for testing purposes like simulating slow network conditions, mocking server responses, or testing the web application’s behavior under specific conditions.
  • 8. Test Automation Services | Test Automation Framework https://afourtech.com/ Example: So, in this example, we are setting up a network route for the requested URL. The lambda expression is called when a matching request is made. We are setting custom messages, status codes, content type, and body as our custom messages. Because we have set up a network route for the URL, our custom response will be returned instead of the regular page content, as shown below:
  • 9. Test Automation Services | Test Automation Framework https://afourtech.com/ G. Accessibility Testing Accessibility testing is essential to ensuring that a web application is usable for all users, including those with disabilities. Playwright provides built-in support for performing accessibility testing. H. Authentication Playwright provides an isolated environment called the browser context for executing tests. This allows tests to load an existing authenticated state, eliminating the need to log in for each test. By saving the authentication state in the context, it can be reused across all tests. This approach saves time by avoiding redundant login operations and ensures complete isolation between independent tests. I. Downloads With Playwright’s downloads feature, you can automate downloading files from a website. This feature helps test scenarios that involve verifying the correct download of files or automating tasks
  • 10. Test Automation Services | Test Automation Framework https://afourtech.com/ that involve downloading files. Furthermore, Playwright allows you to customize the behavior of the downloads feature by specifying the download path or filtering the types of files that can be downloaded. J. Trace Viewer The Playwright trace viewer is a tool that allows you to analyze and visualize the recorded trace data of a browser’s actions during test execution. Let’s see some options that provide detailed insights into the sequence of events, network requests, and other relevant information. Command: mvn exec: Java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args=” show-trace” Actions:
  • 11. Test Automation Services | Test Automation Framework https://afourtech.com/ Once the trace is opened in the Playwright trace viewer, you will find a list of actions that the Playwright performed on the left-hand side. Selecting each action from the list allows you to explore detailed information such as the action snapshot, action log, network log, and more. Metadata: The Playwright trace viewer offers comprehensive information, including the timing of actions, the browser engine utilized, viewport details, mobile device emulation, and the count of recorded pages, actions, and events. Screenshots: Each trace records a screenshot and renders it as a film strip. This film strip provides a visual representation of the recorded actions and states. Hovering over each frame in the film strip lets you
  • 12. Test Automation Services | Test Automation Framework https://afourtech.com/ view a magnified image corresponding to a specific action or state, allowing for detailed inspection and analysis. Call: The call option includes details such as the action name, the timestamp when it was called, the duration of the action’s execution, the parameters passed to the action, the return value, and any associated log messages. Console: The Playwright’s trace viewer Console panel offers a view of the console output generated during the recorded actions. It allows you to observe console logs, errors, warnings, and other relevant messages produced during the test case execution. Network:
  • 13. Test Automation Services | Test Automation Framework https://afourtech.com/ It provides a view of all network requests made by the browser, along with their corresponding responses, headers, timings, and other relevant information. Selenium And Playwright Both are popular choices for web automation testing. There are some key differences. A. Architecture: In Selenium, each command is transmitted as an HTTP request, and the corresponding JSON response is received. Every action, such as launching the browser, clicking an element, or entering text into a textbox, is transmitted as a specific HTTP request. This approach results in the termination of the connection between the server and client, which needs to be re-established for the subsequent request. Connection termination after each request can lead to slower execution, which also introduces a layer of flakiness. On the other hand, Playwright utilizes a single web socket connection to handle all requests during the test execution. This architectural approach minimizes potential points of failure and enables commands to be transmitted smoothly over a single connection. This makes Playwright a more stable tool as compared to Selenium. B. Speed:
  • 14. Test Automation Services | Test Automation Framework https://afourtech.com/ The Playwright is faster than Selenium when it comes to executing tests due to its architecture. C. Flakiness: Playwright is designed to be less flaky than Selenium again, thanks to its architecture that isolates each test in a separate browser context. This means that tests do not interface, reducing the chances of flakiness. D. Cross-browser consistency: Playwright is designed to provide a consistent API across multiple browsers, ensuring that the test can be written once and run across different browsers. Selenium requires browser-specific drivers, which may cause inconsistencies in behaviour and functionality across different browsers. E. Debugging: Both Selenium and Playwright provide good debugging capabilities, but Playwright offers additional features that make debugging easier. Playwright provides an interactive mode that allows you to interact with the browser as the test is running, which helps you to identify issues more quickly. F. Testing framework: Selenium and Playwright can be used with testing frameworks like Jest, Mocha, and Jasmine. However, Playwright has its test runner, making it easier to start with testing without learning a separate framework. Conclusion: In conclusion, Playwright, combined with Java, provides a robust and up-to-date solution for UI automation. Its unified API, ability to work across different browsers, and wide range of features
  • 15. Test Automation Services | Test Automation Framework https://afourtech.com/ streamline the automation process and improve testing efficiency. As a result, it is a popular choice for Test Automation Services and is often used as a foundation for Test Automation Framework. The architecture of Playwright, which utilizes browser-specific binaries and maintains persistent web socket connections, guarantees stability and reliability throughout test execution. For detailed information and additional examples, please refer to the links in the references section. About AfourTech AFour is ideation and technology house. Product companies associate with AFour for its product conceptualization and technology skills in wide range of technologies like Java, Python, .NET, Javascript (MEAN), LAMP (Perl and PHP), Angular, React, C++. The company is a hub of every cutting-edge technology in software product engineering services ─ Hyper-convergence, SDN, Virtualization, Next Generation Data Center Technologies, Networking, Enterprise Mobility. Till date, AFour Technologies has been able to bring together some of the best and brightest minds in software engineering.