Search code examples
javapropertiesselenium-webdriverproperties-file

Properties file in selenium webdriver


i want to use my file.properties in my class test selenium web driver so my file.properties below:

Selenium.test.label1=User name
Selenium.test.label2=Pass word
Selenium.test.url=my/path/url

my class test below

public class SeleniumTest{
 private WebDriver driver;
    /************ File properties configuration ***************/
    // Get the inputStream
    final InputStream inputStream =
            this.getClass().getClassLoader().getResourceAsStream("messages_fr.properties");
    final Properties properties = new Properties();
    // load the inputStream using the Properties
    properties.load(inputStream);
    /*********** End configuration properties file **************/

@before
public void setUp() throws Exception {
        final Properties properties = System.getProperties();
        this.baseUrl =
                properties.getProperty(myurl);
    }
@Test
public void firefoxTest() throws Exception {
   this.driver = new FirefoxDriver();
   testSelenium();
   verifyLabel(this.properties.getProperty(Selenium.test.label1,"UN");
   verifyLabel(this.properties.getProperty(Selenium.test.label2,"PW");
}
private void verifyLabel1(final String expectedLabel, final String label) {
        final WebElement element = this.driver.findElement(By.id(label));
        final String actualLabel = element.getText();
        assertEquals("Name of label:", actualLabel, expectedLabel);
    }
private void action() throws Exception{
      driver.findElement(By.id("id1").sendkeys(this.properties.getProperty("selenium.test.url"));

}

i have a problem in this line properties.load(inputStream); Syntax error on token "inputStream", VariableDeclaratorId expected after this token

so can some one help me to use my properties file in my class test!!

Thanks


Solution

  • Me it static and call your init code in the static block

    static final Properties properties = new Properties();
    
    static {
        /************ File properties configuration ***************/
        // Get the inputStream
        final InputStream inputStream =
                SeleniumTest.class.getResourceAsStream("messages_fr.properties");
        System.out.println("InputStream is: " + inputStream);
        // load the inputStream using the Properties
        properties.load(inputStream);
        /*********** End configuration properties file **************/
    }