• Home

  • Courses

    • Run Java Selenium Tests in Azure Devops
    • Interviewing for Testing Positions
  • For Business

  • Trainings

    • Beginner Selenium (May 2018)
    • Advanced Selenium (Feb 2019)
  • Teacher

  • Bootcamp Info

  • Forum

  • Blog

  • Meetups

    • Test Automation for Responsive Site
    • All about Locators in Selenium Projects
  • More..

    • FAQ
    • Cheat Sheets
    • Presentations
  • More...

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    alexsiminiuc3
    May 16, 2018

    Use proper names for methods

    in Selenium Questions

    public String getLocatorValues(By locator) {
      String values;
    		
      WebElement locatorElement = wait.until(ExpectedConditions
                                      .visibilityOfElementLocated(locator));
      values = locatorElement.getText();
      return values;
    }

    This method uses a locator parameter.

    It finds an element using the locator, gets the element's text value and returns it.


    In short, it returns the text of an element.


    Then, it should not be called getLocatorValues but getElementText() or even shorter getText().


    The locatorElement variable should be renamed as well to element:


    public String getText(By locator) {
      String value = "";
    		
      WebElement element = wait.until(ExpectedConditions
                               .visibilityOfElementLocated(locator));
      value = element.getText();
      return value;
    }

    The name of a method should explain clearly what the method does.

    The name of a variable should explain clearly what the variable is.


    Both names should be as short as possible.


    One word is preferred.

    Two words is ok.

    Three words is bad.

    2 comments
    0
    2 Comments

    Share Your ThoughtsSign up to leave a comment.

    alexsiminiuc3
    May 17, 2018

    atrocious is the correct word :)

    Like

    O
    Oleg K
    May 17, 2018

    So something like getPageElementByAttribute would be atrocious ? ;)

    Like
    2 comments

    © 2021 Vancouver Selenium WebDriver Automation Training