com.coderoad.automation.rocketTruedx.RocketTruedxNaTestBase.java Source code

Java tutorial

Introduction

Here is the source code for com.coderoad.automation.rocketTruedx.RocketTruedxNaTestBase.java

Source

/*
 * CP3TestBase.java
 * Copyright (c) 2014, coderoad, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of coderoad
 * ("Confidential Information"). You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you entered into with
 * coderoad.
 */
package com.coderoad.automation.rocketTruedx;

import static com.coderoad.automation.common.manager.ConfigManager.*;
import static com.coderoad.automation.core.manager.DriverManager.*;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.*;
import org.testng.annotations.*;

import com.coderoad.automation.common.enums.*;
import com.coderoad.automation.common.exception.*;
import com.coderoad.automation.common.log.*;
import com.coderoad.automation.common.util.old.TestLogger;
import com.coderoad.automation.common.util.old.TestResource;
import com.coderoad.automation.common.util.old.TestUtils;
import com.coderoad.automation.core.base.*;
import com.coderoad.automation.core.manager.*;

// TODO: Auto-generated Javadoc
/**
 * this is the base class for the tests.
 * 
 * @author Ruth Chirinos
 * @version 1, 20150401
 */
public class RocketTruedxNaTestBase extends AbstractTest {

    //Driver for all test cases
    public static WebDriver driver;

    /**
     * Sets the up method.
     * 
     * @param context the new up method
     * @throws DriverException the driver exception
     */
    @BeforeSuite(alwaysRun = true)
    public void setup(final ITestContext context) throws DriverException {

    }

    /**
     * Sets the up selenium.
     * 
     * @param context the new up selenium
     * @throws DriverException the driver exception
     */
    @BeforeTest(alwaysRun = true)
    public void setupSelenium(final ITestContext context) throws DriverException {
        TestUtils.rocketTruedxBuild = RocketTruedxNaTestBase.getRocketTruedxBuildNo();

        loadConfig("testData.properties");
        TestCaseLogUtil.printAllTestcases(context);
        if (checkMandatoryParameter()) {
            DriverManager.initializeDriver();
            driver = DriverManager.getDriver();
            driver.manage().window().maximize();
        } else {
            String message = "Mandatory Parameters are not provided";
            throw new DriverException(message);
        }
    }

    /**
     * this method returns the build number for the DP7 build.
     * 
     * @return the d p7 build no
     */
    private static String getRocketTruedxBuildNo() {

        if (TestUtils.xtHost == null)
            return "";
        String versionURL = TestUtils.xtHost + TestResource.getURL("URL.rocket.truedx");
        String version = TestUtils.getBuildNo(versionURL);
        return version;
    }

    /**
     * Tear down.
     */
    @AfterMethod
    public void tearDown() {

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * Close selenium.
     */
    @AfterTest
    public void closeSelenium() {

        DriverManager.close();
    }

    /**
     * Cease.
     */
    @AfterSuite(alwaysRun = true)
    public void cease() {

    }

    /**
     * this method open the Rocket Truedx Na URL.
     * 
     * @throws InterruptedException the interrupted exception
     */
    public void openPage() throws InterruptedException {
        driver.get(this.getRocketTruedxUrl());
        Thread.sleep(2000);
    }

    /**
     * Gets the c p3 url.
     * 
     * @param webKey the web key
     * @return the c p3 url
     */
    protected String getRocketTruedxUrl() {

        return TestUtils.getRocketTruedxUrl();
    }

    /**
     * Wait for element.
     * 
     * @param by the by
     * @return the web element
     */
    protected WebElement waitForElement(final By by) {

        WebElement element = null;
        TestLogger.logMsg("Start waitForElement : + " + TestUtils.getTimeStamp());
        for (int i = 0; i < 3; i++) {
            element = new WebDriverWait(driver, TestUtils.timeout).until(new ExpectedCondition<WebElement>() {
                @Override
                public WebElement apply(WebDriver d) {

                    return d.findElement(by);
                }
            });
            TestLogger.logMsg("Wait waitForElement : + " + TestUtils.getTimeStamp());
        }
        TestLogger.logMsg("Done waitForElement : + " + TestUtils.getTimeStamp());
        return element;
    }

    /**
     * this method returns the build number for the DP7 build.
     * 
     * @return the d p7 build no
     */
    //   private static String getDP7BuildNo() {
    //
    //      if (TestUtils.xwsHost == null)
    //         return "";
    //      String versionURL = TestUtils.xwsHost + TestResource.getURL("URL.cm3.buildNo");
    //      String version = TestUtils.getBuildNo(versionURL);
    //      return version;
    //   }

    /**
     * Gets the cust name for link.
     * 
     * @param custfname the custfname
     * @param custlname the custlname
     * @return the cust name for link
     */
    //   protected String getCustNameForLink(String custfname, String custlname) {
    //
    //      return (custlname + ", " + custfname);
    //   }

    /**
     * this method creates customer and check of existing customer and updates
     * the username & pwd for the user.
     * 
     * @param dealer the dealer
     * @param validusr the validusr
     * @param validpwd the validpwd
     * @param custDmsId the cust dms id
     * @param custfname the custfname
     * @param custlname the custlname
     * @param custemail the custemail
     * @param phoneno the phoneno
     * @param state the state
     * @param vYear the v year
     * @param vMake the v make
     * @param vModel the v model
     * @param vTrim the v trim
     * @param vDrive the v drive
     * @param vVin the v vin
     * @throws InterruptedException the interrupted exception
     */
    //   public void CheckAndCreateCustomer(BusinessPortal business, Customer customer, Vehicle vehicle) throws InterruptedException {
    //
    //      TestLogger.logMsg("createCustomer method");
    //      BusinessLoginPage loginPage = PageFactory.initElements(DP7TestBase.driver, BusinessLoginPage.class);
    //      DealerSearchPage dsearchPage = loginPage.loginToBizPortal();
    //      BusinessLedgerPage ledgerPage = dsearchPage.launchDealer(business.getDealer());
    //      // check whether the user exist, if the customer exist make sure to
    //      // update password for the
    //      // user
    //      String custlink = this.getCustNameForLink(customer.getName().getFirstName(), customer.getName().getLastName());
    //      boolean status = ledgerPage.checkCustExistFixUsrPwd(custlink, customer.getUserName(), customer.getPassword());
    //      if (!status) {
    //         NewCustomerPage newCustPage = ledgerPage.clickOnNewCustomer();
    //         newCustPage.addNewCustomer(customer.getDmsId(), customer.getName().getFirstName(), customer.getName().getLastName(),
    //                 "", customer.getEmail(), customer.getPhoneNo(), customer.getState(), customer.getUserName(),
    //                 customer.getPassword(), vehicle.getYear(), vehicle.getMake(), vehicle.getModel(), vehicle.getTrim(),
    //                 vehicle.getDrive(), vehicle.getVin());
    //         // newCustPage.addNewCustomer("001CP3", custfname, custlname, "",
    //         // custemail,
    //         // phoneno,"California",
    //         // validusr,validpwd, "2008", "INFINITI", "G35", "Base Sedan",
    //         // "RWD","JNKBV61E28M21174");
    //      } else
    //         TestLogger.logMsg("Status exisit");
    //   }

    /**
     * this method creates customer and check of existing customer and updates
     * the username & pwd for the user.
     * 
     * @param webkey the webkey
     * @param dealer the dealer
     * @param validusr the validusr
     * @param validpwd the validpwd
     * @param custDmsId the cust dms id
     * @param custfname the custfname
     * @param custlname the custlname
     * @param custemail the custemail
     * @param phoneno the phoneno
     * @param state the state
     * @param vYear the v year
     * @param vMake the v make
     * @param vModel the v model
     * @param vTrim the v trim
     * @param vDrive the v drive
     * @param vVin the v vin
     * @throws InterruptedException the interrupted exception
     */
    //   public void CheckAndCreateCustomerWithNoUserName(String webkey, BusinessPortal business, Customer customer, Vehicle vehicle)
    //           throws InterruptedException {
    //
    //      TestLogger.logMsg("createCustomer method");
    //      BusinessLoginPage loginPage = PageFactory.initElements(driver, BusinessLoginPage.class);
    //      DealerSearchPage dsearchPage = loginPage.loginToBizPortal();
    //      BusinessLedgerPage ledgerPage = dsearchPage.launchDealer(business.getDealer());
    //      // check whether the user exist, if the customer exist make sure to
    //      // update password for the
    //      // user
    //      String custlink = this.getCustNameForLink(customer.getName().getFirstName(), customer.getName().getLastName());
    //      boolean status = ledgerPage.checkCustExistFixUsrPwd(custlink, customer.getUserName(), customer.getPassword());
    //      if (!status) {
    //         NewCustomerPage newCustPage = ledgerPage.clickOnNewCustomer();
    //         newCustPage.addNewCustomer(customer.getDmsId(), customer.getName().getFirstName(), customer.getName().getLastName(),
    //                 "", customer.getEmail(), customer.getPhoneNo(), customer.getState(), "", "", vehicle.getYear(),
    //                 vehicle.getMake(), vehicle.getModel(), vehicle.getTrim(), vehicle.getDrive(), vehicle.getVin());
    //         // newCustPage.addNewCustomer("001CP3", custfname, custlname, "",
    //         // custemail,
    //         // phoneno,"California",
    //         // validusr,validpwd, "2008", "INFINITI", "G35", "Base Sedan",
    //         // "RWD","JNKBV61E28M21174");
    //      } else
    //         TestLogger.logMsg("Status exisit");
    //   }   

}// End CP3TestBase