Monday, January 30, 2023

Portability testing a web application UI with Selenium

Portability testing of web application UI can easily be handled with Selenium. To handle cross browser testing you can implement a driver instantiation pattern like the one shown below,



For cross mobile agent testing, you can use a TestNG data provider to pass in the device types into your test method and repeat the test for as many emulated devices as you would like.

Find the complete project here, https://github.com/handakumbura/SeleniumAutomationEmployerProfile/tree/feature/cross_browser_cross_agent









Saturday, January 14, 2023

How to read the user selection from a radio button group using Selenium?

SeleniumUtil library has been occupying my free time for the past couple of months. Since I’ve already written at length about what it is I won’t do that again here but if you really want to know you look here [1] [2].

When I implemented the abstraction wrapper for the HTML radio button group I ran into a problem. How would someone go about reading the user selection form a radio button group? Take a look at this HTML block,



According to the HTML5 spec, Radio Buttons belonging to the same group would have the same name attribute value. So toggling a given radio button using Selenium is not too difficult, but unlike Checkbox's the Radio Buttons I've seen in the wild (including this W3C example) doesn't append a checked attribute upon user selection. This complicates things.

I first tried retrieving the selection using the $0 variable that stores the user selection. But it turned out it was a browser specific variable that is not exposed to JavaScript. So how can we get a handle on this element and read its value? I did this,


But you can save all the pain because this snippet and bunch of other JavaScript goodies are available in SeleniumUtil 0.7.5.  

Saturday, January 7, 2023

SeleniumUtil 0.7.0 is now available with a few Java Script utility methods

Abstraction helps to promote code reuse and reduce development time among other benefits. When considering Selenium based test automation, you can abstract at many different points such as at dependency, infrastructure, technology, page, component or even at the element or locator level. SeleniumUtil is an open source library that aims to provide generic abstractions and other useful utilities so that you don’t need to worry about them in your Selenium based test automation projects.

Version 0.7.0 is now available in maven central and it provides a few technology level abstractions in the form of a few parameterized Java Script methods.


Usage











Tuesday, December 27, 2022

SeleniumUtil is an open source library to help make Selenium+Java automation easier and faster

I’ve been through two tech companies where they’ve had their own test automation frameworks. The last framework that I used was built to handle Web UI, API, and AS400. The framework was built by providing wrappers for common open-source automation components such as Selenium and Rest-assured. It was easy to set up an automation project using the framework, and only a few of us had any real concerns with it. It was the responsibility of the respective development teams to use the framework to automate their products based on a few loose programming guidelines. As the teams go through this exercise, they would build any custom components they might need as they see fit. Some of these components are universally used but were not available in the framework of the respective open-source components OOTB. Components such abstractions for working with HTML tables or custom ExpectedConditions. 


When I had some time on my hand I looked around to see if there are any open-source libraries that I can use out there to cut the automation project setup time and I found that there isn’t a lightweight library that can be easily integrated to existing projects. So I started one of my own.


At the moment the library provides a few wrappers for HTML elements such as RadioButton, MultiSelect, and Table. The plan is to implement other useful features such, Wrappers for common JavaScript script snippets, custom ExpectedConditions, and sliders. The library is at version 0.6.5 and it's available on Maven Central[1]. If you’re interested in contributing to the project please follow the instructions here [2][3].


[1] - https://search.maven.org/artifact/io.github.handakumbura/Seleniumutil/0.6.5/jar

[2] - https://docs.google.com/document/d/1Diudxs53eL8QkfYwHpExkusEtpJxF0mDHVrr6XymXYE/edit?usp=sharing

[3] - https://github.com/handakumbura/Seleniumuntil


 

 




Sunday, December 18, 2022

How to create custom locator classes in Selenium and a few reasons why you should

Selenium supports many different HTML element locator strategies such as CSS, class, ID, and XPath. Xpath in my opinion is provides you with the most flexibility as it has features such as axes (build-in functions) and conditional operators. It would be hard to find an element you couldn’t capture in a sensible way with Xpath but it all depends on how good you’re with Xpath. So if you’re a test framework developer it makes sense for you to abstract out some of the common XPath templates into new By classes. Apart from reducing the chances of inexperienced test engineers making mistakes with the Xpaths, you can increase the readability of the code and provide means for greater reusability (through mechanisms such as ByChained).


Test Layer


Custom By Locator




What's in my Bag? EDC of a Tester