我正在使用Page Object模型来设计一些selenium测试。我在下面的关键字中遇到了等待代码的一些问题。当我使用下面的代码在我的NUnit测试中调用关键字时,它会尝试在准备好之前单击按钮。如果我在NUnit测试中粘贴相同的等待代码,它会按预期等待,然后单击按钮。我的偏好是我实现的所有关键字来处理等待而不必在我的测试中编写它。我在这里错过了什么吗?
NUnit测试
public void QuotesPageTest()
{
//Loginto CRM
LoginPage loginPage = new LoginPage();
loginPage.UserLogin();
//Select quotes tile
pgCommon myMenu = new pgCommon();
myMenu.GoToMenu("quotes");
//Click new
pgQuotes QuotesPage = new pgQuotes();
Keywords.DoSendKeys(QuotesPage.btnNew);
}
Keywords.cs
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TraingDay1_1
{
public static class Keywords
{
public static void DoSendKeys(this IWebElement element)
{
String elementName = element.GetAttribute("value");
WebDriverWait wait = new WebDriverWait(GlobalDriver.driver, TimeSpan.FromSeconds(EnvironmentData.objectTimeout));
wait.Until(ExpectedConditions.ElementToBeClickable(element));
element.SendKeys(Keys.Enter);
Console.WriteLine("Selected " + elementName + " and pressed enter key");
}
public static void DoClick(this IWebElement element)
{
String elementName = element.GetAttribute("value");
WebDriverWait wait = new WebDriverWait(GlobalDriver.driver, TimeSpan.FromSeconds(EnvironmentData.objectTimeout));
wait.Until(ExpectedConditions.ElementToBeClickable(element));
element.Click();
Console.WriteLine("Selected " + elementName + " and pressed enter key");
}