Fujiao Liu
Fujiao Liu

Reputation: 2253

execute javascript in robotframework with selenium2library

I am testing a extjs-based web applaction with robotframework and selenium2library,but I can not locate some elements which is contained by a table component. The selenium2library have a keyword called Execute javascript, so I want to kown how can I execute javascript ,For example how can I execute the js code:

var a=document.getElementById('ext-comp-1155').getElementsByTagName("button");
a[0].click();

Does anyone have successful extjs-based web pages automated testing experiences ? Any help would be appreciated.

Upvotes: 1

Views: 12713

Answers (2)

janne
janne

Reputation: 1017

You should be able to execute the javascript like this

  Execute Javascript var a=document.getElementById('ext-comp-1155').getElementsByTagName("button"); a[0].click(); 

I.e. event though there are mutliple statements in the javascript, you can give them in single argument, as long as the semicolons are in place.

That can be made a bit more readable like this:

 ${button clicker}=  document.getElementById('ext-comp-1155').getElementsByTagName("button")[0].click() 
 Execute Javascript  ${button clicker} 

Upvotes: 1

TN.
TN.

Reputation: 611

If you are not limited to Selenium you may want to look at RIATest.

Version 5.0 fully supports ExtJS testing. ExtJS UI widgets are first class citizen in RIATest. This means that unlike other HTML testing tools you do not need to write tests that manipulate the HTML DOM elements. The tests in RIATest operate in terms of ExtJS UI widgets.

Examples of RIATest scripts that work with ExtJS widgets:

The following clicks on an ExtJS button with label "Next Page":

ExtButton("Next Page")=>click();

And the following does drag-n-drop of a row from one ExtJS tree to another:

ExtRow("Controller.js")=>dragAndDropTo(ExtTreePanel("#tree2")->ExtRow("Custom Ext JS"));

And this collapses the header of an ExtJS box:

ExtBox("Feeds")->ExtHeader("FeedsВ")->ExtCollapser()=>click();

(All sample code above is from real test scripts that run on ExtJS sample applications).

RIATest also knows when to automatically wait for ExtJS AJAX to finish, so if your UI does dynamic content downloading the tests will auto-magically wait until data is received from server.

(Disclaimer: I am a RIATest team member).

Upvotes: 0

Related Questions