cls.ui.model.selenium.carDealerManage.BasicInfoPage.java Source code

Java tutorial

Introduction

Here is the source code for cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

Source

package cls.ui.model.selenium.carDealerManage;

import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import cls.ui.base.BaseWebDriver;
import cls.ui.base.Config;

public class BasicInfoPage extends BaseWebDriver {

    private static Config config = new Config();

    //??
    public Boolean isLoadSuccess() {
        driver.switchTo().defaultContent();
        driver.switchTo().frame("iframe_undefined");
        new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.id("dealerName")));
        Boolean flag = false;
        WebElement dealerName = driver.findElement(By.id("dealerName"));
        if (dealerName != null) {
            flag = true;
        }
        return flag;
    }

    //??
    public void enterDealerName(String dealerNameString) throws Throwable {
        WebElement dealerName = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[1]/div[1]/div/input"));
        dealerName.clear();
        dealerName.sendKeys(dealerNameString);
    }

    //???
    public void clickGetInfo() throws Throwable {
        WebElement getInfoBtn = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[1]/div[2]/div/button"));
        getInfoBtn.click();
    }

    //
    public void selectCarDealerType(String carDealerTypeString) throws Throwable {
        WebElement carDealerType = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[2]/fieldset/div[1]/div/select"));
        Select mySelect = new Select(carDealerType);
        mySelect.selectByVisibleText(carDealerTypeString);
    }

    //???????
    public void selectRecommendName(String recommendName) throws Throwable {
        WebElement recommendNameSelect = driver.findElement(By.id("employDealerId"));
        Select mySelect = new Select(recommendNameSelect);
        mySelect.selectByVisibleText(recommendName);
    }

    //???
    public void enterContactName(String contactNameString) throws Throwable {
        WebElement contactName = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[1]/div/input"));
        contactName.clear();
        contactName.sendKeys(contactNameString);
    }

    //??
    public void enterContactPhone(String contactPhoneString) throws Throwable {
        WebElement contactPhone = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[2]/div/input"));
        contactPhone.clear();
        contactPhone.sendKeys(contactPhoneString);
    }

    //?? true ?false
    public void selectDiscount(String isDiscount) throws Throwable {
        WebElement discount = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[3]/div/label[1]/input"));
        WebElement unDiscount = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[3]/div/label[2]/input"));
        if (isDiscount.equalsIgnoreCase("true") == true) {
            discount.click();
        } else {
            unDiscount.click();
        }
    }

    //?
    public void selectProvince(String province) throws Throwable {
        WebElement provinceSelect = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[1]/div/select"));
        Select mySelect = new Select(provinceSelect);
        mySelect.selectByVisibleText(province);
        Thread.sleep(1000);
    }

    //
    public void selectCity(String city) throws Throwable {
        WebElement citySelect = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[2]/div/select"));
        Select mySelect = new Select(citySelect);
        mySelect.selectByVisibleText(city);
        Thread.sleep(1000);
    }

    //
    public void selectArea(String area) throws Throwable {
        WebElement areaSelect = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[3]/div/select"));
        Select mySelect = new Select(areaSelect);
        mySelect.selectByVisibleText(area);
    }

    //?
    public void enterDetailAddress(String detailAddress) throws Throwable {
        WebElement detailAddressInput = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[5]/div/div/input"));
        detailAddressInput.clear();
        detailAddressInput.sendKeys(detailAddress);
    }

    //???
    public void enterCardNo(String cardNo) throws Throwable {
        WebElement cardNoInput = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[8]/div[3]/div/input"));
        cardNoInput.clear();
        cardNoInput.sendKeys(cardNo);
    }

    //?
    public void enterEmployeeNum(String employeeNum) throws Throwable {
        WebElement employeeNumInput = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[9]/div[1]/div/input"));
        employeeNumInput.clear();
        employeeNumInput.sendKeys(employeeNum);
    }

    //??
    public void enterPlaceProportion(String placeProportion) throws Throwable {
        WebElement placeProportionInput = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[9]/div[2]/div/input"));
        placeProportionInput.clear();
        placeProportionInput.sendKeys(placeProportion);
    }

    //?
    public void enterSalesVolume(String salesVolume) throws Throwable {
        WebElement salesVolumeInput = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[9]/div[3]/div/input"));
        salesVolumeInput.clear();
        salesVolumeInput.sendKeys(salesVolume);
    }

    //?
    public void uploadBusinessLicense() throws Throwable {
        WebElement businessLicenseBtn = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[11]/div/div/button[1]"));
        businessLicenseBtn.click();
        Thread.sleep(1000);
        uploadFileAfterClick();
    }

    //?
    private void uploadFileAfterClick() throws Throwable {
        try {

            Runtime.getRuntime().exec(getUploadFilePath());
            Thread.sleep(3000);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //?
    public void uploadBusinessPlace() throws Throwable {
        WebElement businessPlaceBtn = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[12]/div/div/button[1]"));
        businessPlaceBtn.click();
        uploadFileAfterClick();
    }

    //?
    public void uploadConfirmation() throws Throwable {
        WebElement confirmationBtn = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[13]/div/div/button[1]"));
        confirmationBtn.click();
        uploadFileAfterClick();
    }

    //???
    public void uploadAgreement() throws Throwable {
        WebElement agreementBtn = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[14]/div/div/button[1]"));
        agreementBtn.click();
        uploadFileAfterClick();
    }

    //?
    public void clickSaveButton() throws Throwable {
        WebElement saveBtn = driver.findElement(
                By.xpath("/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[2]/div/button"));
        saveBtn.click();
    }

    //
    public void clickAddAccountButton() throws Throwable {
        WebElement addAccountBtn = driver.findElement(By.xpath(
                "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[3]/div/div[1]/div[2]/ul/li/a"));
        addAccountBtn.click();
        Thread.sleep(2000);
    }

    //??
    public void enterAccountName(String accountName) throws Throwable {
        WebElement accountNameText = driver.findElement(
                By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[1]/div[1]/div[1]/div/input"));
        accountNameText.clear();
        accountNameText.sendKeys(accountName);
    }

    //
    public void selectBankName(String bankName) throws Throwable {
        WebElement bankNameSelect = driver.findElement(
                By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[1]/div[1]/div[2]/div/select"));
        Select mySelect = new Select(bankNameSelect);
        mySelect.selectByVisibleText(bankName);
    }

    //??
    public void enterSubBankName(String subBankName) throws Throwable {
        WebElement subBankNameText = driver.findElement(
                By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[1]/div[2]/div[1]/div/input"));
        subBankNameText.clear();
        subBankNameText.sendKeys(subBankName);
    }

    //??
    public void enterBankCardNum(String bankCardNum) throws Throwable {
        WebElement cardNumText = driver.findElement(
                By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[1]/div[2]/div[2]/div/input"));
        cardNumText.clear();
        cardNumText.sendKeys(bankCardNum);
    }

    //
    public void selectAccountType(String accountType) throws Throwable {
        WebElement accountTypeSelect = driver
                .findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[1]/div[3]/div/div/select"));
        Select mySelect = new Select(accountTypeSelect);
        mySelect.selectByVisibleText(accountType);
    }

    //
    public void enterRemark(String remark) throws Throwable {
        WebElement remarkText = driver.findElement(
                By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[1]/div[4]/div/div/textarea"));
        remarkText.clear();
        remarkText.sendKeys(remark);
    }

    //?
    public void clickAddDialogSaveButton() throws Throwable {
        WebElement saveBtn = driver
                .findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[2]/button[1]"));
        saveBtn.click();
    }

    //?
    public void clickAddDialogCancelButton() throws Throwable {
        WebElement cancelBtn = driver
                .findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div/div/form/div[2]/button[1]"));
        cancelBtn.click();
    }

    //??
    public void clickSubmitButton() throws Throwable {
        WebElement submitBtn = driver
                .findElement(By.xpath("/html/body/div/div[1]/div[1]/div[3]/div/div/div/div/span/button[1]"));
        submitBtn.click();
    }

    //??
    public void clickConfirmYesButton() throws Throwable {
        WebElement confirmBtn = driver
                .findElement(By.xpath("/html/body/div[1]/div[1]/div[5]/div/div/div[3]/button[1]"));
        confirmBtn.click();
    }

    //???
    public void clickConfirmNoButton() throws Throwable {
        WebElement cancelBtn = driver
                .findElement(By.xpath("/html/body/div[1]/div[1]/div[5]/div/div/div[3]/button[2]"));
        cancelBtn.click();
    }
}