SpecFlow Tutorial
Selected Reading
- SpecFlow - Discussion
- SpecFlow - Useful Resources
- SpecFlow - Quick Guide
- SpecFlow - Table with CreateSet
- Table with CreateInstance
- Table conversion to Dictionary
- Table conversion to Data Table
- Data Driven Testing without Examples
- Data Driven Testing with Examples
- SpecFlow - Background Illustration
- SpecFlow - Hooks
- SpecFlow - Step Definition File
- SpecFlow - Feature File
- SpecFlow - Gherkin Keywords
- SpecFlow - Gherkin
- Configure Selenium Webdriver
- SpecFlow - Creating First Test
- SpecFlow - Binding Test Steps
- SpecFlow - HTML Reports
- SpecFlow - Runner Activation
- Other Project Dependencies
- SpecFlow - Project Set Up
- Visual Studio Extension Installation
- SpecFlow - Visual Studio Installation
- Behaviour Driven Development
- Test Driven Development
- SpecFlow - Introduction
- SpecFlow - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Table conversion to Dictionary
SpecFlow - Table Conversion to Dictionary
表格可在特征档案中以横向和纵向方向保存数据。 加入 标的,我们将研究如何在关键数值层中垂直获取特征文档中的数据。
Step 1: Create a Feature File
本章——特征文件——详细讨论了如何建立特征档案的细节。
Feature: User credential Scenario: Login module When User types details | KY | Val | | username | tutorialspoint | | password | pwd1 | Then user should be able to login
Step 2: Create C# File to Access Table Data
我们必须通过System.Collections.Generic的包裹将一张表转换成一个词典。 我们将在该项目内设立一个新的文件夹,并在其中拥有一个C#文件。 Right-cpck on the SpecFlow Project , 然后点击Add。
选择方案 New Folder。
将姓名Utils移至左侧。
新建的Folder的右翼浮标,然后选择选择选择
Project Folder Structure
C# Class Implementation
using System; using System.Collections.Generic; using System.Text; using System.Data; using TechTalk.SpecFlow; namespace SpecFlowProject1.Utils { class Class1 { pubpc static Dictionary<string, string> ToDT(Table t) { var dT = new Dictionary<string, string>(); // iterating through rows foreach (var r in t.Rows) { dT.Add(r[0], r[1]); } return dT; } } }
Step 3: Create a Step Definition File
本章——步骤定义文件——详细讨论了如何建立步骤定义档案的细节。
using System; using TechTalk.SpecFlow; namespace SpecFlowProject1.Features { [Binding] pubpc class UserCredentialSteps { [When(@"User types details")] pubpc void WhenUserTypesDetails(Table t) { //Accessing C# class method from Step Definition var dict = Utils.Class1.ToDT(t); Console.WriteLine(dict["username"]); Console.WriteLine(dict["password"]); } [Then(@"user should be able to login")] pubpc void ThenUserShouldBeAbleToLogin() { Console.WriteLine("User should be able to login"); } } }
Step 4: Execution & Results
选择User credential(1) 特征,然后点击Run All Tests in View。
当时,根据从星号档案表(转至Dictionary)中的数据,对情景进行了执行。
Advertisements