Share this page

# Exercise 1: Create an account

This exercise guides you through automating the process of creating a new Advantage Online Shopping account using UFT Developer.

In this topic:

## Step 1: Launch your IDE

Start by launching the supported IDE of your choice. Once the IDE is open, notice:

- The UFT Developer icon in your system tray. This indicates that the UFT Developer runtime engine is launched.

- The UFT Developer menu in your IDE. Use this menu to access the Object Identification Center (OIC), UFT Mobile, run results, and more.

  Example: (Eclipse)

  The View Last Run Results option is enabled only after you've run a test.

Back to top

## Step 2: Configure UFT Developer

1. Open the Engine and Object Identification Settings from the UFT Developer menu in your IDE, or from the system tray menu (right-click the UFT Developer icon and select Settings).

2. On the Engine tab, under Add-ins, configure UFT Developer to use the Web Add-in only.

Save your changes to restart the UFT Developer runtime engine with the Web Add-in.

Back to top

## Step 3: Create a new testing project

Prerequisite for Visual Studio and NUnit:

Install the NUnit framework. For details about supported versions, see the Support Matrix.

1. Create a new testing project or module using one of the UFT Developer templates for your IDE. Give your project a meaningful name.

   - In Eclipse, use the UFT Developer > UFT Developer Testing Project template.

   - In IntelliJ IDEA, use the UFT Developer Test > Testing project template.

   - In Visual Studio, use one of the Visual C# > Test > UFT Developer xx project templates.

   When using Visual Studio and NUnit

   - If NUnit 2.6x is installed, use the UFT Developer NUnit template.

   - If NUnit 3.x is installed, use the UFT Developer NUnit 3.0 template.

2. Your project is created with a new class, using the standard format of the unit testing framework for the template you selected.

   This class contains a test method with the Test annotation (highlighted in the examples below), which you will use to include the test logic.

   Rename this test method with a more meaningful name.

   For example:

   C#

   The following code is generated using the UFT Developer NUnit template. Sample code may differ when using other templates.

       using System;
       using NUnit.Framework;
       using HP.LFT.SDK;
       using HP.LFT.Verifications;

       namespace UFTDeveloper_Tutorial
       {
       	[TestFixture]
       	public class UFTDeveloperTest : UnitTestClassBase
       	{
       		[TestFixtureSetUp]
       		public void TestFixtureSetUp()
       		{
       			// Setup once per fixture
       		}

       		[SetUp]
       		public void SetUp()
       		{
       			// Before each test
       		}

       		[Test]
       		public   void   MyTest()
       		{
       		}

       		[TearDown]
       		public void TearDown()
       		{
       			// Clean up after each test
       		}

       		[TestFixtureTearDown]
       		public void TestFixtureTearDown()
       		{
       			// Clean up once per fixture
       		}
       	}
       }

   Java

       package com.mycopmany.mypackage;

       import org.junit.After;
       import org.junit.AfterClass;
       import org.junit.Before;
       import org.junit.BeforeClass;
       import org.junit.Test;
       import com.hp.lft.sdk.*;
       import com.hp.lft.verifications.*;
       import unittesting.*;

       public class UFTDeveloperTest extends UnitTestClassBase {

       	public UFTDeveloperTest() {
       		//Change this constructor to private if you supply your own public constructor
       	}

       	@BeforeClass
       	public static void setUpBeforeClass() throws Exception {
       		instance = new UFTDeveloperTest();
       		globalSetup(UFTDeveloperTest.class);
       	}

       	@AfterClass
       	public static void tearDownAfterClass() throws Exception {
       		globalTearDown();
       	}

       	@Before
       	public void setUp() throws Exception {
       	}

       	@After
       	public void tearDown() throws Exception {
       	}

       	@Test
       	public   void   myTest() throws GeneralLeanFtException {

       	}

       }

The following libraries are automatically referenced in the project:

- The UFT Developer library
- The unit testing framework library (such as NUnit or JUnit)

Back to top

## Step 4: Add code to open the Advantage Online Shopping site

In the blank test method, add code to launch the browser of your choice using UFT Developer's SDK for your IDE.

Then add code to navigate to the Advantage Online Shopping URL: http://www.advantageonlineshopping.com.

Tip: The examples below open Google Chrome. If you need to, update the code to launch a different browser.

C#

    //Include the UFT Developer SDK's Web namespace

    using HP.LFT.SDK.Web;

    ...

    [Test]
    public void MyTest()
    {
    	//Launch Chrome
    	IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

    	//Navigate to "Advantage Online Shopping"
    	browser.Navigate("http://www.advantageonlineshopping.com");
    }

Java

    //Import the UFT Developer SDK's Web package
    import com.hp.lft.sdk.web.*;

    …

    @Test
    publicvoidmyTest() throws GeneralLeanFtException {

    	//Launch Chrome
    	Browser browser = BrowserFactory.launch(BrowserType.CHROME);

    	//Navigate to "Advantage Online Shopping"
    	browser.navigate("http://www.advantageonlineshopping.com");
    }

Back to top

## Step 5: Add code to click the User Account button

Add code to click the USER icon at the top right of the Advantage Online Shopping site.

Use UFT Developer's OIC to obtain a unique identification for the USER object.

1. Launch your browser.

   Note: If this is the first time you've launched your browser after installing UFT Developer, you are prompted to enable the Micro Focus UFT Agent extension. Enable the agent to continue.

2. Navigate to the Advantage Online Shopping demo application site: http://www.advantageonlineshopping.com.

3. In your IDE, open theObject Identification Center (OIC) by selecting Object Identification Center from the UFT Developer menu, or by clicking the Object Identification Center button in the IDE toolbar.

   Obtain a unique identification for the USER object:

   1. In the OIC, click Start spying:

      Then, hover over the USER object in the top-right corner of your browser window to highlight it. Click it to capture the object properties in the OIC.

      The following image shows a sample desktop with the browser window and OIC displayed, and the USER object highlighted.

   2. In the OIC, click the Recommended tab.

      Note that some properties are starred. UFT Developer uses these stars to recommend a set of properties and values for uniquely identifying the spied object.

      There is only one object on the current page in our application that matches the starred properties and their current values. This is why these properties are recommended to identify our object.

   3. Click the Highlight button to see the USER object identified in your browser window.

   4. Click Generate Code to Clipboard , and paste the code into your test script.

      Click below to see what your identification code should look like. Your code may differ slightly as it is based on the properties recommended by the OIC for your environment.

      C#

          browser.Describe<ILink>(new LinkDescription
          {
          	TagName = @"A",
          	InnerText = @"My account My Orders Sign out "
          });

      Java

          browser.describe(Link.class, new LinkDescription.Builder()
          			.tagName("A")
          			.innerText("My account My Orders Sign out ").build());

      Tip: In addition to UFT Developer's recommendations, you can customize the identification using the OIC's Edit mode. Click the Edit button to switch to Edit mode and select the properties you want to use to identify the object. Then, test the identification by clicking the Highlight button.

      For more details, see Object Identification Center.

4. In your test, add code to click the USER object.

   Click to see how your test should look now:

   C#

       browser.Describe<ILink>(new LinkDescription
       {
       	TagName = @"A",
       	InnerText = @"My account My Orders Sign out "
       }).Click();

   Java

       browser.describe(Link.class, new LinkDescription.Builder()
       			.tagName("A")
       			.innerText("My account My Orders Sign out ").build()).click();

Back to top

## Step 6: Add code to start creating a new account

When the USER object is clicked, the login dialog box opens. Add code to click CREATE NEW ACCOUNT in this dialog box.

Use the same steps you performed earlier in Step 5: Add code to click the User Account button.

Click the following to see what your code should look like.

C#

    browser.Describe<ILink>(new LinkDescription
    {
    	TagName = @"A",
    	InnerText = @"CREATE NEW ACCOUNT"
    }).Click();

Java

    browser.describe(Link.class, new LinkDescription.Builder()
    			.tagName("A")
    			.innerText("CREATE NEW ACCOUNT").build()).click();

Back to top

## Step 7: Add code to fill in the CREATE ACCOUNT form

Extend your test method code to fill in the user details in the CREATE ACCOUNT page that opens when the CREATE NEW ACCOUNT button is clicked in the previous step.

This time, use application models instead of including the object's identification code directly in the script.

Application Models enable you to model your application objects and then reference them from your scripts. The modeled objects can be reused in different scripts and by different users, which can be helpful when maintaining tests.

Do the following:

1. Create a new application model.

   Visual Studio

   In the Solution Explorer, right-click your test project and select Add UFT Developer > Application Model.

   Use the application model name suggested by Visual Studio (ApplicationModel1).

   Eclipse
   1. Right-click the package you created when you created the project, and select File > New > Other > UFT Developer > UFT Developer Application Model Item.
   2. Name the application model ApplicationModel1.

   The item (.tsrx) is added under the package folder and a corresponding .java file is generated under the appmodels folder.

   IntelliJ IDEA

   In the project:

   1. Right-click the package that includes your test class.

   2. Select New > UFT Developer Application Model item.
   3. Name the item ApplicationModel1.

   The ApplicationModel1.tsrx item is added under the package folder and a corresponding .java file is generated under the appmodels folder.

   The Application Model Editor opens in your IDE, and you can use it to model the required objects, as described in the next step.

   For example, in Eclipse:

2. Use the OIC to add the following objects to the application model:

   - User name, Email, Password, and Confirm password fields
   - I agree to the Advantage.com Conditions of Use and Privacy Notice option
   - REGISTER button

   From the Application Model editor, click the button to open the OIC in the Application Model editor.

   Tip: When opened from the Application Model editor, the OIC has an additional button () to add objects to your application model. You can close the other OIC instance.

   Do the following for each of the objects mentioned above:

   1. Spy the object in the application.

   2. At the bottom of the OIC, click the Add object button.

   If you are using Eclipse, save your application model.

   Click to view a sample application model:

   Tip: Alternatively, see Object Identification Center.

3. Close the OIC. Then use the test objects from the application model in your script to do the following:

   - Set the values in the edit fields.
   - Select the I agree ... option.
   - Click the REGISTER button.

   Click the following to see samples of what your script should look like:

   C#

       ApplicationModel1 appModel = new ApplicationModel1(browser);
       appModel.AdvantageShoppingPage.UsernameRegisterPageEditField.SetValue("demoUser");
       appModel.AdvantageShoppingPage.PasswordRegisterPageEditField.SetSecure("596f1409b156a60dc50592de897863e8d552");
       appModel.AdvantageShoppingPage.ConfirmPasswordRegisterPageEditField.SetSecure("596f1409b156a60dc50592de897863e8d552");
       appModel.AdvantageShoppingPage.EmailRegisterPageEditField.SetValue("demoUser@default.com");
       appModel.AdvantageShoppingPage.IAgreeCheckBox.Set(true);
       appModel.AdvantageShoppingPage.RegisterBtnButton.Click();

   Java

       ApplicationModel1 appModel = new ApplicationModel1(browser);
       appModel.AdvantageShoppingPage().UsernameRegisterPageEditField().setValue("demoUser");
       appModel.AdvantageShoppingPage().PasswordRegisterPageEditField().setSecure("596f1409b156a60dc50592de897863e8d552");
       appModel.AdvantageShoppingPage().ConfirmPasswordRegisterPageEditField().setSecure("596f1409b156a60dc50592de897863e8d552");
       appModel.AdvantageShoppingPage().EmailRegisterPageEditField().setValue("demoUser@default.com");
       appModel.AdvantageShoppingPage().IAgreeCheckBox().set(true);
       appModel.AdvantageShoppingPage().RegisterBtnButton().click();

   Note:

   - ApplicationModel1 is the name you gave the application model when you created it (Eclipse/IntelliJ).

     It is also the class name defined for the application model in the right pane of the Application Model editor when the Application Model tab is selected (Visual Studio).

     UFT Developer dynamically compiles your application model to a class of the same name, which, in turn, is used in your code.

   - The browser argument given to ApplicationModel1 in the first line of code is the one you created at the beginning of the script. This argument enables you to reuse the same application model with different browsers.

Click the following to display sample code of the entire test.

C#

    public void MyTest()
    {
    	//Launch Chrome
    	IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

    	//Navigate to "Advantage Online Shopping"
    	browser.Navigate("http://www.advantageonlineshopping.com");

    	//Click the User Account button
    	browser.Describe<ILink>(new LinkDescription
    	{
    		TagName = @"A",
    		InnerText = @"My account My Orders Sign out "
    	});

    	//Click the Create New Account link
    	browser.Describe<ILink>(new LinkDescription
    	{
    		TagName = @"A",
    		InnerText = @"CREATE NEW ACCOUNT"
    	}).Click();

    	//Fill in the user details and create the account
    	ApplicationModel1 appModel = new ApplicationModel1(browser);
    	appModel.AdvantageShoppingPage.UsernameRegisterPageEditField.SetValue("demoUser");
    	appModel.AdvantageShoppingPage.PasswordRegisterPageEditField.SetSecure("596f1409b156a60dc50592de897863e8d552");
    	appModel.AdvantageShoppingPage.ConfirmPasswordRegisterPageEditField.SetSecure("596f1409b156a60dc50592de897863e8d552");
    	appModel.AdvantageShoppingPage.EmailRegisterPageEditField.SetValue("demoUser@default.com");
    	appModel.AdvantageShoppingPage.IAgreeCheckBox.Set(true);
    	appModel.AdvantageShoppingPage.RegisterBtnButton.Click();
    }

Java

     @Test
    	public void myTest() throws GeneralLeanFtException {

    	//Launch Chrome
    	Browser browser = BrowserFactory.launch(BrowserType.CHROME);

    	//Navigate to "Advantage Online Shopping"
    	browser.navigate("http://www.advantageonlineshopping.com");

    	//Click the User Account button
    	browser.describe(Link.class, new LinkDescription.Builder()
    	.tagName("A")
    	.innerText("My account My Orders Sign out ").build()).click();

    	//Click the Create New Account link
    	browser.describe(Link.class, new LinkDescription.Builder()
    	.tagName("A")
    	.innerText("CREATE NEW ACCOUNT").build()).click();

    	//Fill in the user details and create the account
    	ApplicationModel1 appModel = new ApplicationModel1(browser);
    	appModel.AdvantageShoppingPage().UsernameRegisterPageEditField().setValue("demoUser");
    	appModel.AdvantageShoppingPage().PasswordRegisterPageEditField().setSecure("596f1409b156a60dc50592de897863e8d552");
    	appModel.AdvantageShoppingPage().ConfirmPasswordRegisterPageEditField().setSecure("596f1409b156a60dc50592de897863e8d552");
    	appModel.AdvantageShoppingPage().EmailRegisterPageEditField().setValue("demoUser@default.com");
    	appModel.AdvantageShoppingPage().IAgreeCheckBox().set(true);
    	appModel.AdvantageShoppingPage().RegisterBtnButton().click();
    }

Back to top

## Step 8: Run your test from the IDE

1. (Optional) Customize your snapshots level test setting to save snapshots during the test run for each step performed and include them in the UFT Developer run results.

   Test settings are defined in the test settings file referenced by your testing project:

   - Eclipse / IntelliJ / Android Studio: leanft.properties
   - Visual Studio: App.config

   For details, see Customize test settings.

2. Build your project and run your test directly from your IDE.

   Visual Studio

   1. Ensure that you have the NUnit Test Adapter for Visual Studio that is compatible with the UFT Developer NUnit template you are using. For example, if you are working with NUnit 3.0, you must use the NUnit 3.0 Test Adapter.

      In the Visual Studio Extensions and Updates dialog, select Online, and then search for NUnit Test Adapter.

   2. Build your project. For example, right-click your project in the Solution Explorer and select Build.

   3. In the Solution Explorer's Test Explorer tab, right-click your test and select Run Selected Tests.

   Eclipse

   From the Run menu, select Run.

   IntelliJ IDEA

   Click the Run Test button to the left of your test code.

Back to top

## Step 9: View and analyze your run results

From your UFT Developer IDE menu, select View Last Run Results.

If you customized your report settings as described in Step 8.1, notice the screen captures added to your report.

Your run report should look similar to the following:

Next steps:

- Exercise 2: Buy a laptop

https://admhelp.microfocus.com UFT Developer 8942
Tips to improve your search results... UFT Developer Help Center UFT Developer Help 15.0-15.0.2 All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version: