Posted: 5 Mar 2018 4:49 EST Last activity: 16 Mar 2018 6:26 EDT
Ask the Expert - Selenium Automation with Swetha Korukonda
Join Swetha in this month's Ask the Expert session on Selenium Automation!
Meet Swetha Korukonda: Swetha Korukonda works as a Quality Analyst at Pegasystems. Swetha has been involved in test automation since 4 years and handles responsibilites of application quality in Marketing for Communications.
Message from Swetha: I'm happy to take your questions about automating test cases in Selenium, page object model and finding the best identifier for the UI elements.
Let me explain the approach of page object model with a simple example of a user logging in to web application and verifying the UI element text on the welcome page.
1) Let's consider two pages here, Login page and the Welcome Page . Start by creating two class files, It's always preferred to give the class name same as web page name, so in this case class name will be Loginpage.java and Welcomepage.java and define the web elements on the page.
Say Login page has,
1. UserName textbox
2. Password textbox
3. Sign in Button
And Welcome page has,
1. WelcomeHeader Label
2) Define the possible actions on the web elements (objects) as abstract methods in the respective class files.
1. For Textbox : set text
2. For Button : Click, get text on button.
3. For Label: get Text
3) Create an implementation class and define the methods will perform this actions.
4) Now, its time to create business logic which can be reusable, Create and page (class file) and page object to call the above methods.
Is there a way to delegate creation of automated Pega acceptance tests to the business users? Any framework that would lket the business users to record their actions in Pega and then play back checking the reasults? Any experiences from Your projects perhaps?
Could you please brief more on delegation of creating tests.
I did not had this experience in the project before, however Cucumber tool allows to write acceptance tests in easily readable and understandable format (plain English) to Business users. Feature files serve as good documents as well ,by seeing the feature file a user should be able to understand the intent behind the scenario and what the test is all about. Selenium IDE is a record and playback tool which can be used for simple web application automation purpose.
I have a question about uploading and downloading files - we have this functionality of Pega and we are using it in our projects. Can you help me with some ideas about the approach to such scenarios? The most problematic part is that we are using Jenkins as a CI and build manager for our automation project.
For example downloading a file - even if I had it working locally I can click to download and verify my local download location that the file actualy was downloaded there, but when I run same scenario on Jenkins server, I do not know what should be the path to verify that the file was downloaded there. Have you ever tried to automate such scenarios?
Hope you will copy the project folder in the Jenkins server.
You can create a Sample folder named Data in your existing project and download and upload the file from that location.
Please find sample code snipped below which might be helpful for you
String currentDir = System.getProperty("user.dir"); // Gets the current working directory location
currentDir = currentDir.concat("\\Data\\");
currentDir = (currentDir.concat(filename)).concat(".csv"); // Set the current directory location till filename.extension
WebElement uploadFile = Webdriver.findElement(INPUT_FILE_LINK); // Find the search box to enter the path to upload the file
uploadFile.sendKeys(currentDir); // Pass the current directory path till the file name.
this is regarding dynamic layouts and grids, for example if we have a grid repeating in a frame multiple times, can we set unique key/id for the grid? currently we see name which is same for all grids.
If you are trying to find the unique attribute of each grid in a repeating layout, you can find the stable parent element (reference element) of the grid and find child element based on its index of occurrence.
You can find with a parametrized Xpath from parent element.
To support more on this, could you provide the html structure of the grid
My understanding is that the Attach File(s) modal dialog box is a standard Pega component. Do you have a recommendation on how to set focus on the dialog box's input type=file element from within a script of Selenium commands? My objective is to have an automated process upload a file to that input element. In my script I have successfully accessed the dialog box's CloseModal, Cancel and Attach command buttons but the script cannot find the input type=file element.
When executed in the console, the XPath command below returns two input elements of type=file. Can you tell me which one is the element a file should be uploaded to and how to set focus on that element?
Quick clarification here, findElements() method returns array of web elements of data type List (List<WebElement>) for which index starts with 0 not 1. And yes, we also use (Xpath) with starting index 1 however if we define a web element as such it can decrease the chances of reusability.
Would like to know your approach/design strategy in terms of building automation frameworks other than page object framework where we don't have UI ready and need to build a generic framework at the enterprise level. Do you have any suggestions?
Also could you please share us your experience in using data-test-id in identifying the locators during script executions. Many times we have extracted data-test-id but the execution of scripts are consistent only when LiveUI is enabled.
There are different design approaches available like Strategy Design pattern, Page Factory with in Page object etc..
Each has its own pros and cons.
As you have mentioned to want to have a generic framework, you may need to analyse the type of test scenarios that needs to be automated.You can initially start with creating the interface files where a abstract methods and place holder elements can be defined. And based on your test scenario we can follow the implementation approach of those interfaces accordingly.
LiveUI is used to just parse the DOM structure , enabling it should not impact the identification of elements. Could you check the frame id of element is getting changed or constant for the particular element. Also, can you try putting some wait in the script before finding the element, just to check if the controls are taking time to load.
Hi Swetha, I identifying atext box with Id , also tried using xpath both method not able to locate the element while executing the script, I have thread sleep for 9 sec before executing this line. Is there any reason in have an answer.
We can use Telerik, selenium or any other automation tool, i am currently using selenium for the pega application,
if we have to automate the web based application, we can choose selenium as its open-source features help to script own extensions that makes it easy to develop customized actions and even manipulate at an advanced level.