selenium2java利用mysql实现重复购买用例
来源:互联网 发布:淘宝面膜靠谱么 编辑:程序博客网 时间:2024/05/16 11:37
本人在学习使用selenium2java的过程中,遇到过需要测试方案购买的问题,每次买完之后都得手动清除一下数据,重新测试购买流程。在写自动化用例的时候用到了数据库相关方法,分享一下,供参考。
//购买志愿方案(使用兑换卡)public static void buyWishProjectByCoupon(WebDriver driver) throws ClassNotFoundException, SQLException, IOException, InterruptedException {MySql.UpdateOrderStutas(user_id);//使用户当前已购买订单过期findElementByIdAndClick(driver, "btnIndexPay");//点击购买findElementByXpathAndClick(driver, ".//*[@id='payment_channel']/li[1]");//点击兑换卡购买findElementByIdAndClick(driver, "btnOrderCreatePay");//点击立即支付/*如果用户之前购买过,则在第一行设置为过期 * 如果用户之前生成过订单,会提示雷同,跳转订单页面,继续选择兑换卡支付 * 如果用户没有购买过或者订单全部过期,直接使用兑换卡支付 */if (exists(driver, By.className("confirm"))) {sleep(0);findElementByClassNameAndClick(driver, "confirm");findElementByTextAndClick(driver, "立即支付");findElementByIdAndClick(driver, "btnOrderCreatePay");//点击立即支付payByCoupon(driver);}else{payByCoupon(driver);}driver.get("http://172.21.134.15:5555/purchase/order/list");//跳转我的订单页面refresh(driver);//强制刷新String status = getTextByClassName(driver, "pull-right");//获取最新订单状态assertTrue("购买课程失败!", status.equals("已付款"));}
下面是使用兑换卡的方法:
//兑换卡支付public static void payByCoupon(WebDriver driver) throws ClassNotFoundException, SQLException {String coupon_id = MySql.getCouponIdAndPassword();//获取帐号findElementByIdAndClearSendkeys(driver, "input-coupon_number", coupon_id);//输入帐号findElementByIdAndClearSendkeys(driver, "input-coupon_password", "123456");//输入密码findElementByXpathAndClick(driver, ".//*[@id='modal-pay_card']/div/div/div[2]/div/div/div[2]/div/div[4]/div/button");//点击支付}
下面是修改用户订单状态的方法:
//修改用户订单状态public static void UpdateOrderStutas(int id) throws ClassNotFoundException, SQLException, IOException {// 加载驱动程序Class.forName(driver);// 连接数据库Connection connection = DriverManager.getConnection(url, user, password);if(!connection.isClosed()){Statement statement = connection.createStatement();//1是代付款,2是已付款,5是已过期String sql = "UPDATE op_orders SET order_status = 5 where user_id = "+id+" and order_status= 2";statement.executeUpdate(sql);connection.close(); }else { output("failed connecting to the Database!"); }}
下面是获取尚未使用的兑换卡的方法:
//查找尚未使用的兑换卡帐号和密码public static String getCouponIdAndPassword() throws SQLException, ClassNotFoundException {String coupon_id = null;Class.forName(driver);Connection connection = DriverManager.getConnection(url, user, password);if (!connection.isClosed()) {Statement statement = connection.createStatement();String sql = "SELECT * FROM op_coupon LEFT JOIN op_coupon_used on op_coupon.coupon_id = op_coupon_used.coupon_id WHERE op_coupon_used.order_no is null limit 1";ResultSet result = statement.executeQuery(sql);//output("帐号"+"\t"+"密码");while(result.next()){coupon_id = result.getString("serial_no");//output(result.getString("serial_no")+"\t"+result.getString("serial_password"));}result.close();connection.close();}return coupon_id;}
0 0
- selenium2java利用mysql实现重复购买用例
- selenium2java微信支付宝购买功能测试用例
- selenium2java 一个利用mysql获取验证码注册新用户的测试用例
- selenium2java一个用自定义方法写的测试用例
- selenium2java 遇到有三个窗口用例的处理办法
- 利用socket实现在线购买电脑零配件
- 利用保利威视实现教育视频预览和购买
- selenium2java一个弹框上传时间日期大杂烩测试用例
- 通过调用关键字来实现测试用例---重复利用百度搜索
- mysql实现避免重复插入
- js 实现下拉列表的重复利用
- js封装下拉框,实现重复利用
- selenium2java 自定义一个用参数控制等待时间的方法
- selenium2java自定义一个用js点击元素的方法
- selenium2java利用mysq解决向浏览器插入cookies时token过期问题
- iphone 程购买实现
- Android:实现装备购买
- MySql利用数据库实现交集
- [android]笔记5-TableLayout
- 微服务架构的基础框架选择:Spring Cloud还是Dubbo?
- PyQt5与QML通信
- java 两个list 交集 并集 差集 去重复并集
- Ueditor总结
- selenium2java利用mysql实现重复购买用例
- TCP/IP 协议
- Cassandra集群搭建(包含监控)
- html忽略标签关键字标记
- 对象与json互转中的注意事项
- update的三种实现方法
- Jquery中的遍历
- linux---正则表达式
- 作业五