Difference between revisions of "Selenium"

From iDempiere en
(Created page with "<div style="font-size:180%"> <span style="color:red"> IN PROGRESS </span> </div> == Random uuid issue == One of the biggest issue in creating selenium test script for our z...")
 
Line 3: Line 3:
 
</div>
 
</div>
  
−
== Random uuid issue ==
+
== HTML ID ==
  
−
One of the biggest issue in creating selenium test script for our zk client is the zk component id is randomly generated and can change from one run to another.
+
Selenium test script works by simulation of user action. To do so, it need to access each html component using either html id or xpath expression. For zk, we have extended that to support the use of zk jQuery selector as well.
  
−
To address this issue, we assigned id or a special widget attribute to each component. Id is the prefer approach but we need the special widget attribute "instanceName" (AdempiereWebUI.WIDGET_INSTANCE_NAME) approach to resolve the "non-unique id within id space" issue.
+
The selenium test script that uses html id is problematic for zk since the html id for each zk component ( uuid in zk term ) is randomly generated and can change from one run to another.
  
−
The Adempiere id generator use the idspace hierarchy (parent component that implement the idspace interface) to generate the uuid of a component. Specifically, the uuid is the id or widget instance name of all parent idspace owner + the id or widget instance name fo the component. For e.g:  
+
To address this issue, we have to assigned an id ( zk component id, not html id ) to each zk component. There is one caveat with such approach though, Zk required the id of each component to be unique within an idspace ( idspace is defined by the nearest parent component that implement the idspace interface ). This is usually not an issue but could be problematic if you want to assigned a well known id to a shared component. To avoid the risk of causing "non-unique id within id space" exception at runtime, we added a second option. Instead of an id, you can assigned a special widget attribute, "instanceName" (AdempiereWebUI.WIDGET_INSTANCE_NAME) to the component name. AdempiereIDGenerator and your custom test script can then make use of this when component id is not available.
 +
 
 +
The Adempiere id generator uses the idspace hierarchy to generate the uuid of a component. For e.g:  
  
 
* The uuid ( html id ) of the ok button at the login window is loginPanel_Ok which is the id of the login window ( loginPanel ) + the id of the ok button ( Ok ).  
 
* The uuid ( html id ) of the ok button at the login window is loginPanel_Ok which is the id of the login window ( loginPanel ) + the id of the ok button ( Ok ).  
−
* The complete button for sales order have the uuid of window0processButtonPopup_DocAction which is the widget classname of the popup ( window ) + the instanceName attribute ( processButtonPopup) + the id of the button ( DocAction ).
+
* The complete button for sales order have the uuid of window0processButtonPopup_DocAction which is the widget classname of the popup ( window ) + the instanceName widget attribute ( processButtonPopup) + the id of the button ( DocAction ).
  
−
For both example, to access the component using the uuid notation, you just need to prefix it with #, i.e #loginPanel_Ok and #window0processButtonPopup_DocAction. For zk selector, you use $ prefix for component id, and @ prefix for widget classname+instanceName. This translate to "$loginPanel $Ok" and "@window[instanceName=\"processButtonPopup\"] $DocAction" for the 2 example above. Why the 2 notation ? The difference here is the # notation only work when you are using the AdempiereIDGenerator and the AdempiereIDGenerator is only use to create functional test script and is not used for end user testing, development or production instance deployment.
+
In your test script, you access the component using either uuid of zk jQuery selector. For uuid notation, you need to prefix it with #, i.e #loginPanel_Ok and #window0processButtonPopup_DocAction. For zk selector, you use $ prefix for component id, and @ prefix for widget classname+instanceName. This translate to "$loginPanel $Ok" and "@window[instanceName=\"processButtonPopup\"] $DocAction" for the 2 example above. Why the 2 notation ? The difference here is the # notation only work when you are using the AdempiereIDGenerator. For deployed instance, AdempiereIDGenerator is turned off due to performance reason so it is recommended to use the selector approach for your test script. Selenium IDE will record test script with the uuid notation but it is straightforward to convert it to the zk selector notation. For example, "loginPanel_Ok" translate to "$loginPanel $Ok" and window0processButtonPopup_DocAction translate to "@window[instanceName=\"processButtonPopup\"] $DocAction" ( we know it is not an id from the presence of the 0 separator ). It is also easy to find out manually the zk selector needed using the FireBug of Chrome's inspect element tool. Typically, you need to look for the html element with the css class that correspond to the zk component name that you want to access. For e.g, zk decimalbox will have the css class z-decimalbox, hbox will have z-hbox, etc.
  
−
For AD window, report and process, this is addressed at the framework level. For custom form, you would have do the id assignment for each component to make it test ready.
+
For window, report and process, this is addressed at the framework level. For custom form, you would have do the id assignment for each component to make it test ready.
  
 
== Create Test Script ==
 
== Create Test Script ==

Revision as of 11:37, 20 December 2012

 IN PROGRESS 

HTML ID

Selenium test script works by simulation of user action. To do so, it need to access each html component using either html id or xpath expression. For zk, we have extended that to support the use of zk jQuery selector as well.

The selenium test script that uses html id is problematic for zk since the html id for each zk component ( uuid in zk term ) is randomly generated and can change from one run to another.

To address this issue, we have to assigned an id ( zk component id, not html id ) to each zk component. There is one caveat with such approach though, Zk required the id of each component to be unique within an idspace ( idspace is defined by the nearest parent component that implement the idspace interface ). This is usually not an issue but could be problematic if you want to assigned a well known id to a shared component. To avoid the risk of causing "non-unique id within id space" exception at runtime, we added a second option. Instead of an id, you can assigned a special widget attribute, "instanceName" (AdempiereWebUI.WIDGET_INSTANCE_NAME) to the component name. AdempiereIDGenerator and your custom test script can then make use of this when component id is not available.

The Adempiere id generator uses the idspace hierarchy to generate the uuid of a component. For e.g:

  • The uuid ( html id ) of the ok button at the login window is loginPanel_Ok which is the id of the login window ( loginPanel ) + the id of the ok button ( Ok ).
  • The complete button for sales order have the uuid of window0processButtonPopup_DocAction which is the widget classname of the popup ( window ) + the instanceName widget attribute ( processButtonPopup) + the id of the button ( DocAction ).

In your test script, you access the component using either uuid of zk jQuery selector. For uuid notation, you need to prefix it with #, i.e #loginPanel_Ok and #window0processButtonPopup_DocAction. For zk selector, you use $ prefix for component id, and @ prefix for widget classname+instanceName. This translate to "$loginPanel $Ok" and "@window[instanceName=\"processButtonPopup\"] $DocAction" for the 2 example above. Why the 2 notation ? The difference here is the # notation only work when you are using the AdempiereIDGenerator. For deployed instance, AdempiereIDGenerator is turned off due to performance reason so it is recommended to use the selector approach for your test script. Selenium IDE will record test script with the uuid notation but it is straightforward to convert it to the zk selector notation. For example, "loginPanel_Ok" translate to "$loginPanel $Ok" and window0processButtonPopup_DocAction translate to "@window[instanceName=\"processButtonPopup\"] $DocAction" ( we know it is not an id from the presence of the 0 separator ). It is also easy to find out manually the zk selector needed using the FireBug of Chrome's inspect element tool. Typically, you need to look for the html element with the css class that correspond to the zk component name that you want to access. For e.g, zk decimalbox will have the css class z-decimalbox, hbox will have z-hbox, etc.

For window, report and process, this is addressed at the framework level. For custom form, you would have do the id assignment for each component to make it test ready.

Create Test Script

  • Using Selenium IDE and Export to JUnit 4
  • Write JUnit Test Case using Web Driver API
  • Write Junit Test Case using ZTL API
  • Write Fitnesse test case using fitlibrary.zk.ZkFixture
Cookies help us deliver our services. By using our services, you agree to our use of cookies.