I am new to Selenium automation, in automating a web application which is preferred. Can we write scripts page by page or functionalities. How to identify that?

  • if it’s page by page how we verify the success criteria for any element?
  • if it’s functionality how to verify other generic validations?

Try using Page Object model, to verify the elements let the function return boolean value and check if it's not false. For example, if you got click on login button create a function with try catch. If the element is available then click on it and return true else return false.


Option1: If you want to use selenium for page by page verifications, you can use page object model in following way:

 * Tests login feature
public class Login {

  public void testLogin() {
    // fill login data on sign-in page
    driver.findElement(By.name("password")).sendKeys("my supersecret password");

    // verify h1 tag is "Hello userName" after login
    assertThat(driver.findElement(By.tagName("h1")).getText(), is("Hello userName"));

Option 2: If you are using selenium framework to test web UI, accessibility and API services, then preferable to use cucumber boilerplate:

Reference: webdriverio/cucumber-boilerplate Sample Cucumber Feature File with maximum reusability:

    In order to keep my product stable
    As a developer or product manager
    I want to make sure that everything works as expected

Scenario: Check title of website after search
    Given I open the url "http://google.com"
    When I set "WebdriverIO" to the inputfield "#lst-ib"
    And I press "Enter"
    Then I expect that the title is "WebdriverIO - Google Search"

Option3: If you want to use an automation framework for locally built app for web UI, preferable to use Cypress instead Selenium:

Feature: Home Page Test on OrangeHRM website

   Scenario: Check valid home page tabs display
      Given I open OrangeHRM homepage
      When I SignIn as user
      Then the user name should be displayed
      And the Admin tab should be displayed
   Scenario: Click on Admin Tab of home page
      Given I open OrangeHRM homepage
      When I SignIn as user
      And I click on admin tab of home page
      Then the admin sub tab section displayed

Reference: narayananpalani/cypress-test-techniques.


I agree with the other commenters that the Page Object Model is a great way to structure test code for interacting with the page, however, for the tests themselves, I recommend writing tests for functionality instead of page-by-page.

Tests aren't about validating pages, after all. All of your users and most of your staff don't care which page something is on, they care whether it works or not.

There's a bit of nuance. Unit tests will often run against a single component of a page, whereas functional tests run across multiple pages. For a functional test, grouping by functionality reflects how your developers will make changes, and allows for sensible multi-page tests. For instance, imagine you're writing a mortgage application. There are five steps for making a new application:

  1. Create an account or log in on the homepage
  2. Provide your ID
  3. Provide the property details
  4. Provide your financial details
  5. Submit the application

Your users will never visit the 'Property Details' page directly. They must take the other steps first.

If you wrote 5 separate page tests, you'd have to make extra, crappy tests for each page to make sure it was receiving and providing the right data. If you add a new page between 4&5, you now need to change the test code for page 4, the new page, and page 5.

If your application is composed of re-usable components, page-based tests make even less sense. Say users can provide financial information without logging in, on order to estimate how much they can borrow. If you're using page-based tests, you have to write and update both tests when that component changes.

If instead you're doing functionality grouped tests, you can instead create a page object for that component and write a unit tests for it. Then, during your functional tests, just pass the page object the relevant data for either page, and assume that


I would recommend using page object model where you create a specific class where you put all the elements/objects and actions can be done within a page that makes them reusable to test cases that you'll automate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.