我在VSCode中站起来一个NUnit框架,但在我的页面ctor中设置PageFactory时遇到了问题。我已经将DotNetSeleniumExtras.PageObjects添加到我的.csproj中,但即使使用了SeleniumExtras.PageObjects,也无法调用PageFactory.InitElements(driver,this)。
我看过有关PageObjects的文章/视频正在从.Net Core中删除,但我想(也许是天真的)DotNetSeleniumExtras会解决这个问题。
有没有人因为PageObjects被引入他们自己的项目而得到了这个工作?
以下是我在设置时遵循的步骤:
1)安装VSCode
2)创建新文件夹
3)在VSCode中打开文件夹
4)安装.Net Core
5)安装扩展程序:
C#
.Net Core Test Explorer
显示测试结果(对NUnit .Net Core的TDD支持)
6)添加NUnit模板:
dotnet new -i NUnit3.DotNetNew.Template
7)创建一个项目:
dotnet new nunit
8)添加包:
dotnet add package Selenium.Webdriver
dotnet add package Selenium.Support
dotnet add package DotNetSeleniumExtras.PageObjects
dotnet add package NUnit
dotnet add package NUnit3TestAdapter
dotnet add package Microsoft.NET.Test.Sdk
.csproj内容
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetSeleniumExtras.PageObjects" Version="3.11.0" />
<PackageReference Include="nunit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.1" />
<PackageReference Include="Selenium.Support" Version="3.11.0" />
<PackageReference Include="Selenium.Webdriver" Version="3.11.0" />
</ItemGroup>
</Project>
Page.cs
using NUnit.Framework;
using System;
using SeleniumExtras.PageObjects;
using OpenQA.Selenium;
namespace IS.Pages
{
class Landing
{
public Landing()
{
PageFactory.InitElements(DriverUtil.driver,this);
}
// Start Search Button
[FindsBy(How = How.CssSelector, Using = "body > main > header > div.background-wrapper > div > div > div:nth-child(1) > div > a")]
public IWebElement AdvancedSearch {get; set;}