慕课网web自动化测试实战之购买商品(六)

慕课网自动化测试实战

购买商品

需求:
  1. 实现简单的商品购买流程:登录->立即购买->提交订单->立即支付
脚本代码(代码中调用的类和方法,请参考之前的文章)
/**
     * 下单流程
     */
    @Test(dependsOnMethods = {"testLogin","getLoginHome"})
    public void downOrder() throws IOException, InterruptedException {
        Thread.sleep(3000);
        driver.get("https://coding.imooc.com/class/411.html");
        String currentText=this.buyCourseNow();
        System.out.println("课程页面信息为:"+currentText);
        this.sureOrder();
//        this.getOrder();
        String orderCourseText=this.getOrderCourse();
        System.out.println("订单页面课程信息为:"+orderCourseText);
        if (currentText.equals(orderCourseText)){
            System.out.println("下单成功!");
        }
        Thread.sleep(2000);
        driver.stop();
    }

    //获取课程信息
    public String getCourseText(WebElement element){
        return element.getText();
    }

    //获取element
    public WebElement getElement(By by){
        return driver.findElement(by);
    }

    /**
     * 功能:立即购买,并返回课程信息
     */
    public String buyCourseNow() throws IOException {
        WebElement elementNode=this.getElement(ByLocation.getLocator("courseInfoText"));
        String currentText=this.getCourseText(elementNode);  //获取课程名称
        driver.click(this.getElement(ByLocation.getLocator("buyNow")));//立即购买
        return currentText;
    }

    /**
     *功能:确认订单
     */
    public void sureOrder() throws IOException {
        driver.click(this.getElement(ByLocation.getLocator("sureOrder")));
    }

    /**
     * 功能:获取订单的文字,确认订单是否为空
     */
//    public String getOrder() throws IOException {
//        return this.getCourseText(this.getElement(ByLocation.getLocator("order")));
//    }

    /**
     * 功能:立即支付,并获取支付中心商品信息
     */
    public String getOrderCourse() throws IOException {
        Thread.sleep(3000);
        WebElement elementNode=this.getElement(ByLocation.getLocator("orderCourseNode"));
        driver.click(this.getElement(ByLocation.getLocator("wxpay")));//微信支付
        driver.click(this.getElement(ByLocation.getLocator("orderpay")));//立即支付
        return this.getCourseText(elementNode);
    }
}

效果:

在这里插入图片描述

控制台输出:
课程页面信息为:全面系统学测试 从小白入门到实战就业
JavaScript warning: https://order.imooc.com/static/lib/util/placeholder.js?v=202003111810, line 101: unreachable code after return statement
JavaScript warning: https://order.imooc.com/static/lib/backbone/backbone-1.0.0.min.js?v=202003111810, line 3: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead
订单页面课程信息为:全面系统学测试 从小白入门到实战就业
下单成功!
stop driver
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值