Selenium Verifying vehicle Loan calculator algorithm

Source: Internet
Author: User
Tags gettext testng

1. Verify that the car loan calculator on the page matches the result of the formula given in the requirement.

Page Image:

The code is as follows (simple implementation, need to be optimized):

 Packagecom.test;ImportJava.math.BigDecimal;ImportOrg.junit.Assert;Importorg.openqa.selenium.By;ImportOrg.testng.Reporter;ImportOrg.testng.annotations.AfterClass;ImportOrg.testng.annotations.BeforeClass;Importorg.testng.annotations.Listeners;Importorg.testng.annotations.Test;ImportCom.core.base.MidConvert;/**  * @authorQiaojiafei *@versioncreated: December 4, 2015 2:23:36 * class description*/@Listeners ({com.core.base.BaseListener.class}) Public classTestlaiyongcheextendsmidconvert{String URL= "Http://172.16.30.243:8888/offical/home.action"; DoubleCar_shoujia = 5000000.36;//Vehicle Price    DoubleCar_other = 1000.55;//Other Fees    DoubleCAR_SFBL = 40.21;//Down payment ratio    intCar_zuqi = 24;//Vehicle Rental Period@BeforeClass Public voidbefore () {Super. Initdriver (); //http://172.16.30.243: 8888/offical/home.actiondr.get (URL); LC= Cm.getlocator ("LinkText", "Business Guide");        Cm.click (LC); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } LC= Cm.getlocator ("ClassName", "MARGINBOTTOM20"); Dr.findelement (By.classname ("MARGINBOTTOM20")). Findelements (By.tagname ("button")). Get (3). Click (); } @AfterClass Public voidAfter () {Super. TearDown (); } @Test Public voidtestsuixin () {Testmain ("Fast Melt", "1", Car_zuqi);//1-New cars, 2-used cars, 3-lcv,4-micro surfaceTestmain ("Fast Melt", "2", Car_zuqi); Testmain ("Fast Melt", "3", Car_zuqi); } @Test Public voidTestjs () {Testmain ("Harmony", "1", Car_zuqi); } @Test Public voidTestkx () {Testmain ("Happy Melting", "4", Car_zuqi); }         Public voidTestmain (string pd, String ct,intCarz) {String Product= PD;//Financing ProductsString cartype = ct;//Type of vehicle//type of vehicle:LC = Cm.getlocator ("id", "cartype");                Cm.select (LC, CT); //Financing Products:LC = Cm.getlocator ("id", "Product");                Cm.select (LC, product); //Vehicle Price:LC = Cm.getlocator ("id", "carprice");        Cm.type (LC, String.valueof (Car_shoujia)); //Other Fees:LC = Cm.getlocator ("id", "otherprice");                Cm.type (LC, String.valueof (Car_other)); //Vehicle Rental Period:LC = Cm.getlocator ("id", "tenancy");                Cm.select (LC, String.valueof (Car_zuqi)); //Down payment ratioLC = 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)); //margin ratioString s = dr.findelement (By.id ("bail") . GetText (); DoubleBZJ = 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 blockE.printstacktrace (); }        DoubleRe_sfje = car_shoujia*car_sfbl/100 +bzj;//amount of down payment        DoubleRe_rzje = Car_shoujia-re_sfje + car_other;//Financing Amount                DoubleNLL = 0;//Monthly interest Rate        if(Product.equals ("Harmony")) ) {NLL= 0.17680; }Else if(Product.equals ("fast-melting")) {            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 ("Free to Melt") ) {NLL= 0.18680; }Else if(Product.equals ("Happy Harmony") ) {NLL= 0.25970; }Else if(Product.equals ("Love and Harmony")) ) {NLL= 0.19680; }        DoubleYll = NLL/12; DoubleA = 1+Yll; Doubleb =Car_zuqi; Doubletemp =Math.pow (A, b); DoubleRe_yg = (re_rzje*yll*temp)/(TEMP-1);//amount of monthly contribution//BigDecimal bd1 = new BigDecimal (RE_YG); //Double f1 = Bd1.setscale (2, bigdecimal.round_half_up). Doublevalue ();                DoubleRe_rg = RE_YG/30;//Daily Supply//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 (NewJava.text.DecimalFormat ("#.##"). Format (Re_rzje), Ac_rzje); Assert.assertequals (NewJava.text.DecimalFormat ("#.##"). Format (Re_sfje), ac_sfje); Assert.assertequals (NewJava.text.DecimalFormat ("#.##"). Format (RE_YG), AC_YG); Assert.assertequals (NewJava.text.DecimalFormat ("#.##"). Format (RE_RG), AC_RG); Reporter.log (PD+ "," +ct+ ", test Pass"); }}

Selenium Verifying vehicle Loan calculator algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.