[英]FindsBy attribute with resource file c# Selenium
Using PageObject pattern in selenium and i would like to put all the locators in a resource file. 在selenium中使用PageObject模式,我想将所有定位器放在资源文件中。
wondering if possible to use a FindsBy Attribute with resource file 想知道是否可以在资源文件中使用FindsBy属性
[FindsBy(How = How.Id, Using = "btnUserApply")]
public Button ApplyButton { get; set; }
becomes as below which gives an error and cannot be done 如下所示会产生错误而无法完成
[FindsBy(How = How.Id, Using = MyRexFile.btnUserApply)]
public Button ApplyButton { get; set; }
FindsBy is also sealed so cannot inherit . FindsBy也是密封的,所以不能继承。
Any suggestions? 有什么建议么?
It isn't possible. 这是不可能的。
FindsBy
annotation receives const (evaluated in compilation) string as the Using
parameter. FindsBy
注释接收const(在编译时评估)字符串作为Using
参数。 Data from resource file is evaluated in run time. 资源文件中的数据在运行时进行评估。
You could create another class to hold all the locators 您可以创建另一个类来保存所有定位器
public static class Locators
{
public const string btnUserApply = "btnUserApply";
}
public class PageObject
{
[FindsBy(How = How.Id, Using = Locators.btnUserApply)]
public Button ApplyButton { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.