Generate IDs in all components in ADF Faces pages and fragments – to facilitate automated Selenium based testing
Lately, we have been introducing Selenium based testing for many our ADF Faces based web applications. Or rather, our testers created the tests for the web pages using Selenium. And did so quite successfully.
However, certain test scripts seemed to fall apart after having been run only a few times. That was rather annoying. Upon closer inspection, we noticed that the scripts that started failing had one thing in common: the Selenium scripts contained references to element id values that started with j_id. I realized that these id values are not defined in the pages by the developer, but instead assigned at run time by the ADF Faces framework. That in turn means that these ID values can easily change, between two test sessions using the same test script for example.
In order to have test scripts that continue functioning – it was required to have fixed id values. Besides, it is a best practice to assign id values to all components at design time rather than having them generated dynamically. Unfortunately, as found out later, we had over 2000 components lacking an id attribute with developer defined value. Going through all files and assigning ID values manually was not a task anyone on the team was really looking forward to.
We then decided to write a small Java utility that processes all JSPX and JSFF files, locates elements of specified types without and ID attribute and assigns a unique ID attribute value. Running this utility took all of 45 seconds and corrected 2186 components.
You can download the AddIDsToADFPage.zip file that contains a JDeveloper 11g application with a single class – JSPXProcessor. To correct your JSPX and JSFF files – simply load the application, open the class, specify the directory to (recursively) process in the main method and run the class. The private List variable elementNamesThatNeedId contains a List of element names for which ID attributes should be added. Some components, such as f:facet and f:param, do not require an ID attribute. You may want to extend this list to better suit your needs.
Note: the structure of the JSPX and JSFF files will change when even a single ID attribute is added, as the XML is written again to the file system in potentially a different layout than before. This may (and did on our site) confuse diff-and-merge utilities.
Download JDeveloper application: AddIDsToADFPage.
- Selenium – Browser based Tool for Integration Testing of Web Applications (JavaPolis Quicky)
- Selenium IDE – plugin for FireFox – easy black box web application testing
- Introduction to Blackbox testing of Web Applications using Selenium
- Automated SOAP testing with maven and the SoapUI plugin
- Driedaagse Oracle Service Bus (OSB) 11g training – 29, 30 en 31 januari 2014
- Oracle ADF Virtual Developer Day 2013
- The AMIS Summary of Oracle OpenWorld 2013 is available for download – 60-page white paper
- OOW13: summarizing one week and 2000 sessions in 3 hours and a bit – the yearly AMIS OOW Review session – 10th October
- Case Study: A Case of Fusion Middleware
- Het Oracle OpenWorld Preview Evenement (5 september 2013) – 15 sprekers & sessies
- ADF 12c: Using WebSockets to implement client to client push (in a scalable manner)
- ADF 12c – The Hierarchical Mystery Tour – Treemap, Sunburst, Treetable, Hierarchy Viewer and Thematic Map
- ADF DVT: Sunburst to quickly inspect the hierarchical composition
- JDeveloper 12c & ADF 12c: Launch of the next generation