Selenium + JUnit: test order/flow?

前端 未结 5 795
感动是毒
感动是毒 2021-02-03 10:08

I am using Selenium to test my java web app\'s html pages (JSPs actually). My web app requires a flow to access each pages (it is a small online game web app), as in: to get to

5条回答
  •  执笔经年
    2021-02-03 10:59

    We use a Framework call Cucumber. Its behavioral driven development. So essentially, you can create testing function that are agnostic of the flow and use feature to control the flow of your testing.

    Example Page 1, enter 2 input, click enter, verify page 2 loaded with a something.

    Then you'll have this in a feature file:

    Given Page 1
       Then I enter text1
       Then I enter text2
       Then I click button
       Then I see page 2
    

    And in you code, you can have a class that implements these steps. And with the cucumber framework, you can use annotation to denote the mapping between you testing code and the feature file.

    ...
    @Given("^Page 1$")
    public void iLoadPage1() {
      WebDriver driver = new ....
      driver.go('URL');
    }
    
    @Given("I enter (.*)$")
    public void iEnterTest(String txt) {
      ...
    }
    
    ...
    

提交回复
热议问题