具有资源文件的 FindsBy 属性 c# Selenium
FindsBy attribute with resource file c# Selenium
在 selenium 中使用 PageObject 模式,我想将所有定位器放在一个资源文件中。
想知道是否可以将 FindsBy 属性与资源文件一起使用
[FindsBy(How = How.Id, Using = "btnUserApply")]
public Button ApplyButton { get; set; }
变成如下报错无法完成
[FindsBy(How = How.Id, Using = MyRexFile.btnUserApply)]
public Button ApplyButton { get; set; }
FindsBy 也是密封的,所以不能继承。
有什么建议吗?
这是不可能的。 FindsBy
注释接收 const(在编译中求值)字符串作为 Using
参数。来自资源文件的数据在 运行 时间内评估。
您可以创建另一个 class 来保存所有定位器
public static class Locators
{
public const string btnUserApply = "btnUserApply";
}
public class PageObject
{
[FindsBy(How = How.Id, Using = Locators.btnUserApply)]
public Button ApplyButton { get; set; }
}
在 selenium 中使用 PageObject 模式,我想将所有定位器放在一个资源文件中。
想知道是否可以将 FindsBy 属性与资源文件一起使用
[FindsBy(How = How.Id, Using = "btnUserApply")]
public Button ApplyButton { get; set; }
变成如下报错无法完成
[FindsBy(How = How.Id, Using = MyRexFile.btnUserApply)]
public Button ApplyButton { get; set; }
FindsBy 也是密封的,所以不能继承。
有什么建议吗?
这是不可能的。 FindsBy
注释接收 const(在编译中求值)字符串作为 Using
参数。来自资源文件的数据在 运行 时间内评估。
您可以创建另一个 class 来保存所有定位器
public static class Locators
{
public const string btnUserApply = "btnUserApply";
}
public class PageObject
{
[FindsBy(How = How.Id, Using = Locators.btnUserApply)]
public Button ApplyButton { get; set; }
}