是否有使用 net core 的 PageFactory 替代方案 [英] Is there any alternative for PageFactory using net core

查看:21
本文介绍了是否有使用 net core 的 PageFactory 替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Selenium v​​3.6.0 和 .NET Core 2.0,以下代码在 PageFactory.InitElements 上给我一个错误,说它在当前上下文中不存在.

I'm using Selenium v3.6.0 and .NET Core 2.0, the following code gives me an error on PageFactory.InitElements saying it doesn't exist in the currenct context.

using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;

namespace Example
{
    public class Form
    {
        [FindsBy(How = How.Name, Using = "Filter")] // This does exist in current context using .NET Core
        public IWebElement Filter { get; set; }

        [FindsBy(How = How.TagName, Using = "Button")]
        public IWebElement Button;

        public Form(IWebDriver driver)
        {
            PageFactory.InitElements(driver, this); // This doesn't exist in current context using .NET Core
        }
    }
}

我对此有点困惑,因为属性 FindsBy、FindsByAll 和 FindsBySequence 在 OpenQa.Selenium.Support.PageObjects 命名空间中都可用,但 PageFactory 不是.据我所知,这些属性仅适用于 PageFactory.

I'm a bit confused about this since the attributes FindsBy, FindsByAll and FindsBySequence are all available in the OpenQa.Selenium.Support.PageObjects namespace, but PageFactory is not. To my knowledge, these attributes only work with PageFactory.

是否有使用 .NET Core 的不同方法,或者它只是(尚未)实现?

Is there a different approach to this using .NET Core or is it just not (yet) implemented?

推荐答案

WebDriver.Support.dll 中没有 PageFactory 类 for version 3.6.0 (在visual studio中你可以在对象资源管理器中打开这个dll,看到有没有这样的课程).所以你只是遇到了常见的编译错误.

There is no PageFactory class in WebDriver.Support.dll for version 3.6.0 (In visual studio you can open this dll in object explorer and see that there is no such class). So you've got just usual compilation error.

我在 github 上查看过源代码 https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/support/PageObjects/PageFactory.cs并查看 PageFactory 类中的预处理器指令 #if !NETSTANDARD2_0 ... #endif.我不知道为什么 NETSTANDARD2_0 会影响 NETCORE2_0,也不确定这是不是真正的原因,但对于我们图书馆用户而言,PageFactory 暂时无法访问.

I've looked source code on github https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/support/PageObjects/PageFactory.cs and see preprocessor directive #if !NETSTANDARD2_0 ... #endif in PageFactory class. I don't know why NETSTANDARD2_0 affected NETCORE2_0, and not sure that it's real reason, but for us as library users PageFactory is unaccessible for now.

这篇关于是否有使用 net core 的 PageFactory 替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆