繁体   English   中英

Specflow:将名称(从功能文件传递字符串)替换为步骤定义文件中的 AccessibilityId

[英]Specflow: Replace Name(pass string from feature file) to AccessibilityId in step definition file

我是 Specflow 的新手。 我的框架是 C#。 功能文件:

Feature: test ABC app

Scenario: 00 Application is open 
    Given Application is open in "User" mode
    When the "Configuration" screen is open

Scenario: 02 Search for servers
    Given the "Add Server" screen is open
    And "Request Server" button is clicked
    When the "Request serer" screen is open

在步骤定义文件中 function 是这样的:

 [When(@"the ""(.*)"" screen is open")]
 [Given(@"the ""(.*)"" screen is open")]
 public void GivenScreenIsOpen(string element)
 {
   element_Interactions.ClickOnElement(element);
 }

需要的解决方案:从功能文件中,我传递了一个带有屏幕名称的字符串作为变量,但在步骤定义文件中,而不是使用driver.FindElementByName(element)我想使用driver.FindElementByAccessibilityId(element) 我无法从我的页面 class 中的步骤定义 function 中获得有关如何使用/调用适当屏幕名称的 AccessibilityId 以及如何为所有其他屏幕动态使用相同屏幕名称的解决方法

提前致谢。

我仍然不能 100% 确定你在处理什么,但似乎一个屏幕字典和可访问性 ID 将是最简单的解决方案:

[Binding]
public class YourSteps
{
    private static readonly Dictionary<string, string> accessibilityIds = new Dictionary<string, string>()
    {
        { "screen1", "accessibility-id-"},
        { "screen2", "accessibility-id-2"},
        { "screen3", "accessibility-id-3"}
    };

    [When(@"the ""(.*)"" screen is open")]
    [Given(@"the ""(.*)"" screen is open")]
    public void GivenScreenIsOpen(string element)
    {
        var accessibilityId = accessbilityIds[element];

        // Or however you click on an element by its accessibility Id
        element_Interactions.ClickOnElement(accessibilityId);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM