Showing posts with label Sel-FF-Chrome-TestRuner. Show all posts
Showing posts with label Sel-FF-Chrome-TestRuner. Show all posts

Saturday, December 27, 2008

Selenium1.0b buglist for Firefox 3 Chrome TestRunner

There are a lot of bugs in Selenium1.0b to run on Firefox 3 with chrome TestRunner.html.

I list them here:
1. CSS/Resource issue: http://jira.openqa.org/browse/SIDE-222
2. Permission Denied issue: http://jira.openqa.org/browse/SEL-612
3. waitForPopUp issue: http://jira.openqa.org/browse/SIDE-228
4. click link issue: http://jira.openqa.org/browse/SEL-614
5. UI-Element not work issue: http://sejq.blogspot.com/2008/12/fix-ui-element-cant-run-bug-in-chrome.html

Saturday, December 20, 2008

Dedicated to developing Selenium Core Firefox chrome branch

Since my team has chosen Selenium Core-Firefox chrome with Selenese table test case as primary Selenium testing method, my task will focus on Selenium Core Firefox chrome branch development(A brand new Selenium-IDE). I will also contribute a bundle of Java APIs to play Selenium Core*ffchrome. Moreover, I should provide a GRID framework for huge test case number run.

"Simply the best". No proxy server, no Remote Control, no IE/HTA, no Java Test Case, no Same Origin Policy, I really found this mode is efficient but powerful as long as we provide an enterprise framework.

For QA, they only need learn Selenese table knowledge without Java programming skills. They don't need to install any complex framework but only setup our Selenium-IDE version on their desktop.

For framework developer, then needn't build a heavyweight infrastructure like proxy server, client driver. What they need do are only:
1) Let Selenium-Core*ffchrome save detailed enough result capture/snapshot with well formed structure to local file system.
2) Extend chrome URL parameters to meet all configuration requirements. We can benifit a lot from Mozilla APIs and do some fantasitic jobs for Selenium core(That why we choose Firefox as Selenium browser).
3) A bundle of Java APIs to play Selenium-Core*ffchrome under isolated profile and parse run results to Java Objects. We can define an atomic unit(1-3) as one Selenium Agent.
4) A GRID Java framework to distribute huge test case number run on Agents with scalability. DB support is necessary to save both test case info and run result info.
5) Then a GUI web based test case maintenance and execution portal is possible with above back end framework supporting.

Comparing to official RC+GRID solution, our solution is more suitable for acceptance test, integrating test & regression test(black box).

Friday, December 12, 2008

Firefox3 new security rule: Selenium no CSS on Chrome TestRunner

Firefox 3 introduced more strict security rules than older version. Many Selenium weird issues on FF3 are related to it, while most of these issues didn't happen on FF2.

Today I encountered one SeleniumIDE1.0b2 bug: [SIDE-222]Test execution is not possible in chrome mode in Firefox 3.

FF3 Error Console reported:
Security Error: Content at (local test suite html address like file:///c:/seltest/testsuite1.html) may not load or link to "chrome://selenium-ide-testrunner/content/selenium/selenium-test.css" 
It seems FF3's default security settings not allow external file access chrome:// resource.
I read Mozilla docs: https://developer.mozilla.org/en/Chrome_Registration#contentaccessible

It said: (New in FF3) Chrome resources can no longer be referenced from within <img>, <script>, or other elements contained in, or added to, content that was loaded from an untrusted source. This restriction applies to both elements defined by the untrusted source and to elements added by trusted extensions. If such references need to be explicitly allowed, set the contentaccessible flag to yes to obtain the behavior found in older versions of Firefox.

So, I try to modify Selenium-IDE1.0b2's chrome.manifest file.
content selenium-ide-testrunner jar:chrome/selenium-ide.jar!/content/ xpcnativewrappers=no 
content selenium-ide-testrunner jar:chrome/selenium-ide.jar!/content/ xpcnativewrappers=no contentaccessible=yes
SeleniumIDE1.0b2 displayed CSS correctly this time on FF3 Chrome TestRunner.

Monday, December 1, 2008

Fix ui-element can't run bug in Chrome TestRunner mode

Selenium-IDE1.0b2 introduced a new feature: UI-Element. It is very useful feature for annoyed XPATH EL.

We try demo in Selenium IDE panel successfully. However, when we try UI-Element test case in Chrome TestRunner, even if we set &userExtensionsURL=chrome://selenium-ide/content/ui-element.js,file:///c:/ui/my-ui-map.js correctly in chrome URL, it failed to load any UI-Element feature.

Weird, we have discussed it on openqa forum. Finally, I fix this bug in chrome://selenium-ide/content/ui-element.js
function is_IDE()
{      
 //[Begin Fix]
 var locstr = window.location.href;  
 if(locstr.indexOf("selenium-ide.xul") != -1){
     //IDE mode   
     return true;
 }else{
     return false; 
 }
 //[End]
 return (typeof(SeleniumIDE) != 'undefined');
}
It seems
typeof(SeleniumIDE) != 'undefined'
not work in Chrome TestRunner mode.

Finally, with above fix, UI-Element works in both IDE and Chrome TestRunner.

More discussion: http://clearspace.openqa.org/message/53306

Saturday, November 15, 2008

Customize Selenium Chrome TestRunner profile in JRunner

There is a prefs.js configuration file for each Firefox profile.
Selenium Java Runner can do some necessary customization before launch Firefox TestRunner instance.
Read prefs.js docs: http://kb.mozillazine.org/Prefs.js_file

Sample prefs.js customize code:
PrintStream out = new PrintStream(new FileOutputStream(prefsJS, true));
// Don't ask if we want to switch default browsers
out.println("user_pref('browser.shell.checkDefaultBrowser', false);"); 
// suppress authentication confirmations
out.println("user_pref('network.http.phishy-userpass-length', 255);");
// Disable pop-up blocking
out.println("user_pref('browser.allowpopups', true);");
out.println("user_pref('dom.disable_open_during_load', false);");
out.println("user_pref('startup.homepage_welcome_url', '');");
// Disable Restore your session dialog. Always start a new session
out.println("user_pref('browser.sessionstore.enabled', false);");
// Disable security warnings
out.println("user_pref('security.warn_submit_insecure', false);");
out.println("user_pref('security.warn_submit_insecure.show_once', false);");
out.println("user_pref('security.warn_entering_secure', false);");
out.println("user_pref('security.warn_entering_secure.show_once', false);");
out.println("user_pref('security.warn_entering_weak', false);");
out.println("user_pref('security.warn_entering_weak.show_once', false);");
out.println("user_pref('security.warn_leaving_secure', false);");
out.println("user_pref('security.warn_leaving_secure.show_once', false);");
out.println("user_pref('security.warn_viewing_mixed', false);");
out.println("user_pref('security.warn_viewing_mixed.show_once', false);");
// Disable cache
out.println("user_pref('browser.cache.disk.enable', false);");
out.println("user_pref('browser.cache.memory.enable', true);");
// Disable "do you want to remember this password?"
out.println("user_pref('signon.rememberSignons', false);");
// Disable any of the random self-updating crap
out.println("user_pref('app.update.auto', false);");
out.println("user_pref('app.update.enabled', false);");
out.println("user_pref('extensions.update.enabled', false);");
out.println("user_pref('browser.search.update', false);");
out.println("user_pref('browser.safebrowsing.enabled', false);"); 
//enable javascript 
out.println("user_pref('javascript.enabled', true);"); 
//Optional Tips: User-Agent hijack for http traffic debug
//out.println("user_pref('general.useragent.override', 'Here crack user-agent');");  out.close();

Tuesday, November 11, 2008

Selenium close all Firefox windows in profile when finish run

There is a Chrome URL parameter &close=true in Selenium-IDE. When set to true, it will automatically close Selenium Firefox windows when finish run. However, if application window has popuped child windows like ads, selenium can't close these popup windows when quit.

This has risk to lock Firefox profile when multiple Firefox profiles running simuteniously. Please refer to "Firefox is aleady running issue"
Enhance Selenium-IDE by XPCOM API: close all Firefox windows under current profile. Add logic when Selenium quit(close=true).
Sample code:
var windowManager = Components
  .classes['@mozilla.org/appshell/window-mediator;1'].getService();
var windowManagerInterface = windowManager
  .QueryInterface( Components.interfaces.nsIWindowMediator);
var enumerator = windowManagerInterface.getEnumerator( null );
var appStartup = Components
  .classes['@mozilla.org/toolkit/app-startup;1'].
  getService(Components.interfaces.nsIAppStartup);
while ( enumerator.hasMoreElements()  )
{
  var domWindow = enumerator.getNext();
  if (("tryToClose" in domWindow) 
       && !domWindow.tryToClose())
    return false;
  domWindow.close();
};
appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);

Monday, November 10, 2008

Save to local files with XPCOM for Selenium Firefox Chrome

We save selenium run snapshot/result/log to local files instead of complex POST to server solution. We require APIs in browser(out of Security Sandbox) for local files accessing.

In IEHTA, there is ActiveX object FSO to access local files.
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
Is there a similar object in Mozilla Firefox Chrome?
The answer is XPCOM object @mozilla.org/file/local;1

Save to file Sample:
function saveFile(fileName, val){
   try {
      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   } catch (e) {
      //alert("Permission to save file was denied.");
   }
   var file = Components.classes["@mozilla.org/file/local;1"]
             .createInstance(Components.interfaces.nsILocalFile);
   file.initWithPath(fileName);
   if (file.exists() == false) {
     //alert("Creating file... " );
     file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
   }
   var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
            .createInstance(Components.interfaces.nsIFileOutputStream);
   outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 ); 
   //UTF-8 convert
   var uc = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
     .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
   uc.charset = "UTF-8";
   var data_stream = uc.ConvertFromUnicode(val);
   var result = outputStream.write(data_stream, data_stream.length );
   outputStream.close(); 
}
We use UTF-8 encode here.

Sunday, November 9, 2008

PseudoTestRunner.html to run Selenium Chrome by cmdline

Launch Selenium Chrome TestRunner by cmdline: firefox.exe -chrome "chrome://selenium-ide-testrunner/content/selenium/TestRunner.html..." will cause many weird issues on Firefox.
I'm not sure the root cause which maybe related to Firefox Chrome Security Strategy for -chrome parameter.

Here is a workaround:
Hijack selenium-ide.xpi. Under selenium-ide\content\selenium\ add a file PseudoTestRunner.html
Source:
<html>
<head><title>Pseudo Test Runner - Used for launch Chrome by Cmdline</title></head>
<body>
  <script language="javascript"> 
  var strHref;
  var intParamsStartIndex;
  var strParams;
  strHref = window.location.href;
  intParamsStartIndex = strHref.indexOf("?");
  strParams = strHref.substring(intParamsStartIndex);
  window.open("chrome://selenium-ide-testrunner/content/selenium/TestRunner.html" + strParams);
  window.close();
  </script>
</body>
</html>
Then please always use PseudoTestRunner.html instead of TestRunner.html in cmdline, keep the same parameter list in URL.

Refer to topic: http://clearspace.openqa.org/message/51801#51801

Saturday, November 8, 2008

How to let JAVA play with Selenium Firefox Chrome TestRunner

Selenium Firefox Chrome TestRunner is written by JS/DHTML. When we want to embed Firefox Chrome TestRunner engine into our testing framework. We are asking for a way to let JAVA play with Firefox Chrome TestRunner. You can also refer to Selenium-RC source code to launch a browser. Here is a workaround solution with pseudo code.

1. In & Output of 'Selenium Firefox Chrome TestRunner' component for JAVA IN: it is usually URL trigger for running. Chrome URL with parameters looks like:
chrome://selenium-ide-testrunner/content/selenium/TestRunner.html?test=file:///c:/testing/MyTestSuite.html&auto=true&multiWindow=true&userExtensionsURL=http://localhost/user-extensions.js,http://localhost/ui/my-ui-map.js&close=true&[other self defined parms]
We can see Selenium passed parameters by chrome URL for input. We can add more self defined params by modify Selenium-IDE code.
If we can convert all parameters in JAVA to chrome URL parameters, it's possible to let JAVA invoke Selenium-IDE.

OUTPUT: one output choice provided by S-CORE is using POST data when Selenium closed. It required you create a server side receiver.
One better solution is S-IDE save run snapshot/result/log runtimely to file system directly. We treat these important data as output.

For offical docs about IN&OUTPUT, refer to http://seleniumhq.org/projects/core/usage.html

2. 'IN' Wrapper in JAVA
We create a Java Object as a chrome URL paramters wrapper, simple like:
public class SeleniumRequest implements Serializable {
 private String test; 
 private String auto;
        private String multiWindow;
...
        public String getAuto() {
  return auto;
 } 
 public void setAuto(String auto) {
  this.auto = auto;
 }
...
}
3. 'OUTPUT' Wrapper in JAVA
We also create a Java Object as atomic run result wrapper, simple like:
public class SeleniumResult implements Serializable {
 private int testRuns; 
 private int testFailures; 
        private String resultSummary;
 private String logFilePath;  
...
        public String getResultSummary() {
  return resultSummary;
 } 
 public void setResultSummary(String resultSummary) {
  this.resultSummary= resultSummary;
 }
...
}
Detailed run results are saved on file system by S-IDE. logFilePath is the path for their index file.

4. SeleniumJRunner in Java
Now, we can define a very simple & generic interface for run S-IDE in Java.
public interface SeleniumJRunner {
      public SeleniumResult run(SeleniumRequest request); 
}
We assume this run API is sync mode, which means run() will be blocked in Java thread until S-IDE finished run and generate OUTPUT.

5. SeleniumResultParser.java
S-IDE saved all results in file system, we need a Java class to parse file content and set to SeleniumResult object. This is part of SeleniumJRunner implementation logic. To do html file parser in Java, there are many opensource lib. You can use Nekohtml.

6. SyncExecutor.java
Since S-IDE is an external process for Java. We need launch it with parameters from Java in sync mode. Usually, JAVA API Runtime.getRuntime().exec() meets basic requirement. However, we need a timedout mechanism and safely execution which Runtime.getRuntime() doesn't provide. We create a powerful but simple SyncExecutor util. For related topic, refer to how to safely execute process from java

7. Launch Selenium with profile isolation on the same machine
It is super Firefox can run multiple instances with session/cache isolation concurrently on the same machine by Firefox Profiles mechanism.
We need to add -p ProfileName -no-remote parameters to Firefox cmdline.
For multiple Firefox profiles run together, refer to http://clan.yo2.cn/run-multiple-firefox-profiles-simultaneously.html

8. There is critical issue for launch Chrome TestRunner in cmdline mode
User may encounter weird issue if launch Chrome TestRunner in cmdline like firefox.exe -chrome "chrome://selenium-ide-testrunner/content/selenium/TestRunner.html..." . It's hard to resolve. In JRunner, we must choose a workaround substitution.
For solution, read topic: http://clearspace.openqa.org/message/51801#51801

Friday, November 7, 2008

Build a regression automation testing framework based on Selenium FIT mode

When company only has 100 regression test cases written by Selenese, QA steps to do regression tasks by Selenium FIT mode:
1) Organize test cases files with suites files on local driver or shared driver
2) Open Chrome TestRunner in Firefox
3) Import test suites address in file sytem, click run
4) Monitor and wait for run finished, manually collect run result and write a run report with generic result info.

Assume your company business's growth and you have 1000+ regression test cases.
How to execute these cases in a short time and generate report with detailed enough info automatically?
0) All QA upload and maintain test cases on a central portal.
1) Choose test cases you want to kick off regression from case repository
2) Specify necessary parameter for regression and kick off
3) A scalable machine matrix in backend begin to do automation run parallelly. There are also multiple instances running simuteniously on same machine. Each instance used Selenium FIT engine. The run snapshot/result/log are stored into filesytem/DB runtimely by above instances called Agent.
4) When all run finished, a report can be generated from file sytem/DB.

It's feasible to implement such a system with Selenium FIT mode.

Comparing to similar system based on S-RC+S-GRID:
1) No need proxy server, more lightweight framework. No need precompile like .java test case source.
2) Firefox Chrome TestRunner is more stable and faster than RC Runner. It can bypass many issues which RC can't resolve. Chrome XPCOM APIs is very powerful for develop Selenium new features.
3) User only need to know how to create a Selenese test case, no other skill requirement.

Thursday, November 6, 2008

FIT mode best choice: running Selenium with Firefox Chrome TestRunner

I don't think Selenium-RC is the best choice for QA who does feature testing & regression testing with blackbox style, esp. those who doesn't have programming background.

S-RC(JAVA) disadvantages for blackbox QA/regression testing:
1) programming skills trainning cost for QA
2) test code complexity for maintenance
3) bad HTTPS/SSL page support
4) popup/alerts make automation stuck, require an autoclick alerts mechanism
5) not stable and with weird issues caused by Proxy Server
6) not lightweight tools, need setup environment
7) still need do 2nd around development to integrate with regression distributed system(even if S-GRID).

FIT mode is familiared by QA. There has 3 ways:
1) deploy Selenium CORE/TEST on testing server
2) MS IEHTA with test case repository anywhere
3) Firefox Chrome by Selenium-IDE with test case repository anywhere

For 1), some company has restriction to deny to do deployment
For 2), IEHTA is unstable and has critial issues such as multiwindow popup,xpath slowness etc. It's also hard to provide a session/cache isolation solution for multiple instances running simultaniously on one machine. It's also hard to create a recorder for IE.

I think running Selenium with Firefox Chrome TestRunner is the best choice for FIT mode.
1) Selenium-IDE is a good tool with recorder and still can do huge improvements.
2) Stable and well support HTTPS. Well support multiwindow.
3) multiple selenium running simultaniously on same machine with session/cache isolation by Firefox profiles mechanism
4) set FF preferences to let Selenium not stuck(click out popup/alerts)
5) save run snapshot/results/log to local file system other than postUrl solution
6) No need any proxy server. No need any additional installation and configuration.
7) Opensource Firefox platform is developer friendly. Firefox Chrome's XPCOM APIs can support us to implement all kinds of selenium features.

However, the bottleneck for openqa's FIT mode(Esp. Selenium-IDE) not become enterprise usage:
1) Selenium-IDE doesn't save down detailed enough snapshot/results/log to local file system which is the significant requirement for enterprise tools. Many other significant requirements also haven't been implemented.
2) FIT mode doesn't provide neccessary development SDK. We can build our enterprise test case maintenance system with GUI/webflow, parallel execution system with distributed infrastructure, result reporting system with DB/file system. However, we need SDK APIs to integrate Selenium FIT engine into these systems.

Most of developers are contributing for S-RC product on community. I hope openqa can also push Selenium-IDE FIT product line for enterprise usage.