我希望这比看起来更容易,我刚刚变得雪盲试图修复它!您的帮助将不胜感激。
我正在使用 PageObject 模型(我认为!)来创建我的测试。我有一个对象可以复制图像的浏览和上传,我必须调用 AutoIt 脚本来完成。这可行,但是在上传图像后,即使它具有 ID 属性,也找不到“上传”按钮。
它在文件选择后正确启用,因此不确定我缺少什么。
PageObject 的代码是:
public void AddImage(string FileDescription, int DocNo, int Revision, string StatusLstItem, string CreationDate)
{
driver.FindElement(By.Id("Button1")).Click();
driver.SwitchTo().Window("FileDetails");
driver.FindElement(By.Id("Description1")).Clear();
driver.FindElement(By.Id("Description1")).SendKeys(FileDescription);
driver.FindElement(By.Id("DocNo1")).Clear();
driver.FindElement(By.Id("DocNo1")).SendKeys(DocNo.ToString());
driver.FindElement(By.Id("revision1")).Clear();
driver.FindElement(By.Id("revision1")).SendKeys(Revision.ToString());
new SelectElement(driver.FindElement(By.Id("FileStatus1"))).SelectByText(StatusLstItem);
driver.FindElement(By.Id("creationDate1")).Clear();
driver.FindElement(By.Id("creationDate1")).SendKeys(CreationDate);
IWebElement element = driver.FindElement(By.Id("Filename1"));
element.Click();
Process.Start("C:\\Users\\Tom\\Desktop\\FileUploadCr.exe");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
IWebElement upload = driver.FindElement(By.Id("action1"));
upload.Click();
}
然后我AddImage
使用以下方法从测试类中调用 ' ' 方法:
[Test]
public void ItemChecks()
{
InformationObject informationObject = new InformationObject(driver);
informationObject.ExpandAllButton();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
informationObject.AddImage("SampleDesc", 01, 01, "Approved", "01/10/2012");
informationObject.ClickUpdateButtonOne();
}
由于某种原因,它没有找到/单击“action1”上传按钮。我尝试切换回“FileDetails”窗口,但这也不起作用。
任何想法我错过了什么???
仅供参考 - 上传按钮的代码是:
<input type="Submit" value="Upload" id="action1" disabled=""/>
更新 - 修改后的 + 工作 PageObject 方法现在看起来像这样:
public void AddImage(string FileDescription, int DocNo, int Revision, string StatusLstItem, string CreationDate)
{
driver.FindElement(By.Id("Button1")).Click();
driver.SwitchTo().Window("FileDetails");
IWebElement element = driver.FindElement(By.Id("Filename1"));
element.Click();
Process.Start("C:\\Users\\Tom\\Documents\\Visual Studio 2010\\Projects\\AutoIt_Files\\FileUploadCr.exe");
Thread.Sleep(1000);
driver.FindElement(By.Id("Description1")).Clear();
driver.FindElement(By.Id("Description1")).SendKeys(FileDescription);
driver.FindElement(By.Id("DocNo1")).Clear();
driver.FindElement(By.Id("DocNo1")).SendKeys(DocNo.ToString());
driver.FindElement(By.Id("revision1")).Clear();
driver.FindElement(By.Id("revision1")).SendKeys(Revision.ToString());
new SelectElement(driver.FindElement(By.Id("FileStatus1"))).SelectByText(StatusLstItem);
driver.FindElement(By.Id("creationDate1")).Clear();
driver.FindElement(By.Id("creationDate1")).SendKeys(CreationDate);
driver.SwitchTo().Window("FileDetails");
Thread.Sleep(1000);
IWebElement upload = driver.FindElement(By.Id("action1"));
upload.Click();
Thread.Sleep(1000);
driver.SwitchTo().Alert().Dismiss(); //Ignore this, just an alert that displays following upload and not part of the solution
}