Selenium 初回测试
页面结构:
测试的目标是为:iframeContent中的页面添加数据.并且确定保存成功.
iframeContent中的页面有如下元素:
TextBox: tbFileNumber
TextBox: tbFileName
Button: btnSave
当单击btnSave时,页面提示"保存成功",方可测试成功.
测试代码如下:
[Test] public void Test() { selenium.Open("http://www.file.com//Default.aspx"); Assert.AreEqual("用户登录", selenium.GetTitle()); //登录 selenium.Type("tBoxName", "admin"); selenium.Type("tBoxPwd", "123456"); //设置选择框 选择 "管理员" selenium.Select("rblType", "index=1"); selenium.Click("btnLogin"); selenium.WaitForPageToLoad("5000"); //单击 超级链接 "起草文件".通过class= draftoutFile ''查找a标签 selenium.Click("xpath=//a[@class='draftoutFile']"); //等待页面载入 selenium.WaitForPageToLoad("5000"); Assert.AreEqual(true, selenium.IsTextPresent("起草文件"));
//起草文件 填写表单 selenium.Type("tbFileNumber", "SeleniumNumber" + new Random().Next()); selenium.Type("tbFileName", "SeleniumName" + new Random().Next()); //单击 提交按钮.使用xpath selenium.Click("xpath=//input[@name='btnSave']"); /*** 请注意****/ selenium.SelectFrame("iframeRight"); selenium.SelectFrame("iframeContent"); selenium.WaitForPageToLoad("50000");
Assert.AreEqual(true, selenium.GetHtmlSource().Contains("成功")); /*****请注意*****/ Console.Write(selenium.GetHtmlSource() + "<<<<<<<<<<");
} |
代码: selenium.SelectFrame("iframeRight"); selenium.SelectFrame("iframeContent"); selenium.WaitForPageToLoad("50000"); 选择frame的原因为:最终的页面在iframeContent中,但是如果按找登录的顺序这时候的selenium并不在页面中,如果想让 Assert.AreEqual(true, selenium.GetHtmlSource().Contains("成功")); 成功, selenium.GetHtmlSource(). 返回当前提交页的值,就需要选择Frame,将selenium定位到最终的frame中,并且设置页面等待. |
wlhc_jing