我有很多测试,由于某些原因,我的明确等待似乎没等到我告诉它的时间长度。我有一个基类,我继承了我声明变量的地方。
当我在20秒之前运行我的代码时,它说“远程服务器返回错误(404)未找到”。
这是因为它没有等到我告诉它的长度
我的代码如下
public class WordBaseClass
{
public string wordId = OfficeVersion.Word();
public const string AppDriverUrl = "http://127.0.0.1:4723";
public static WindowsDriver<WindowsElement> wordSession;
public static string exception;
public static DesiredCapabilities appCapabilities = new DesiredCapabilities();
public static WebDriverWait webDriverWait;
protected virtual void SetUp()
{
try
{
appCapabilities.SetCapability("app", wordId);
var initialSession = new WindowsDriver<WindowsElement>(new Uri(AppDriverUrl), appCapabilities);
var capabilities = new DesiredCapabilities();
capabilities.SetCapability("app", "Root");
wordSession = new WindowsDriver<WindowsElement>(new Uri(AppDriverUrl), capabilities);
CommonMethods.keyCheck(wordSession);
webDriverWait = new WebDriverWait(wordSession, TimeSpan.FromSeconds(20));
Thread.Sleep(2000);
}
catch (Exception)
{
CommonMethods.ExceptionHandler("WinApp Driver failed to load Word", new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), wordSession);
}
}
}
我的考试班
public class Word:WordBaseClass
{
[TestMethod]
public void newWordDoc()
{
try
{
base.SetUp();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(wordSession.FindElementByName("Blank document"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(wordSession.FindElementByName("Create"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(wordSession.FindElementByName("New"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(wordSession.FindElementByName("A Agreements"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(wordSession.FindElementByName("A Confidentiality Agreement"))).Click();
CommonMethods.IsElementDisplayed(wordSession, new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), "CreateErrorIcon", "Error appeard while selecting the A Confidentiality Agreemnet button");
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(wordSession.FindElementByName("OK"))).Click();
CommonMethods.IsElementDisplayed(wordSession, new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), "CreateErrorIcon", "Error appeard while selecting the OK button");
}
catch (Exception)
{
CommonMethods.ExceptionHandler("Couldn't find element", new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), wordSession);
}
TearDown();
}