0

Possible Duplicate:
Load an external js file containing useful test functions in selenium

I have to do performance testing for a system using Selenium RC and writing the tests in Javascript so the rest of my team can understand them. I need to be able Sencha Ext library to access certain controls on the page so I need to be able to define the external js library. In my tests for selenium I can't define the library using the normal means of writing a script tag to the page; document is undefined. Also trying to use other selenium commands like addScript dont seem to be much help.

Is there a better way to include an external js library with Selenium? I do have the open source Sencha Ext library locally so I can put it wherever.

Can I just load the library as a reference from soda? I did see somebody modifed the Selenium standalone RC jar file but that is way out there for me to understand. I'm kind of lost here where to go from here.

Thanks,

Community
  • 1
  • 1
tree
  • 391
  • 2
  • 16

1 Answers1

0

Well, from the point of view that js can be run from selenium test in this way:

WebDriver driver;
// create driver, i.e. driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("alert('Hello from Selenium!');");

So actually we need to include js lib through selenium API. IMHO your solution be like:

 WebDriver driver;
    // create driver, i.e. driver = new FirefoxDriver();
    JavascriptExecutor js = (JavascriptExecutor) driver;

//Load an external js file containing useful test functions in selenium
js.executeScript("var doc = this.browserbot.getCurrentWindow().document; var scriptTag = doc.createElement("script"); scriptTag.type = "text/javascript" scriptTag.src = 'your_script_URL_goes_here'; doc.body.appendChild(scriptTag)");

in that way we included needed js lib. In a similar way you can call functions containing in this external js lib.

This post might be helpful for you. Also investigate this question. Regards.

Community
  • 1
  • 1
eugene.polschikov
  • 7,254
  • 2
  • 31
  • 44
  • Thanks but Im looking for a javascrpt only solution; no JAVA. The first link i see is JAVA while the other is off the selenium IDE;Im using neither. I'm using selenium RC from the command line to tests written in javascript "only" with soda as the intermediary. – tree Oct 15 '12 at 17:10
  • I did try adding Sencha Ext as an extension to the selenium RC jar but it doesn't seem to work. Updating RemoteRunner.html, TestRunner.html, and adding it to the user-extensions.js doesn't seem to define my scripts. I'm trying to first add the scripts in the normal js fashion to the page eithe programmatically adding a script tag as in the user-extension.js or in the html files. But then I think I also need to define an object Ext which is used to target Sencha methods;like $ or jquery in jquery. – tree Oct 15 '12 at 17:16
  • I'm skipping doing this for now since I can manage with just the runscript method for a while. – tree Oct 19 '12 at 12:51