Start Automation Test with Cucumber in Septeni

1. Setup environment

2. Create project

      • Open cmd
      • Move to folder contain project & run bellow command to create project (pattern)
        mvn archetype:generate -Dfilter=serenity-cucumber
        Input: group_id; artifact (project name)
      • Move to project folder & run command
        mvn eclipse:eclipse
      • Import project that you created on eclipse
        Edit POM.xml file on eclipse (cucumber version, serenity version)
      • Run test case:
        mvn test verify or mvn clean test verify
        → Path to test report: target > site > serenity > “.index” file
      • Refer link
        https://tool.devsep.com/wiki/display/ST/Create+demo+automation+project+with+Serenity+BDD

3. Project structure

3 parts

  • src/test/java => contain class [~TestSuite.java] & [~ScenarioSteps.java]
  • src/test/resource => package [features.~] → file BDD [~.feature]
  • src/man/java => package [~.pages] → class [~Page.java]
    & package [~.steps] → class [~Steps.java]

Steps to write code for Automation test

  • Step1. Write BDD → run cucumber → copy steps missing to [~ScenarioSteps.java]
  • Step2. Write code for [~ScenarioSteps.java]
    – Using ctrl + shift + o → add library
    – declaration objects & variables
    Ex: @Steps
    UserSteps userSteps
    – Write actions in steps
    Ex: userSteps.open_home_page()
  • Step3. Write code for [~Steps.java]
    – Using library of Serenity → extends ScenarioSteps { }
    – declaration objects & variables
    Ex: UserPage userPage
    – Write actions in method
    Ex: @Step print this method when run cucumber
    public void open_home_page() {
    UserPage.open()
    }
  • Step4. Write code for [~Page.java]
    – Using library of Serenity → extends PageObject { }
    – declaration objects & variables
    Ex: @FindBy([locator of element])
    Private WebElementFacade [name of element]
    – Write actions in method
    Ex: public void enter_email (String email) {
    element(inputEmail).sendKey(email)
    };

*** [~Page.java] is used to define elements on ~ page & actions on each this element
[~Steps.java] is used to define a business logic, it is a combination of actions on pages.

4. Some commands

Ctrl + shift + f: align format
Ctrl + shift + o: get library
Ctrl + shift + s: save
Ctrl + space : display support

5. Share some experiences

  • Hard in get locator of elements→ Using some tools support get locator as Selenium, some Plugin, … And it is more easy if you know about HTML
  • Sometime you can not run cucumber normally → run again command mvn eclipse:eclipse or/and restart eclipse
  • If run cucumber you meet “timeout error” → maybe locator of elements were changed.
  • If you want change name of file/element, exist many places → right click & choose Refactor > Rename
  • If element contains “name” or “id” → you no need declaration in @FindBy that you can using name/id directly
  • Default execute test of cucumber is firefox, if you want to run on other browsers → Need download it’s driver & run test on cmd using mvn command to cursor to that driver.

Refer from Linh Vũ – Septech

Add a Comment

Scroll Up