This article is for the people who would like to automate their applications pragmatically with less effort. We all know, designing a framework for every project is a big deal and a tiresome process. You may say, ‘I am using the Page Object Model and TestNG’. It’s not just adopting certain frameworks, what matters is, how much time you’ve spent on designing the page objects. So, this article tells you how to facilitate & mitigate incommodious tasks using Selenium Object Bank and Cucumber JVM. You can consider this as a Hybrid Framework. Click here to download sample project (Cucumber with SOB).
What is Selenium Object Bank
Selenium Object Bank (SOB) is a project introduced by Automation Testing Utilities. Using this, we can reduce the little effort in creating page objects. The objectives of SOB are
- Storing all the Objects in a central location
- Changing Object properties without any modification on the Script
- Readability and clear understanding of the automation steps performed by just looking into the Script
- Minimizing the Script code by Object Notation
- Creating Robust Scripts
- Reusability of the Objects
- Identifying the Objects with different locators other than those provided by Web Driver (id, name, XPath, CSS, class, tagName)
What is Cucumber
Cucumber allows you to write feature documentation in Plain Text. You could sit with your Client or Business Analyst to write down the features to be built on your application. Proper use of this framework has a great potential to bridge the gap between business people and development people. Anyway, I am not gonna illustrate every nook and cranny here. Simply saying, cucumber JVM will generate the test methods for you so that you don’t need to spend time on designing test methods again. You can surf on the internet for more information on Cucumber.
How to use SOB
Selenium Object Bank is available as a Plugin for Eclipse IDE. You must follow a few steps to avail the beauty of it.
Step 3. You should see a window with ‘Add’ button. On clicking ‘Add’, you should see a pop up ‘Add to Repository‘ which allows you to add the downloaded Plugin. Just click on Local and browse the extracted zip.
Step 4. Once the Plugin directory is selected, the path is shown in the small window. Click on the ‘Ok’ button, you can also give the name it’s optional.
Once it’s done, you should see ‘Selenium Object Bank Manager‘ on right-clicking any class
How to use Cucumber
It’s quite simple, we need to design scenarios in features files which states the behavior of the application in plain English. Once you’re done with it, just right click on the feature file and run as ‘Cucumber Feature’ which generates test methods saying ‘You can implement missing steps with the snippets below’ in the console.
How to use Cucumber JVM with Selenium Object Bank
Once you get the test methods on running cucumber feature files, you need to create step definitions for all the scenarios. For that just create a Package named ‘com.stepDef’ and create a class of that feature. Now copy the test methods from the console and paste it in the class you have created.
Right click on that class, you should see ‘Selenium Object Bank Manager‘. Just click it.
Now here comes the interesting part, you should see a control panel where you can add the page objects present in that page.
Just give proper readable object name and also Attribute (XPath) & Value (value).
From the SOB window, you can see the available Objects in the left Pane
When you click on any Object from the left pane, you can see the Object details and the Element Tag type from the Properties table and the Select Box
To Add an Object, Enter a Unique Object Name in the field, Select the element tag type, enter the attribute and its value (you can add more than one locator) and click on Add button.
Once you’re done with adding page objects close the window and Refresh the Project. A package starts with ‘objects.mapper…’ and a folder ‘ObjectBank’ along with a class Has[Script Name]Objects will be generated.
It’s simple right! now you can just call the page objects wherever you require it. Since most of the work was done by Cucumber & SOB and rest will be done by us implementing a few logics based on the functionality. This framework really saves huge time and makes you nonchalant. You can download sample project (Cucumber with SOB) from here.
I hope this framework can be used for automating web applications (Selenium) as well as mobile applications (Appium) too.
Credit goes to the creators of SOB and Cucumber frameworks. These frameworks make our job much simpler.