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+",测试通过"); } }