selenium验证车贷计算器算法
1.验证页面上的车贷计算器算的结果是否与需求中给的公式结果一致。
页面图片:

代码如下(简单实现,需要优化):
package com.test; import java.math.BigDecimal; import org.junit.Assert;
import org.openqa.selenium.By;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test; import com.core.base.MidConvert; /**
* @author QiaoJiafei
* @version 创建时间:2015年12月4日 下午2:23:36
* 类说明
*/
@Listeners({com.core.base.BaseListener.class})
public class Testlaiyongche extends MidConvert{
String url = "http://172.16.30.243:8888/offical/home.action";
double car_shoujia = 5000000.36;//车辆售价
double car_other = 1000.55;//其他费
double car_sfbl = 40.21;//首付比例
int car_zuqi = 24;//车辆租期 @BeforeClass
public void before() {
super.initDriver();
//http://172.16.30.243:8888/offical/home.action
dr.get(url);
lc = cm.getLocator("linkText", "业务指南");
cm.click(lc);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
lc = cm.getLocator("className", "marginbottom20");
dr.findElement(By.className("marginbottom20")).findElements(By.tagName("button")).get(3).click();
}
@AfterClass
public void after() {
super.tearDown();
}
@Test
public void testSuiXin() {
testmain("极速融","1",car_zuqi);//1-新车,2-二手车,3-LCV,4-微面
testmain("极速融","2",car_zuqi);
testmain("极速融","3",car_zuqi);
} @Test
public void testJs() {
testmain("随心融","1",car_zuqi);
}
@Test
public void testKx() {
testmain("开心融","4",car_zuqi);
} public void testmain(String pd, String ct, int carz) {
String product = pd;//融资产品
String cartype = ct;//车辆类型
//车辆类型:
lc = cm.getLocator("id", "carType");
cm.select(lc, ct); //融资产品:
lc = cm.getLocator("id", "product");
cm.select(lc, product); //车辆售价:
lc = cm.getLocator("id", "carPrice");
cm.type(lc, String.valueOf(car_shoujia)); //其他费用:
lc = cm.getLocator("id", "otherPrice");
cm.type(lc, String.valueOf(car_other)); //车辆租期:
lc = cm.getLocator("id", "tenancy");
cm.select(lc, String.valueOf(car_zuqi)); //首付比例
lc = cm.getLocator("xpath", "/html/body/section[2]/div/div/div/div/div[2]/div[4]/div[1]/table[2]/tbody/tr[6]/td[2]/input");
cm.type(lc, String.valueOf(car_sfbl)); //保证金比例
String s = dr.findElement(By.id("bail")).getText();
double bzj = car_shoujia*Integer.parseInt(s)/100; lc = cm.getLocator("id", "calculation");
cm.click(lc);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
double re_sfje = car_shoujia*car_sfbl/100 +bzj;//首付金额
double re_rzje = car_shoujia - re_sfje + car_other;//融资金额 double nll = 0;//月利率
if(product.equals("随心融")) {
nll = 0.17680;
}else if(product.equals("极速融")) {
if(cartype.equals("1")) {
nll = 0.17680;
}else if (cartype.equals("2")) {
nll = 0.18680;
}else if(cartype.equals("3")) {
nll = 0.19680;
}
}else if (product.equals("随意融")) {
nll = 0.18680;
}else if(product.equals("开心融")) {
nll = 0.25970;
}else if (product.equals("爱心融")) {
nll = 0.19680;
}
double yll = nll / 12;
double a = 1+yll;
double b = car_zuqi;
double temp = Math.pow(a, b); double re_yg = (re_rzje*yll*temp)/(temp-1);//月供金额
//BigDecimal bd1 = new BigDecimal(re_yg);
//double f1 = bd1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); double re_rg = re_yg/30;//日供
//BigDecimal bd2 = new BigDecimal(re_rg);
//double f2 = bd2.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); String ac_rzje = dr.findElement(By.id("financingAm")).getText();
String ac_sfje = dr.findElement(By.id("firstPay")).getText();
String ac_yg = dr.findElement(By.id("monthlyPay")).getText();
String ac_rg = dr.findElement(By.id("dayPay")).getText();
//System.out.println(ac_rzje+"------------"); Assert.assertEquals(new java.text.DecimalFormat("#.##").format(re_rzje), ac_rzje);
Assert.assertEquals(new java.text.DecimalFormat("#.##").format(re_sfje), ac_sfje);
Assert.assertEquals(new java.text.DecimalFormat("#.##").format(re_yg), ac_yg);
Assert.assertEquals(new java.text.DecimalFormat("#.##").format(re_rg), ac_rg); Reporter.log(pd+","+ct+",测试通过");
}
}
selenium验证车贷计算器算法的更多相关文章
- IOS OC 计算器算法(不考虑优先级)
个人见解:为还在计算器算法方面迷惑的同学一个数据处理解决方案:定义一个可变数组array,一个可变字符串str,使字符通过[array addObject:str];方法添加到可变数组,每当触发运算符 ...
- Python开发——利用正则表达式实现计算器算法
Python开发--利用正则表达式实现计算器算法 (1)不使用eval()等系统自带的计算方法 (2)实现四则混合运算.括号优先级解析 思路: 1.字符串预处理,将所有空格去除 2.判断是否存在括号运 ...
- iOS 收款计算器算法
一个收款计算器算法,从之前高仿有赞Demo里面抽离的一个界面 demo 在这里 https://github.com/L-vinCent/calculView_function 显示计算记录 不能连续 ...
- 基于COCO数据集验证的目标检测算法天梯排行榜
基于COCO数据集验证的目标检测算法天梯排行榜 AP50 Rank Model box AP AP50 Paper Code Result Year Tags 1 SwinV2-G (HTC++) 6 ...
- hdoj 2063 过山车【匈牙利算法+邻接矩阵or邻接表】
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- Selenium 验证picklist是可被正确选中且是有序的(动态数组赋值)
原代码: <select id="edit-submitted-im-interesting-in" class="form-select required&quo ...
- hdu 2063 过山车【匈牙利算法】(经典)
<题目链接> RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partne ...
- hdu-2063-过山车(匈牙利算法)
过山车 Problem Description RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找 ...
- HDU 2063.过山车-Hungary(匈牙利算法)
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- iostat命令
http://www.orczhou.com/index.php/2010/03/iostat-detail/ Linux系统出现了性能问题,一般我们可以通过top.iostat.free.vmsta ...
- 下面介绍一下 Yii2.0 对数据库 查询的一些简单的操作
下面介绍一下 Yii2.0 对数据库 查询的一些简单的操作 User::find()->all(); 此方法返回所有数据: User::findOne($id); 此方法返回 主键 id=1 的 ...
- C语言回滚(三)-指针
#include <stdio.h>#include <stdlib.h> //& 地址运算符 //* 间接运算符 // *的作用 当*后面跟一个指针名或地址的时候, ...
- mongodb学习3---mongo的MapReduce
1,概述MapReduce是个非常灵活和强大的数据聚合工具.它的好处是可以把一个聚合任务分解为多个小的任务,分配到多服务器上并行处理.MongoDB也提供了MapReduce,当然查询语肯定是Java ...
- 关于IE处理margin和padding值超出父元素高度的问题
两个div,父div有padding值,子div有margin-top值,浏览器在解析实际父子位置关系时,他们之间的距离是父padding+子margin-top.现在把父div设置固定高度,并有意让 ...
- ajax使用
ajax基本使用 ajax在我们的开发中是必须使用的一个技术,ajax即异步的javascript和xml但是现在我们通常使用json来完成数据的交互,ajax职责很单一就是数据的交互,发送数据接收数 ...
- mvc项目架构分享系列之架构搭建之Infrastructure
项目架构搭建之Infrastructure的搭建 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构 ...
- 代码导出Reporting Services报表文件
背景部分 使用Reporting Services很容易制作和发布我们需要的报表,报表效果也还不错 不过如果报表数据过大或报表数量过多,打开及查看报表感觉可能就是另外一回事了 好在Reporting ...
- java多线程系列8-线程的优先级
在java中设置线程优先级使用setPriority,在jdk中的源代码如下: public final void setPriority(int newPriority) { ThreadGroup ...
- C语言异常与断言接口与实现
程序中通常会出现三种错误:用户错误.运行期错误以及异常 欢迎关注我的个人博客:www.wuyudong.com, 更多精彩文章与您分享 标准库函数setjmp和longjmp 在C语言中,标准库函数s ...