com.nexenta.qa.bs.wz.Test1Reg.java Source code

Java tutorial

Introduction

Here is the source code for com.nexenta.qa.bs.wz.Test1Reg.java

Source

package com.nexenta.qa.bs.wz;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import static org.testng.Assert.assertEquals;

/**
 * Created by user on 08.02.14.
 */
public class Test1Reg {
    WebDriver driver;
    RegPanel reg;
    public static Logger logger = LoggerFactory.getLogger(Test1Reg.class);

    @BeforeClass
    public void setUPbro() throws MalformedURLException {
        //Get Props
        Properties prop = new Properties();
        reg = new RegPanel();
        InputStream input = null;
        try {
            input = new FileInputStream(System.getProperty("propFile"));
            prop.load(input);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        // create driver
        driver = new RemoteWebDriver(new URL("http://" + prop.getProperty("WCM") + ":4444/wd/hub"),
                DesiredCapabilities.firefox());

        driver.get("http://" + prop.getProperty("MUT") + ":8457/register/");
        String needlogin = driver.getTitle();
        logger.info(needlogin);
        if (needlogin.equals("NMV Login")) {
            WebElement nameu = driver.findElement(By.name("_nmv_username_"));
            WebElement passu = driver.findElement(By.name("_nmv_password_"));
            nameu.sendKeys("admin");
            passu.sendKeys("nexenta");
            driver.findElement(By.name("_nmv_login_")).click();
            driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        }

    }

    @AfterClass
    public void stopBro() {
        //       driver.quit();
    }

    @Test
    public void registerMe() {
        WebElement msig = driver.findElement(By.id(reg.MachineSigById));
        String machinesig = msig.getAttribute("value");
        //String machinesig = driver.findElement(By.id(reg.MachineSigById)).get);
        logger.info("MSIG: " + machinesig);

        try {

            Process p = Runtime.getRuntime().exec(
                    "/usr/bin/perl /home/user/selenium/utils/nxt-key/gen-com-key.pl " + machinesig + " TRIA 99");
            String line;
            BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
            line = in.readLine();
            logger.info("LICENCE: " + line);
            WebElement lic = driver.findElement(By.id(reg.LicenseFieldByID));
            lic.clear();
            lic.sendKeys(line);
            in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

        driver.findElement(By.id(reg.RegisterOK)).click();
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

        assertEquals(driver.getTitle(), "Nexenta Management View: Appliance and Group Status");

    }
}