Share this page

# Additional code samples (.NET SDK)

In this topic:

## Implement SpecFlow steps for a calculator feature file

This example implements the steps of the SpecFlow CalculatorFeature feature file using UFT Developer steps.

To view the corresponding CalculatorFeature file or for more information about implementing Cucumber tests using SpecFlow and UFT Developer, see Use UFT Developer with Cucumber.

    using System;
    using TechTalk.SpecFlow;
    using System.Diagnostics;
    using HP.LFT.SDK;
    using HP.LFT.SDK.StdWin;
    using NUnit.Framework;

    namespace LeanFtSpecFlowTest
    {
    	public partial class CalculatorFeature : UnitTestClassBase
    	{
    	}

    	[Binding]
    	public   class CalculatorSteps
    	{
    		private   static IWindow _calculator;

    		[BeforeFeature]
    		public   static void BeforeFeature()
    		{
    			(new Process { StartInfo = { FileName = @"c:\windows\System32\calc.exe" } }).Start();

    			_calculator = Desktop.Describe<IWindow>(new WindowDescription
    			{
    				WindowClassRegExp = "CalcFrame",
    				WindowTitleRegExp = "Calculator"
    			});
    		}

    		[AfterFeature]
    		public   static void AfterFeature()
    		{
    			_calculator.Close();
    		}

    		[BeforeScenario]
    		public   static void BeforeScenario()
    		{
    		}

    		[AfterScenario]
    		public   static void AfterScenario()
    		{
    		}

    		[Given(@"I have entered (.*) into the calculator")]
    		public void GivenIHaveEnteredIntoTheCalculator(int p0)
    		{
    			_calculator.SendKeys(p0.ToString());
    		}

    		[Given(@"I press add")]
    		public void WhenIPressAdd()
    		{
    			_calculator.SendKeys("+");
    		}

    		[Given(@"I press multiply")]
    		public void WhenIPressMult()
    		{
    			_calculator.SendKeys("*");
    		}

    		[When(@"I press equals")]
    		public void WhenIPressEquals()
    		{
    			_calculator.SendKeys("=");
    		}

    		[Then(@"the result should be (.*) on the screen")]
    		public void ThenTheResultShouldBeOnTheScreen(int p0)
    		{
    			var resultTextBox = _calculator.Describe<IStatic>(new StaticDescription
    			{
    				WindowId = 150,
    				NativeClass = "Static"
    			});

    			Verify.AreEqual(p0.ToString(), resultTextBox.GetVisibleText());
    		}
    	}
    }

Back to top

Tips to improve your search results... UFT Developer .NET SDK Reference Version 15.0-15.0.2 UFT Developer SDK Reference 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: