Selenium Coding Standards

Example

Note: WE NEED A GOOD EXAMPLE here! Please feel free to add one.

// put great example of pseudocode that follows our coding standards here

Principles

PageObjectModel

Use the PageObjectModel! It takes more time to set up in the beginning, but it makes the code much more robust.

Selenium

XPATH/Locators

  • Try to be as specific in your locators as possible: IDs, and name elements when you can, and if you have to use XPaths, construct them so that they only return the one (or more) elements about which you actually care. (StanVogel)
  • Make sure when using XPath that the attributes being used do not change (such as an id that changes from one visit on a web page to another). (LeslieReis)
  • Construct xpath locators with %s and use String.format to insert variables values into the same xpath. For instance if you need to select an option from a dropdown menu, you might use something like ‘xpath = “//input[@id=dropdown]/option[text()=%s]”;’ and then use ‘String.format(xpath, “Desired Option”);’ (KyleRoth)
  • Use contains() in an xpath to grab part of an ID (accounts for IDs which are not consistent when the application loads) or avoid issues with white space in text. For instance, a text field with an ID of “extAdminPanel_txtSearchField” could have a locator of “//input[contains(@id, ‘AdminPanel’) and contains(@id, ‘SearchField’)]” (KyleRoth)

Sikuli

  • Use Sikuli locators when needed, but always opt for traditional xpath locators first. For instance a dropdown might need a Sikuli click to open, but then can take an xpath click to choose the option you’re looking for. (KyleRoth)

Naming Conventions

Entity Format Example
     
     
     
     

-- GenericUltranaut - 14 Apr 2020
Topic revision: r3 - 16 Nov 2022, NicoleRadziwill
© 2020 Ultranauts - 75 Broad Street, 2nd Floor, Suite 206, New York, NY 10004 - info@ultranauts.co