使用网络核心的PageFactory是否有其他选择? [英] Is there any alternative for PageFactory using net core

查看:93
本文介绍了使用网络核心的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?

推荐答案

对于版本3.6.0,WebDriver.Support.dll中没有PageFactory类(在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.

这篇关于使用网络核心的PageFactory是否有其他选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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