Automation Tools

Generating HTML results for Selenium RC scripts 

Here is an example of Google search and the results are saved as a HTML file:

Code for GoogleSearch.cs file:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;
using System.Diagnostics;
namespace SeleniumTests
{
[TestFixture]
public class GoogleSearch
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void GoogleSearchTest()
{
int stepsPassed = 0;
int stepsFailed = 0;
string TestCase = "Google Search";
Results.writeTCHeading(TestCase);
selenium.Open("/");
selenium.Type("q", "seleniumwiki");
selenium.Click("btnG");
selenium.WaitForPageToLoad("30000");
try
{
Assert.IsTrue(selenium.IsTextPresent("Selenium Wiki"));
Results.passMSG("The text Selenium Wiki is present on the search results page"); //pass message
stepsPassed++;
}
catch (AssertionException e)
{
verificationErrors.Append(e.Message);
Results.failMSG("The text Selenium Wiki is not present on the search results page"); //fail message
stepsFailed++;
}
//write report for the total number of steps passed and failed.
int totalsteps = stepsPassed + stepsFailed;
if (stepsFailed > 0)
{
Results.writereport(TestCase + "test case failed - " + stepsFailed + " of " + totalsteps + " step(s) FAILED.");
}
else
{
Results.writereport(TestCase + "test case passed - " + stepsPassed + "  step(s) PASSED.");
}

More...

By Pavandeep Puddupakkam on February 4, 2011 | Automation Tools, Selenium RC | A comment?
Tags: , ,

Selenium captureEntirePageScreenshot 

Using selenium you can capture the screen shot of the pages when running the selenium script. This is useful when you want to capture the screen shot of the page where you have a failure/ error.

selenium.CaptureEntirePageScreenshot("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\test.png", "");

More…

By Pavandeep Puddupakkam on | Automation Tools | A comment?
Tags: ,

WebDriver Selenium IDE plugin 

This is a plugin for Selenium IDE that adds WebDriver backed Selenium formatters, which allows users to take advantage of WebDriver without having to modify their tests to use the new API.

More…

By Pavandeep Puddupakkam on December 1, 2010 | Automation Tools | A comment?
Tags: , ,

Unit Test Adapter threw exception:URI formats are not supported 

I am using Selenium RC in Visual Studio 2010 – Test Project framework. When I try to run the scripts from the share drive I get the following error “Unit Test Adapter threw exception: URI formats are not supported”
The solve the problem please follow the steps:
Double click on Local.testsettings which is under the Solution Items of Project
Test Settings window is displayed. Click on the Deployment link.
You will see a checkbox Enable Deployment. Select the checkbox and click Apply.
The Test Settings can also be found under TraceAndTestImpact.testsettings and just follow the same steps.
Now run your scripts.

By Pavandeep Puddupakkam on November 22, 2010 | Automation Tools, Visual Studio 2010 | A comment?
Tags:

Getting the Browser details in Selenium 

There are times when you would like to get the browser details when running the selenium scripts. Here is the selenium script that you can use to to get browser details.

String a = selenium.GetEval("navigator.appCodeName");
Console.WriteLine(a);
String b = selenium.GetEval("navigator.appName");
Console.WriteLine(b);
String c = selenium.GetEval("navigator.appVersion");
Console.WriteLine(c);
String d = selenium.GetEval("navigator.cookieEnabled");
Console.WriteLine(d);
String e = selenium.GetEval("navigator.platform");
Console.WriteLine(e);
String f = selenium.GetEval("navigator.userAgent");
Console.WriteLine(f);

More…

How to verify the image height and width in Selenium 

Its now easy to verify the image height and width of an image on a web page using Selenium. Here is the code that verifies if the height of the image is between 595 and 686 px and width is 230 px.

decimal height = selenium.GetElementHeight("//img[@class='heroImageMain']");
decimal width = selenium.GetElementWidth("//img[@class='heroImageMain']");
Console.WriteLine("Hero Image dimensions:- " + width + " x " + height + " pixels.");
if ((height >= 595 && height < = 686) && (width == 230))
{
console.writeline(Testcase + "Hero image dimensions are invalid -> " + +width + " x " + height + " pixels.");
}

More…

By Pavandeep Puddupakkam on October 13, 2010 | Automation Tools, Software Testing, Visual Studio 2010 | A comment?