You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Overview

In this tutorial, we will create a NUnit Test Case in C#, using LeanFT for browser automation.

Description

The test case opens a Google page, search for a given keyword and checks the results returned by Google.



LeanFtTest.cs
using System;
using NUnit.Framework;
using HP.LFT.SDK;
using HP.LFT.SDK.Web;
using HP.LFT.Verifications;

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

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

        [Test]
        public void TotalPriceTest()
        {
            //Launch Chrome and navigate to the online store application
    	    IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);
    	    browser.Navigate("http://www.advantageonlineshopping.com");

            //Click the "Tablets" category 
            ILink tabletsLink = browser.Describe<ILink>(new LinkDescription { Id = @"TabletsImg" });
            tabletsLink.DisplayName = "Tablets";
            tabletsLink.Click();

            //Click a specific tablet
            IImage tabletElitePad = browser.Describe<IImage>(new ImageDescription
            {
                Src = @"http://www.advantageonlineshopping.com/catalog/fetchImage?image_id=3100",
                ClassName = @"imgProduct"
            });
            tabletElitePad.DisplayName = "Tablet ElitePad";
            tabletElitePad.Click();
    	
        	//Add it to the cart
            browser.Describe<IButton>(new ButtonDescription { Name = @"ADD TO CART"	}).Click();
    	
        	//Store its price
            String tabletPrice = browser.Describe<IWebElement>(new WebElementDescription { ClassName = @"roboto-medium cart-total ng-binding"}).InnerText;

        	//Check out
    	    browser.Describe<IButton>(new ButtonDescription { ClassName = @"roboto-medium ng-binding"}).Click();

            //Verify that the total price presented in the purchase summary page, is exactly the price of the selected tablet
            String totalPrice = browser.Describe<IWebElement>(new WebElementDescription {
		                    ClassName = @"roboto-medium totalValue ng-binding",
		                    InnerText = As.RegExp(@"\$.*")
	                    }).InnerText;
    	
    	    Verify.AreEqual(tabletPrice, totalPrice, "Verify total price");            
        }

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

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



After running successfuly the Test Case and generating the NUnit XML report (e.g. results.xml), it can be imported to Xray (either by the REST API or through "Import Execution Results" action within the Test Execution).

Nunit's Test Case is mapped to a Generic Test in JIRA, and the "Generic Test Definition" field contains the name of the namespace, class, and the method name that implements the Test case.

The Execution Details of the Generic Test contains information about the context, which in this case corresponds to the Test case method itself. 


References






  • No labels