• 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 26, 2018

    Avoid using locators directly in the test method

    in Selenium Questions

    Test methods should not include any locators.


    Instead of having the following code in a test method

    selectListBox(SEARCH_MAKE_ID, make);
    selectListBox(SEARCH_MODEL_ID, model);
    selectListBox(SEARCH_MAXPRICE_ID, price);

    the test should have


    selectMake(CAR_MAKE);
    selectModel(CAR_MODEL);
    selectPrice(CAR_MAXPRICE);


    See below the code of all 4 methods:


    public void selectMake(String make) {
       selectListBox(SEARCH_MAKE_ID, make);
    }
    	
    public void selectModel(String model) {
       selectListBox(SEARCH_MODEL_ID, model);
    }
    	
    public void selectPrice(String price) {
       selectListBox(SEARCH_MAXPRICE_ID, price);
    }
    	
    public void selectListBox(By listLocator, String listVisbleText) {
    
       WebElement listElement = wait.until(ExpectedConditions
                                     .visibilityOfElementLocated(listLocator));
       Select list = new Select(listElement);
       list.selectByVisibleText(listVisbleText);
    
    }

    0 comments
    0
    Comments

    Share Your ThoughtsSign up to leave a comment.

    0 comments

    © 2021 Vancouver Selenium WebDriver Automation Training