(This post was written by Wen Dong & Hua Cheng from the UFT R&D Team)
Are you looking for a powerful, lightweight, developer-oriented automation tool for your continuous test-driven development project? Look no further, LeanFT is your answer.
LeanFT is a new functional testing framework built specifically for continuous testing and continuous integration. What’s really cool is that LeanFT (as well as as Unified Functional Testing) fits nicely into the development ecosystems (such as Microsoft TFS, GIT, and Subversion), IDEs (Eclipse & Visual Studio), and unit testing frameworks (NUnit and JUnit). With LeanFT, you can write the test in Java or C# programming language and still have access to Web/Windows-based technologies (such as SAPUI5).
Now you can take advantage of LeanFT to automate SAPUI5 applications. This blog post demonstrates how to use LeanFT to write a simple automation test with NUnit to test the SAPUI5 ListBox in just three steps. I am going to show you how to use the LeanFT Object Identification Center to generate C# code for a SAPUI5 control and use that to complete a test.
Before you start, make sure the following are installed:
- Visual Studio 2012 or 2013 (any edition except “Express” is good)
- LeanFT - select the “full installation” option in the installation wizard, which includes the SDK, the runtime engine, and a plugin for Visual Studio (make sure to mark the relevant installed Visual Studio version)
- Optional: The Nunit framework. If you would like to use MSTest, no additional installation is required
Steps
- Create your LeanFT NUnit project. LeanFT is integrated into Visual Studio 2012 and 2013 via an extension. You can create a LeanFT NUnit Project by clicking menu File > New Project and selecting the Templates > Visual C# > Test category. The LeanFT extension creates a Nunit-based project with template code.
Note: In the reference of the project, ensure the NUnit reference is valid.
- Spy on your Application-under-test (AUT) to generate description code of your object. The LeanFT Object Identification Center is similar to UFT’s Object Spy, but also provides additional capabilities.
Note: Ensure that the LeanFT Runtime Engine is running as seen above, otherwise manually launch it from the start menu or from the LeanFT menu within the Visual Studio.
- Launch your Internet Explorer, Chrome, or Firefox browser and find your SAPUI5 AUT. (Make sure you open your browser only after the LeanFT runtime engine started). Below is a sample web page showing a demo SAPUI5 application with a SAPUI5 list boxes.Launch the Object Identification Center from the tool bar of Visual Studio.
- Click the button (shown below) to spy on your AUT, in our case: SAPUI5 ListBox
- You can fine tune your object properties in the “Edit" mode to get the exact object description you need, as shown in Figure 7. After you change the selected properties or their values, it’s a good idea to click the Highlight button , which marks the corresponding object in the AUT, so you can see if your description gives you a unique identification of the desired object.After pasting the code generated by LeanFT, the programmatic description code will look something like the code below:
- The Describe method describes the properties of the browser object
- ListBoxDescription class describes the properties of the IListBox object
- TagName, Name, and Index are the properties of IListBox. They are selected from above in the Object Identification Center dialog (seen above)
browser.Describe<IListBox>(new ListBoxDescription
{
TagName = @"DIV",
Name = string.Empty,
Index = 5
});
Now you can continue to write your test case using the object details set in the Object Identification Center using the Generate Code to Clipboard option mentioned above. Below is a simple case that selects the item “Hallo2” in the list.
Take a look at the comments to help you follow the example:
var browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
try
{
//Navigate to the AUT website.
browser.Navigate("http://<your-SAPUI5-AUT>");
//Describe the object with the generated code from the Obj ID Ctr
var uiList = browser.Describe<SAPUI5.IListBox>(new SAPUI5.ListBoxDescription
{
TagName = @"DIV",
Name = string.Empty,
Index = 5
});
//Perform a selection on the list.
uiList.Select(@"Hallo2");
//Verify that the correct item is selected.
Assert.AreEqual("Hallo2", uiList.SelectedItems[0].Text);
}
catch (AssertionException e)
{
Reporter.ReportEvent("Verify SAPUI5 ListBox failed.", "Failed during validation", Status.Failed, e);
throw;
}
finally
{
browser.Close();
}
And you can take advantage of additional functionality using the property “ControlType”. For example:
if (uiList.ControlType == SAPUI5.ControlType.Mobile)
{
uiList.Mobile.More();
}
That's it.
With just three steps, we created a SAPUI5 automation test. It’s extremely easy. Now you can start your own.
Thanks to Wen and Hua for providing this article!
Additional LeanFT Sources:
LeanFT Java SDK
LeanFT.NET SDK
SAPUI5 .NET code examples
SAPUI5 Java code examples
Feel free to leave a comment in the box below.