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

Java tutorial

Introduction

Here is the source code for com.solidmaps.test.po.LicenseFederalInsertPO.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.LicenseFederalForm;
import com.solidmaps.test.form.ProductForm;

public class LicenseFederalInsertPO {

    private RemoteWebDriver driver;

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

    public LicenseFederalListPO submit(LicenseFederalForm form) {

        JavascriptExecutor executor = (JavascriptExecutor) driver;

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

        for (ProductForm product : form.getListProducts()) {

            driver.findElement(By.className("ui-autocomplete-input")).sendKeys(product.getOfficialName());
            driver.findElement(By.className("ui-menu-item")).click();

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

        }

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

        return new LicenseFederalListPO(driver);

    }

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

    public String getProductName(String nameProduct) {

        return driver
                .findElement(
                        By.xpath("//table[@id='productsTable']//tr//td[contains(text(),'" + nameProduct + "')]"))
                .getText();

    }

}