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 OpenText Functional Testing for Developers steps.

To view the corresponding CalculatorFeature file or for more information about implementing Cucumber tests using SpecFlow and OpenText Functional Testing for Developers, see Use OpenText Functional Testing for Developers 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

https://admhelp.microfocus.com Functional Testing for Developers 8942
Tips to improve your search results... OpenText™ Functional Testing for Developers Help Center OpenText™ Functional Testing for Developers Help 25.2 All View Local Help Center View Online Help Center Version: