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

本文通过示例展示了如何使用Holmos自动化测试工具处理JavaScript中的alert、confirm及prompt弹窗,包括打开窗口、点击按钮及处理弹窗的具体实现。
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时为点击提示框中“取消”按钮
       }
}
控制台输出结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值