简体   繁体   中英

Selenium what is best way to keep xpaths either in Properties file or excel sheet

I have two Selenium java automation hybrid frame works.

In one framework xpaths are storing in OR.properties file.

In other frame work xpaths are storing in excel sheet .

Finally I am creating one more new framework so which way(OR.Properties/Excel sheet) shall I use in my new framework.

Can any one suggest about your experience .

Neither, use page objects and define your locators inside the page object.

The big advantage is that it keeps everything related to the page in one place, this makes it much easier to refactor your tests.

Here is a very simple Java example (you haven't specified which language so i don't know if this is relevant to you, but the concept should hold).

public class HomePage {

    @FindBy(how = How.NAME, using = "q")
    private WebElement searchTerms;

    public HomePage(WebDriver driver) {
        PageFactory.initElements(driver, this)
    }

    /**
     * Perform a Google search
     *
     * @param searchString Search query
     */
    public void searchFor(String searchString) {
        searchTerms.clear();
        searchTerms.sendKeys(searchString);
        searchTerms.submit();
    }
}

You should have the logic that determines how elements are located and interacted with inside your page object and then the test can use the page objects to drive the site that you are testing.

There has been quite a lot of discussion around this subject on the selenium users mailing list as well, here are a couple of useful threads:

Finally, there is some information about page objects available in the Selenium documentation and in the Selenium wiki:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM