9/19/2012

Running JavaScript with Selenium RC

If you want to run longer javascript code with the selenium java api, you’ll need to use the selenium.getEval(String jsCode); method. Also you have to consider, that only the last line of the javascript code is returned. For Example, if you have a TextModifier Object in your page which has the Method inverseString(StringToInverse) , a HTML-Element with known id, which name is “dlroW” and you’ll run the following command: The result will be Hello World. For not executing javascript and only injecting javascript into the page use the runScript(String jsCode) method of selenium.

Hudson job running Selenium RC tests with TestNG Parameters

I really can recommend to execute tests under the testng framework. It provides optional parameters and execution of test suites in an easily understanding way and allows to modify the style of the reports through a css file. Optional parameters also allows you to run tests within Eclipse without setting them (then the default value is used, see below)For my Tests I used a superclass containing the “setUp” method, which is executed just before each testclass:
As you can see the parameters “seleniumhost” etc. are optional. If one of them isn’t set, then the default value is used, e.g. “localhost. You want to insert all your testclasses into your testsuite often named “testng.xml”. There you also can set values for the parameters: For running the testsuit testng.xml you just need to type "java org.testng.TestNG testng1.xml" into your command prompt. For the execution of your tests by hudson, you’ll need to create a new hudson job, build it once, then copy your tests into the established directory of the job (you’ll find it at usr/.hudson/jobs ) and write a ant file, which can be executed by hudson.
An Ant file has different targets, which can or can’t be executed separatly, sequential. You can define them in the hudson job configuration. Your ant file could look like this: For publishing results I can recommend to use testng-plugin and/or HTML Publisher Plugin for Hudson.

Test Design Methods

Notes from OOP 2012, talk by Peter Zimmerer:
If you are limited in time, what you always are, and you want to test the User Interface, Markov Chains resulting in trees with percentages of usage, can help you to prioritize parts of the system for testing. Finding the right test cases is always a big problem. In the following you can see an outline of methods, which can lead to an idea or directly to a test case:

Black box:
  • requirement / use case based testing
  • traceability matrix
  • crud
  • flow testing
  • scenario testing
  • soap opera testing
  • user / operational profiles
  • frequency and priority / statistical (markov)
  • feature functions interfaces
  • design by contract
  • equivalence class partitioning
  • boundary value analysis
  • classification tree method
  • state based testing
  • cause effect graphing
  • decision tables, decision trees
  • combinatorial testing ( orthogonal arrays, pair-wise, n-wise)
  • time cycles 
Grey box:
  • dependencies relations between classes, methods or components, services, application, system
  • communication behavior
  • trace or protocol based testing 
White box:
  • control flow-based
  • statements (c0), nodes
  • branches (c1), transitions, links, paths
  • conditions, decisions (c2,c3)
  • elementary comparison mc/dci
  • interfaces (s1,s2)
  • cyclomatic complexity
  • read / write acces 
  • def / use criteria 
With ongoing time always check the quality of the tests. Positiv valid test cases vs. negative invalid test cases. You should also perform fault based testing including risks, attacks, errors, bug patterns and exploratory testing.