Tuesday 12 March 2013

Taking ScreenShots

The hareness allows you to take screenshots for your Test Case(s)

There are 3 methods you can use:
  1. takeScreenshot()
  2. takeScreenshot(String imageName)
  3. takeScreenshot(String imageName, String caption)
Now lets use all the above methods in the test case we created.































ScreenShots In Test Results

The hareness when it generates the results of the test case(s) using the JUnit style will link all screenshots related to a test case. 

Navigate to index.html in the RegressionTestHarness/results/junitreports directory and click on the package that the test case belongs to.















Now click on the View link for the test case to view the images associated with it.












Finally, you will now be presented with a jquery slide show of all images that have been taken with the test case. You are able to play/pause the slideshow, navigate to the previous/next image(s) and also each image will display the prefix (Same as annotation) of the browser it was taken from. Also each image can have an optional caption associated with it.




Custom Firefox

The framework allows you to use a custom profile using two options. For both ways we need to set the use.profile property in config.properties to yes

Option 1

Lets create a profile named Selenium on the pc that were running the harness on.
I followed the instructions here.

When creating the profile on my computer I specified Choose Folder and created a folder named Selenium as my storage location.

I recommed loading the profile and making the following adjustments.
























Now set the profile.name property in config.properties to Selenium.
From this point onwards the hareness will use the profile named defined by profile.name when testing the firefox browser.

Option 2

Using a firefox profile directory that has not been created on the pc that were running the framework on. Follow the instructions here but make sure you select Don't Delete Files as we are going to move this folder shortly. 

Navigate to the location of the Selenium directory and MOVE this folder to a desiable location.

Now set the profile.directory property in config.properties to the absolute(escaped) path to the top level of the firefox profile directory we have just moved.

From this point onwards the hareness will use the directory defined by profile.directory when testing the firefox browser.


Test Case Browsers

You can choose which browsers to run for each Test Case ie each individual *.java file.

Valid Browser Annotations are as follows
 

Annotation Description
@Browsers({ "CH" }) Run Test Case using the Chrome browser
@Browsers({ "IE" }) Run Test Case using the Internet Explorer browser
@Browsers({ "FX" }) Run Test Case using the Firefox browser
@Browsers({ "ALL" }) Run Test Case using Firefox,Internet Explorer and Chrome browsers
@Browsers({ "CH","IE" }) Run Test Case using Chrome and Internet Explorer browsers
@Browsers({ "CH","FX" }) Run Test Case using Chrome and Firefox browsers
@Browsers({ "IE","FX" }) Run Test Case using Internet Explorer and Firefox browsers

Running Test Cases(s)

Now its finally time to run our test case(s).
Navigate to the RegressionTestHarness directory and run ant

Note: When running either the IEDriverServer/chromedriver for the first time your firewall will ask for permission to allow access, so you should allow access and re-run ant again.

You will now see the Internet Explorer browser open and perfom a google search for "WebDriver API" and click on the search button and then the browser will close.

  
Congradulations thats our test case run via the harness.
Just a recap of the stages:
  • Record Test Case(s) Using Selenium IDE
  • Convert Test Case(s)
  • Fix Compilaton Errors (if any)
  • Specify Configuration
  • Run Test Case(s)

Test Results

The harness will generate the results of the test case(s) run in two styles.
  •  testNG - index.html in the RegressionTestHarness/results directory
  • JUnit     - index.html in the RegressionTestHarness/results/junitreports directory
The testNG results are slightly more complicated to understand, I personally prefer the JUnit style easy to read and understand. But both are provided by the framework.

Configuration

Before we can run our test case(s) we need to set the configuration required by the harness.
Navigate to the RegressionTestHarness\config directory.








The excludes/includes files both are used by the hareness to determine what test cases(s) are to be included or excluded when running the regression pack.  

Each line within these files will be treated as an include/exclude pattern.

The excludes.txt will contain the following exclude pattern: **/com/examples/core/*.*
The above pattern will exclude all files within the core directory

PLEASE ENSURE YOU DO NOT REMOVE THIS DEFAULT EXCLUDE PATTERN

The includes.txt will contain the following include pattern: **/com/examples/tests/*.*
The above pattern will include all files within the tests directory

To run all tests for all packages you will require the following include pattern:
**/com/examples/*/*.*

Finally config.properties contains some properties that we can set.

Property Description Required
use.profile Use a custom firefox profile. Valid values for this property are:"yes","no" No
profile.name The name of the firefox profile, assuming that the profile has been created using "firefox -ProfileManager" on the pc that the framework will be running on. Yes, only if use.profile has been set.Specify either profile.name or profile.directory
profile.directory The absolute(escaped) path to the top level of a firefox profile directory if it isn't already registered with Firefox on the pc that the framework will be running on
host.url The host URL of the site that you want to test Yes
archive.results Archive test results to the archive directory for historical purposes. Valid values for this property are:"yes","no" No
bit.type The bit type of the pc's OS that the framework will be running on. Valid values for this property are: "64" ,"32" Yes

The purpose of out demonstartion test case contained in Test1.java  was to perfom a google search for "WebDriver API" and click on the search button.
When we converted our exported test we specified that we will test against the Internet Explorer browser.

So in order to run our test case we need to specify the minimum property values required as:

  • host.url=http://www.google.com
  • bit.type=64 (This is the bit-type of the OS im running)
  

Sunday 10 March 2013

Conversion Explained

Lets view the orignal java file that Selenium IDE exported for us


Now lets view the java file that the conversion has generated for us

The conversion process will firstly if it already does not exist create our package, which in this case is called com.example.tests

Secondly,creates a java file that is compatable with the hareness of the project with our orignal selenium commands that are present in the orignal exported file, which in this case were

                selenium.type("id=gbqfq", "WebDriver API");
                selenium.click("id=gbqfb");


Finally, It places an annotation at the class level defining what browser that this test file should run against.