Quick Start

From QAliber

Jump to: navigation, search

This document will take you through the development and execution of an automated test scenario using QAliber. the visual studio (2005) project for this tutorial available here A video for this tutorial can be found on our web site. This is only a quick start, if you want to get more in depth on how to develop test cases, you can refer to the [Getting Started] article.

Contents

QAliber Visual Studio Plug-in Overview

After installing QAliber Visual Studio Plug-in, and launching visual studio, you will see something like this QAliber Visual Studio Plugin
As you can see there are 3 supplemental features provided by the QAliber VS plug-in:

  1. New menu “UI Testing” was added, with start/stop Record buttons, and UI Control Browser launch button. Click it to open the GUI browser.
  2. The UI Control Browser, expose to you a tree structure of all current available UI controls. You can drill down the GUI elements of each application by expanding the control. When a control is selected you can see its properties in VS properties window. You can learn more on the UI Control Browser here, but for now just keep in mind the UI Control browser is the tool which lets you explore all the GUI elements of your SUT.
  3. New template for test project.

Let’s create a new test project by using the template from File -> New -> Project -> Visual C# / Visual Basic -> TestCasesPackage.

Test Project Structure

The blank project provides you the infrastructure to quickly develop a test and deploy it to the QAliber Test Builder. MyTestCase.cs file is where the recorded (and edited) C# code, which drives your automation, is written. Currently you should simply note 2 things: The attribute above the class

[QAliber.TestModel.Attributes.VisualPath("My Test Cases")]

Provides the name exposed to the user in the QAliber Test Builder. Second thing to note is it inherits the TestCase, besides providing access to test logic inherited from TestCase, it also tells the QAliber Test Builder that this class is a test case to run, and can be integrated into a test scenario as a single step.
Additionally three new libraries should be referenced by your test project:

  • Qaliber.Engine: The core engine for GUI interaction
  • Qaliber.Logger: The entire tool set you'll need to log your test during runtime.
  • Qaliber.TestModel: The integration of the test with the QAliber framework API.

For more thorough explanation about the template click here

Coding

Setup and Record

Test Case constructor should provide information about our test, which will be available to the user using it. Special consideration should be given to the expectedResult, by default the expected result is set to TestCaseResult.None. You should decide if this test case has to Pass / Fail / None (don’t care). See log documentation for more information. At this tutorial you’ll automate the Calculator application, test that it adds 2 single digits correctly, and you expect it to pass each time, so your constructor should look like this:

public MyTestCase()
{
    name = "Test Sum of 2 Digits";
    description = "Verify 2 digits are added in calc correctly";
    expectedResult = TestCaseResult.Passed;
}
  • Launch windows calcuator application.
  • Verify your active document in Visual Studio is MyTestCase.cs (the generated code from the recording will be in this class)
  • Press record (avaiable from the UI Control Browser or use Ctrl+Shift+4) , and while recording, on the calc application click ‘2’ ‘+’ ‘3’ ‘=’, then stop recording (Ctrl + Shift + 6)
  • New code similar to this should be added (if under windows XP):
#region Temporary Recording Code
private void RecordedTest1()
{
   UIAButton @button2 = Desktop.UIA[@"Calculator", @"SciCalc", @"UIAWindow"][@"2", @"Button", @"126"] as UIAButton;
   @button2.Click(MouseButtons.Left, new Point(21, 11));
   UIAButton @button = Desktop.UIA[@"Calculator", @"SciCalc", @"UIAWindow"][@"+", @"Button", @"92"] as UIAButton;
   @button.Click(MouseButtons.Left, new Point(24, 16));
   UIAButton @button3 = Desktop.UIA[@"Calculator", @"SciCalc", @"UIAWindow"][@"3", @"Button", @"127"] as UIAButton;
   @button3.Click(MouseButtons.Left, new Point(21, 14));
   UIAButton @button_1 = Desktop.UIA[@"Calculator", @"SciCalc", @"UIAWindow"][@"=", @"Button", @"112"] as UIAButton;
   @button_1.Click(MouseButtons.Left, new Point(19, 11));
}
#endregion

Lets take a moment to review the syntax.

  • Desktop.UIA - The root of all GUI elements identified by UI automation
  • [@"Calculator", @"SciCalc", @"UIAWindow"] - An indexer of the format [control name, control class name, control id], which identifies the calculator's main window
  • [@"2", @"Button", @"126"] - An indexer of the format [control name, control class name, control id], which identifies the button '2' inside calculator's main window
  • The indexers return a UIControlBase type, so QAliber casts it to UIAButton
  • The click actions are pretty straightforward

QAliber record is action driven. A control is identified when the user interacts with it, in this case the button was clicked at a certain point (Upper left of the control is 0,0).

Lets run the test of what we just recorded, in the Body() function add a call to our recorded function:

public override void Body()
{
    RecordedTest1();
}
  • Make sure the calc application is up
  • Compile and run the solution.

Verification

Ok you should see the test run automatically, the mouse cursor move and click calculator as expected. Now lets add verification of the result: In the upper right corner of the UI Control Browser you have a cursor, this allow you to target specific control that you want to work with. Click and drag it to the result text box of the calc application or hover the result text box and use (Ctrl + Shift + 1) this way is helpful mainly when working on pop ups and less visible controls. The control browser now shows a tree path to the calculator's result edit box and the properties of the control are available for you to explore, for now lets focus on these properties:

  • ControlType – So you’ll know which type of object to create.
  • Text – this Editbox property reveals the result you want to verify.
  • Code Path – the code which identify the control on runtime.

Write new function with the signature private void VerifySum(int dig1, int dig2) Copy and paste the UIEditBox codePath, create a new UIEditBox object which refers to the Code Path, use casting. Parse the result to int (note the text has ‘. ’ in the end you should remove) and add and if condition to verify the text equals the sum of the digits.

private void VerifySum(int dig1, int dig2)
{
    UIAEditBox resultBox = Desktop.UIA[@"Calculator", @"SciCalc", @"UIAWindow"][@"", @"Edit", @"403"] as UIAEditBox;
    string result = resultBox.Text.Replace(". ", "");
    if (int.Parse(result) == dig1 + dig2)
    {
        QAliber.Logger.Log.Default.Info("Result was as expected: " + (dig2 + dig1));
        actualResult = TestCaseResult.Passed;
    }
    else
    {
        QAliber.Logger.Log.Default.Error("Result was not as expected.", "Found: " + result + " but expecting " + (dig2 + dig1));
        actualResult = TestCaseResult.Failed;
    }
}

Add a break point on the first line of the function, in Body() after the call RecordedTest1() call VerifySum(2,3), debug the application, the GUI interaction is done, step to make sure the result is as expected.

Parameterize the Test

Since you don’t want to write different test for each 2 digits combination, you have to add parameters. Parameterizing in QAliber is done by exposing the test parameters as public properties in your test case class

  • Add using System.ComponentModel;
  • Add 2 parameters and expose them as properties.

Use [DisplayName()] and [Description()] to provide more information to the user of the test in [QAliber Test Builder].

private string firstDig ="0";
 
[DisplayName("First Digit")]
[Description("Single digit (0-9)")]
public string FirstDig
{
   get { return firstDig; }
   set { firstDig = value; }
}
 
private string secondDig ="0";
 
[DisplayName("Second Digit")]
[Description("Single digit (0-9)")]
public string SecondDig
{
    get { return secondDig; }
    set { secondDig = value; }
}

After we have parameters, change the recorded code to use our parameters, simply replcae the button name with our parameter:

UIAButton @button2 = Desktop.UIA[@"Calculator", @"SciCalc", @"UIAWindow"][firstDig] as UIAButton;

The name by itself is enough to identify our control. Remember to change the verification call to VerifySum(int.Parse(firstDig) ,int.Parse( secondDig ));

Running our test now will click on ‘0’ ‘+’ ‘0’ ‘=’ , since 0 is the default initialization. To comprehand the parameters and the way they work proceed to the next section, you are done coding.

Documentation and Deployment

Before deploying your tests, you can document the new tests so users will know how to work with it. QAliber documentation is built in the code and done using XML. Help tags and hows is covered here, for now simply add the XML above our class:

    /// <summary>
    /// Calcs sum of 2 numbers.
    /// <workflow>
    /// <verfication>Sum is correct</verification>
    /// <action>Clicks digit var + digit var = </action>
    /// </workflow>
    /// <preconditions>Calc is up</preconditions>
    /// <postconditions>30 in result</postconditions>
    /// </summary>

You can also document the properties (parameters of the test), in the same way. This is how we suggest you should deploy your tests to the QAliber Test Builder:

  • Open the project properties
  • On the application tab rename your assembly to have more meaningful name.
provide name for the test

  • On the build tab change the output path to a folder where you will put all your binaries there.
  • Check the “XML Documentation File” option and put it in the same folder as above.
Changing the output path

That’s it, your done. From here it’s up to the tester to build and run your tests.

QAliber Test Builder Overview

Run the First Test Scenario

Now your in the hat of the tester, and you were asked to verify single digits x + y works on the calculator. Launch the Qaliber Test Builder and lets build our script: Qaliber Test Builder is open, you can click the help from menu to dive into all the features it has to offer, in this quick tutorial we’ll go over the basic stuff only.

  • Click File -> New. A blank scenario is open.

image:QAliberBuilderOverview.png
The screen is divided into 4 main panels, these can be set display / hide and move to you convenient layout.

  1. Left panel is the scenario flow. Displayed as a tree view.
  2. Selected test case / scenario exposed parameters and properties panel.
  3. Test Cases and Macros repository.
  4. Variables, Lists & Tables panel, to parameterize your test.
  • Select the root step (scenario), the panel properties grid for the selected step is open, change the Name property from “unkown scenario” to “Test calc demo”, press Enter or click to leave the field.
  • Looking at the TestCases Repository you should see new folder named “My Test Cases” Remember, this is the visual path class attribute, expand it and you’ll see the “Test sum of 2 digits” TestCase.

image:QAliberBuilderTestRepository.png

  • Right click -> help will show you what the step is expecting to do, as you wrote in the documented help.
  • Now to add it to your scenario, simply drag and drop it over the Test Calc Demo root.
  • Expand your scenario and select the test case we just added.
  • You should see on the parameters panel First Digit and Second Digit, when you select each you should see the description you provided and the bottom of the properties panel.
  • Change the parameters to 4 and 5.

image:QaliberBuilderScenarioEdit.PNG
Make sure calc is open and run the test with the blue play button in the toolbar. See it run automatically and when the test is done the test log is open (configurable), marking your test case passed as expected. Close the log, as we will get back to it later.

Test Cases Repository

Since we want the single calculator application up each time, we need to add 2 test cases. The first will close all calc instances and the secode will launch one, to make sure we have only 1 instance of calc running. To do this you can use some pre made test cases which comes with QAliber, these are an ever growing commonly used actions and tests developed by the QAliber community (which can also be you). For a complete list of all available test cases you can log into our web site here, search for and download steps to extend your repository. What you’ll need for now is already available with the default installation, so lets continue:

  • From the test cases repository drag and drop 2 test cases from System -> Process -> Kill process & Start Process (1 in pic below).
  • Select Kill Process and set the Process Name to calc (2 & 3), use the toolbar “Move up in tree” button and set it as the first step (4).
  • Do the same with Start Process. Select “Start Process” and set the Process parameter to calc. use the toolbar “Move up in tree” button and set it as the second step.

image:QaliberBuilderScenarioEdit2.PNG

  • Run the scenario again. See it closes calc (if open) , open it and interact with the GUI.
  • Before you continue you can save your scenario from File -> Save as “Test1”.

Iterations and Parameters

So far its nice, you can quickly prepare and run a test, but we want to test all options so you now want the test to iterate and add all the x + y options (0 – 9 digits). To do that focus on the variables panel (at the bottom). Switch to lists tab and add 2 lists : “first” and “second”.

Click on the list values (2nd column), in the open dialog “Edit List Items” write in each row digits from 0 to 9. Set “second” and do the same. image:QaliberListEdit.png
Lets think about what we need here. we want our test to iterate on each digit in the first list (1st loop), and for each iteration we want to iterate through the second list and add the 2 numbers (2nd loop). QAliber describes the workflow as a tree view, so loops and conditions are folders for other test cases you want to run in continues loop.

  • Add loop: From Test Cases Repository -> Flow Control -> Loops, drag “For Each Item in List” step into our scenario.
  • Set the “List name” property to “first”.
  • Right click Copy, right click again and Paste (copy into it self), a nested “For Each Item in List” loop was created, change the “List name” to "second".

image:QaliberScenarioEdit3.png

  • Drag and drop the “Test sum of 2 digits” step into the nested loop.
  • We need to change First and Second digit parameter, to the current number in first and second lists, right click first digit and open the variable wizard.
  • In the wizard start click first (the name of list) an intellisens is open to help you complete select first.Current and click submit, you see $first.Current$ is set as the parameter value, it simply states the the current indexed value in the loop, which increases by 1 in each loop.
  • For the second digit simply write $second.Current$ and that's it, you’ve completed parameterizing your scenario.

image:QaliberScenarioEdit4.png
Variable are covered more throughly in the user manual. You can refer to it, and find more information which will help you master the test flow. Before running this scenario lets change some options for this run.

  • Select from menu View-> Options and switch to the Engine tab.
  • Uncheck “Block mouse & keyboard activities from use when simulating them”
    This option will block the interaction when the test run is simulating mouse & keboard activities (and only then so you’ll be able to stop the run…)
  • In our test we enter a loop which will make it difficult (though possible) for us to stop it so uncheck it. And click Ok to close the options dialog.
  • Use Ctrl+Alt+F5 to run our test. Nice, its looping & clicking all the combinations, this may take some time though, since by default QAliber actions are “Humanized”, meaning it move the cursor and wait after actions.
  • Lets stop the run (Ctrl+Alt+F7) and change some options to make it run faster:
  • Go to the options dialog again, select from menu View-> Options and switch to the Engine tab.
  • Uncheck the “Animate Mouse” option.
  • And set the “delay after action (in milliseconds)” to 5.
  • Click OK and rerun the test Ctrl+Alt+F5.
    Remember we set the test run not to block mouse and keyboard, try not to intefere the run.

You can read more about the many features the Builder has to offer in creating and editing test flow in the user guide.

Personal tools