com.solidmaps.test.po.LicenseExercitoInsertPO.java Source code

Java tutorial

Introduction

Here is the source code for com.solidmaps.test.po.LicenseExercitoInsertPO.java

Source

package com.solidmaps.test.po;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.Select;

import com.solidmaps.test.form.LicenseExercitoForm;
import com.solidmaps.test.form.ProductExercitoForm;

public class LicenseExercitoInsertPO {

    private RemoteWebDriver driver;

    public LicenseExercitoInsertPO(RemoteWebDriver driver) {
        this.driver = driver;
    }

    public LicenseExercitoListPO submit(LicenseExercitoForm form) {

        JavascriptExecutor executor = (JavascriptExecutor) driver;

        new Select(driver.findElement(By.id("select-company"))).selectByValue(form.getIdCompany());
        driver.findElement(By.name("numRegister")).sendKeys(form.getNumCertified());
        new Select(driver.findElement(By.id("select-responsable"))).selectByValue(form.getIdUser());
        driver.findElement(By.name("dateExpiration")).sendKeys(form.getDateExpiration());
        driver.findElement(By.name("protocolRenovation")).sendKeys(form.getCodProtocol());

        for (ProductExercitoForm productExercito : form.getListProducts()) {

            driver.findElement(By.className("ui-autocomplete-input"))
                    .sendKeys(productExercito.getProduct().getOfficialName());
            driver.findElement(By.name("Aquisio (Compra)")).sendKeys(productExercito.getQtdBuy());
            driver.findElement(By.name("Utilizao Industrial"))
                    .sendKeys(productExercito.getQtdIndustryUtilization());
            driver.findElement(By.name("Exportao")).sendKeys(productExercito.getQtdExport());
            driver.findElement(By.name("Comrcio")).sendKeys(productExercito.getQtdSell());
            driver.findElement(By.name("Utilizao Laboratorial"))
                    .sendKeys(productExercito.getQtdLaboratoryUtilization());
            driver.findElement(By.name("Importao")).sendKeys(productExercito.getQtdImport());

            WebElement addButton = driver.findElement(By.id("btnAddProduct"));
            executor.executeScript("arguments[0].click();", addButton);

        }

        WebElement submitButton = driver.findElement(By.name("btnSubmit"));
        executor.executeScript("arguments[0].click();", submitButton);

        return new LicenseExercitoListPO(driver);

    }

    public String getErrorMsg() {
        return driver.findElement(By.id("errorMsg")).getText();
    }

    public String getProductName(String idProduct) {

        return driver.findElement(By.id(idProduct)).getText();

    }

}