1

I'm testing with the selenium webdriver, and getting an error. I have set the Ro.properties file and put all locator in properties file.

Below is the code that I am using, can anyone please help me out?

public class usePropertiesFile {
    private WebDriver driver;
    public static Properties prop = new Properties();
    public static FileInputStream fip = null;
    @BeforeTest
    public void setup() throws IOException {
        driver =new FirefoxDriver();
        driver.get("http://gmail.com/");
        driver.manage().window().maximize();

    }
    @AfterTest
    public void Teardown() {
        driver.quit();
    }
    @Test
    public void testPropFile() throws Exception {
              fip = new FileInputStream("C:\\Users\\src\\config\\RO.properties");
        prop.load(fip);
        driver.findElement(By.xpath(prop.getProperty("login_use"))).clear();
        driver.findElement(By.xpath(prop.getProperty("login_use"))).sendKeys("userid");
    }
}
4

2 回答 2

1

I think you are getting the Illegal Argument error because your Ro.Properties file is not present the path you have declared in the script.

First of all, copy the updated Ro.properties file in the execution folder path (if it is not present). Then verify the attributes used properly assigned or not.

Execute the script, it should work.

于 2013-04-29T12:50:40.933 回答
1

在您的.properties文件(位于C:\Users\src\config\RO.properties)上,该属性login_use未设置。

换句话说,您的测试程序正在查找properties文件(否则它会抛出未找到文件的异常),但没有找到具有login_use名称的属性。

尝试添加后prop.load(fip);

System.out.println("Value of 'login_use': "+prop.getProperty("login_use"));

它可能会打印null.

将此行添加到您的RO.properties

login_use=//input[@name\='Email']

它现在应该//input[@name\='Email'](而不是null)作为值(当然,将表达式更改为您想要的)。

于 2013-04-28T01:48:35.513 回答