samedi 30 juin 2018

Getting error : org.openqa.selenium.WebDriverException: unknown error: keys should be a string

I am getting the error to access the data from the properties file in my selenium UI : How can this be solved ?

org.openqa.selenium.WebDriverException: unknown error: keys should be a string.

I have the following framework. I made it for my self for ease, looks like complicating myself. If any good ideas to better it, please suggest. Appreciate all suggestions.

Framework contains the following : 1. config properties file 2. utilities class 3. Page elements definition class file 4. reusable functions class file 5. test classes

config.properties file has the following content :

url=http://some.com
username=someuser
password=somepassword

utilities class (BrowserCalls) the following code :

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class BrowserCalls {

    public WebDriver driver;
    public Properties configs = new Properties();
    public String pathToProperties = "path to config.properties file";

    public void invokeChromeBrowser() throws IOException {

        FileInputStream input = new FileInputStream(pathToProperties);
        pmsConfigs.load(input);
        System.setProperty("webdriver.chrome.driver", configs.getProperty("chromepath"));
        driver = new ChromeDriver();
        getAndMazimize();

    }

    private void getAndMazimize(){

        driver.get(configs.getProperty("url"));
        driver.manage().window().maximize();

    }


    public void closeChromeBrowser(){

        if(driver != null){

            driver.close();
        }

    }


}

Page elements definition class file has the following code :

import org.openqa.selenium.By;

public class LoginPageElements {


    //Login page elements
    public static By element1 = By.xpath("/html/head/link[1]");
    public static By username = By.xpath("//*[@id=\"login\"]/input/tr1/td1");
    public static By password = By.xpath("//*[@id=\"login\"]/input/tr2/td1");
    public static By submitButton = By.xpath("//*[@id=\"login\"]/input/tr3/td2/button");
    public static By title = By.xpath("/html/head/title");

}

Functionality definition classes to be called by test case classes :

import com.automation.PageElements.LoginPageElements;
import com.automation.ReusableFunctions.BrowserCalls;

public class LoginFeature extends BrowserCalls {

    public void userLogin(){

        driver.findElement(LoginPageElements.element1);
        driver.findElement(LoginPageElements.username).sendKeys(configs.getProperty(Email));
        driver.findElement(LoginPageElements.password).sendKeys(configs.getProperty(Password));
        driver.findElement(LoginPageElements.submitButton).click();

    }

}

Test Case class is as below :

import com.automation.ReusableFunctions.BrowserCalls;
import com.automation.Components.LoginFeature;
import org.testng.annotations.Test;

import java.io.IOException;

public class LoginTestCase1 extends BrowserCalls {

    @Test (description = "Verify application login")
    public void LoginTest() throws IOException {

        LoginFeature login = new LoginFeature();
        login.invokeChromeBrowser();
        login.userLogin();
        login.closeChromeBrowser();

    }

}

Aucun commentaire:

Enregistrer un commentaire