Tutorial ranorex
Upcoming SlideShare
Loading in...5
×
 

Tutorial ranorex

on

  • 1,916 views

 

Statistics

Views

Total Views
1,916
Slideshare-icon Views on SlideShare
1,916
Embed Views
0

Actions

Likes
1
Downloads
25
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Tutorial ranorex Tutorial ranorex Document Transcript

    • Ranorex Tutorial Spirit Du March 27th, 2007 Ver. 1.1.4Contents About this Document....................................................................................... 1Ranorex Installation and Setup ...................................................................... 1Tutorial – Test SimpleCalculator using Ranorex............................................ 2About this Document NUnit framework is very useful for testing a small piece of programwithout GUI. But how do we test the correctness of GUI interactions? Thisdocument introduces a tool Ranorex, which can “simulate” userinteractions and perform assertions. We will integrate this tool with theNUnit framework to test the SimpleCalculator developed in yourhomework.Ranorex Installation and Setup Ranorex is a Windows GUI test and automation Library for C++,Python, and the .Net languages. The user (e.g. the software tester)should use the functionalities of the programming languages like Pythonor C# as a base, and enlarge it with the GUI automation functionality ofRanorex. Before starting this tutorial, it needs to get the Ranorex installerform the URL: http://www.ranorex.com/download/ Download the free edition and execute the installer with defaultsettings. After installation 1 , copy the file: RanorexCore.dll 2 from [RanorexLocation] 3 BinNet2.0 and then paste to [Windows] 4 system32 asglobal library cache 5 .1 You don’t have to install the Ranorex. But you do need to do this set up step byyourself because there is no such file in system32 folder in the computer lab.2 Any project developed with Ranorex will run with RanorexCore.dll3 The default location is C:Program FilesRanorex-1.1.04 The default location for Windows XP/2000 is C:WinNT5 It will facilitate the development without denoting the location of RanorexCore.dll ineach project.Windows Programming Tutorial – Ranorex - 1-
    • Tutorial – Test SimpleCalculator using RanorexStep1.Open the existing Visual Studio Solution which contains your calculator. As shown in Figure 1, SimpleCalculator is the project developed in the previous homework which is contained in Windows Programming solution. Figure 1 The Solution contains SimpleCalculator projectStep2.Add a class: GUITester into existing project. Figure 2 Add a new class: GUITesterStep3.Add RanorexNet references 6 Figure 3 Add Ranorex referenceStep4.Add using declarations Open the GUITester.cs and add the following two declarations.6 Default location: C:Program FilesRanorex-1.1.0BinNet2.0Windows Programming Tutorial – Ranorex - 2-
    • using NUnit.Framework; using Ranorex;Step5.Declare a test fixture and a member data This is similar to the previous tutorial; add a test fixture attribute before the class declaration. Then, change the visibility to public and add a new field: _testee. namespace SimpleCalculatorGUITests { [TestFixture] public class GUITester { Form _testee; } }Step6.Use the Ranorex to activate SimpleCalculator in setup method 7 . Add a member method, setup(), into GUITester class. Note that the [SetUp] attribute and the value of application string must be the same as the title (name of the .exe file) of your simple calculator. [SetUp] public void setUp() { // Project Name or executable file name string application = "SimpleCalculator"; Application.SleepTime = 50; Mouse.MoveTime = 10; Application.Start(application); _testee = Application.FindFormTitle(application, SearchMatchMode.MatchExact, true, 2000); Assert.IsTrue(_testee != null); }Step7.Add a tear down member method to close the activated form In the previous tutorial, it is not necessary to declare the tear down method, because garbage collection is automatically performed. But in this tutorial, a tear down method is required to close the application (form) activated by the set up method.7The assertion failed in setup() that will skip the runTest() and then call teardown()directly.Windows Programming Tutorial – Ranorex - 3-
    • [TearDown] public void tearDown() { _testee.Close(); }Step8.Add a member method to control the mouse 8 Ranorex offers several ways to find 9 GUI widgets (controls) on the screen and also offers the control of mouse and keyboard. Now add a member method as below which can move the mouse pointer to the target control and then click on it. public void moveToControlAndClick(Form form, string text) { Assert.IsTrue(form != null); Control control = form.FindChildText(text); Assert.IsTrue(control != null); Mouse.MoveToControl(control); Mouse.ClickControl(control); }Step9.Write a test script Now we can write test cases by using the above moveToControlAndClick method. Add a new member method with the following codes to automatically perform the user’s actions 10 : 1+12-3-4*5/6=8 The same as the setUp() method, if there is any assertion failed in themoveToControlAndClick() method, the NUnit will skip the remaining codes and thencall tearDown() directly.9 Ranorex provides several methods: by object name or id, text and class name. Formore information, please refer to the Ranorex document.10 Design your actions sequence for practice if you have more time after finishing thetutorialWindows Programming Tutorial – Ranorex - 4-
    • public void runScripts() { moveToControlAndClick(_testee, "1"); moveToControlAndClick(_testee, "+"); moveToControlAndClick(_testee, "1"); moveToControlAndClick(_testee, "2"); moveToControlAndClick(_testee, "-"); moveToControlAndClick(_testee, "3"); moveToControlAndClick(_testee, "-"); moveToControlAndClick(_testee, "4"); moveToControlAndClick(_testee, "*"); moveToControlAndClick(_testee, "5"); moveToControlAndClick(_testee, "/"); moveToControlAndClick(_testee, "6"); moveToControlAndClick(_testee, "="); }Step10. Add assertion integrated with NUnit Framework Now we would like to make sure the result of the previous calculation is 5. Add a member method with [Test] attribute (so that it can be identified by UnitRun add-in) as follows: [Test] public void runTest() { Assert.IsTrue(_testee != null); runScripts(); Control control = _testee.FindControlName("_resultDisplayer"); Assert.IsTrue(control != null); Assert.AreEqual(control.Text, "5."); }Step11. Run the unit test through UnitRun add-in While the unit test is under running, please do not move your mouse or click any key. Any event generated by mouse moving or clicking will cause the test failed.Windows Programming Tutorial – Ranorex - 5-
    • Figure 4 Run unit test through UnitRun add-in. Figure 5 NUnit activate simple calculator through Ranorex and assert the value. – End Tutorial –Windows Programming Tutorial – Ranorex - 6-