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中,并且设置页面等待.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值