Holmos自动化测试入门学习(三)------处理alert、confirm、prompt对话框

来源:互联网 发布:java虚拟机规范 编辑:程序博客网 时间:2024/05/20 16:37
Holmos处理js的 alert confirm 以及prompt是非常非常简单的,下面具体看例子:

alert.html文件,保存于D盘下:

<html><head><title> Alert</title ><script type="text/javascript">        function disp_prompt() {               var name = prompt("Please enter your name" , "")               if (name != null && name != "") {                     document.write( "Hello " + name + "!" )              }       }</script></head><body>        <input id="alert" value="alert" type="button"onclick ="alert('这个是alert窗');" />        <input id="confirm" value="confirm" type="button"onclick ="confirm('确定吗?');" />        <input id="prompt" value="prompt" type="button" onclick="disp_prompt()" value="Display a prompt box" /></body></html>
Alert.java Page类代码:
import com.holmos.webtest.element.Button;import com.holmos.webtest.struct.Page;public class Alert extends Page {        public Alert() {               super();               this.comment = "测试页面";               this.init();// 页面元素收集器       }        // 都采用ID定位        public Button alert = new Button( "alert按钮" );        public Button confirm = new Button( "confirm按钮" );        public Button prompt = new Button( "prompt按钮" );       {               alert.addIDLocator("alert" );               confirm.addIDLocator("confirm" );               prompt.addIDLocator("prompt" );       }}


Alert.java Test类的代码:
import org.junit.Test;import com.holmos.webtest.EngineType;import com.holmos.webtest.utils.HolmosWindow;public class Alert_Test {        public Alert aler =new Alert();        @Test        public void alert(){              HolmosWindow. openNewWindow(EngineType.WebDriverChrome, "D:\\alert.html" );               aler.alert .click();// 点击alert按钮              System. out.println(HolmosWindow.dealAlert()); //处理alert,得到弹窗内容输出                             aler.confirm .click();// 点击confirm按钮              System. out.println(HolmosWindow.dealConfirm( true));//处理confirm,得到弹窗内容输出,如果要去点,true改为false                             aler.prompt .click();//点击prompt按钮              System. out.println(HolmosWindow.dealPrompt( "米阳!" , true)); //处理prompt.参数为false时为点击提示框中“取消”按钮       }}
控制台输出结果:


原创粉丝点击