Currently Browsing

ASP.NET

Ranorex – is this tool the tester heaven?

What is Ranorex? Is this a medicine? 🙂

Ranorex is an automated testing tool which provides testing of Microsoft desktop apps, webpages and mobile applications. It supports wide range of technologies like .NET, WFA, WPF, Java, HTML5, Flash, iOS, Android, Windows apps (hybrid and native) and so on. You can perform cross-browser, data-driven, automated functional, regression, automated GUI and keyword-driver testing. The Ranorex software pack can be classified into a few big parts. Ranorex Studio is the main section. Ranorex Studio contains the main tools like Ranorex Recorder, Ranorex Repository and RanoreXPath. In this post we will introduce them generally in different sections.

Ranorex Studio

Ranorex Studio is the heart of the Ranorex ecosystem. If you are familiar with Microsoft’s Visual Studio you will know immediately how to use it. It has the same layout like Visual Studio 2008/2010.

Main view of the Ranorex studio

Main view of the Ranorex studio

Selenium – How to check if an element has focus

Problem:

We have a contact form with Name, Email and Comment fields, and if invalid data is entered to the fields, the validation system will highlight that field and it will be focused, so the user can change it quickly. In our tests we want to check if the proper field gets the focus.

<div class="contact-form">
    <label> Name </label>
    <input id="contact-name" type="text" />
    <label> Email </label>
    <input id="contact-email" type="text" />
    <label> Comment </label>
    <input id="contact-comment" type="text" />
</div>

(this is just an example code, and not a functional one)

Solution:

Selenium suggest to use css selectors, so we will start with that. To see if the element has the focus we will use css pseudo-class “:focus” and check if an element is present like this:

Assert.IsTrue(selenium.IsElementPresent("css=#contact-name:focus"));

This looks quite nice and easy, but you may encounter some problems with it. The element #contact-name can be found, but #contact-name:focus can not. In this case we have to think outside of the box, and come up with another solution. We can use the Javascript DOM locator to get the element that is selected (has focus), and compare it to the element we expect to have focus:

Assert.AreEqual(selenium.GetElementIndex("dom=document.activeElement"),
selenium.GetElementIndex("css=#contact-name"));

Solution for Selenium IDE Export to C# problem

When using the Selenium IDE to generate C# tests users get the following error “Suite export not implemented for the cs-rc formatter”:

This happens because there is an error in the code that can’t convert from the default HTML Format to C#. The workaround is to go to Options -> Format and then select C# – Selenium RC. Once converted you don’t need to export anything you can just save it or copy paste it to your C# test.

With this workaround you can also export existing saved selenium test cases from HTML or any of the others to C#. Just open up the saved test case and then switch to C# in Options -> Format