0

I have a background test case with tags which I need to run everytime with mutliple scenarios .

Example :

There are 3 scenarios and 1 background. In short, Background should behave like @BeforeMethod of testing

So my execution should be like

  1. Background then Scenario1 (@Dev,@tagteacher1)
  2. Again Background then Scenario2 (@Dev,@tagteacher2)
  3. Again Background then Scenario3 (@Dev,@tagteacher3)
@TestStory
    Feature: Teachers' timesheet need to be filled


      Background: 

      Scenario Outline: Open Webpage
        Given User Open teacher application with given <ENDPOINT> 
        And   Login into application with given <USERNAME> and <PASSWORD>
        And User clicks on teacher submission link

        @DEV
        Examples: 
          | endpoint                       | USERNAME | PASSWORD    |
          | http://teachersheetdev.ggn.com | sdrdev| aknewdev|



        @QA
        Examples: 
          | endpoint                      | USERNAME | PASSWORD    |
          | http://teachersheetqa.ggn.com | sdrqa | aknewdev|


    @tagteacher1
    Scenario1: Open app home page and click the button1
    Given I'm at the teachersheet homepage
    When User clicks Add Task button
    Then User should see the tasks schedule


    @tagteacher2
    Scenario1: Open app home page and click the button2
    Given I'm at the teachersheet homepage
    When User clicks Add Task button
    Then User should see the tasks schedule

    @tagteacher3
    Scenario1: Open app home page and click the button3
    Given I'm at the teachersheet homepage
    When User clicks Add Task button
    Then User should see the tasks schedule



    import org.junit.runner.RunWith;
        import com.optum.synergy.common.ui.controller.WebController;
        import cucumber.api.CucumberOptions;
        import cucumber.api.SnippetType;
        import cucumber.api.junit.Cucumber;

        @RunWith(Cucumber.class)
        @CucumberOptions(
                plugin = { "json:target/test_results/cucumber.json"}, 
                features = { "src/main/resources/ui/features" },
             tags ={"@Dev,@tagteacher"},
                snippets = SnippetType.CAMELCASE

                )

        public class CucumberRunnerTest {

            public static void tearDown(){
                WebController.closeDeviceDriver();
            }
        }

How to use tag when I want to run with Dev or QA env?

N8888
  • 670
  • 2
  • 14
  • 20
Little bird
  • 1,106
  • 7
  • 28
  • 58
  • You can use `@Before` hook to achieve this. See https://stackoverflow.com/questions/51202574/using-background-title-as-background-in-cucumber/51203125#51203125 – Nandan A Jul 10 '18 at 15:35

1 Answers1

1

You would be able to achieve this easier by setting the site you are using in a config file (whether it's the dev or qa site), and move the username and password to the step definition, using the one that correlates to whether it's QA or Dev.

After this, you'll be able to do this:

Background: 
    Given the user has opened the teachers application
    And they have logged in

@teacher
Scenario: Open app home page and view the task schedule
  Given they are on the teachersheet homepage
  When they start to add a task
  Then they should see the task schedule

@teacher
Scenario: Open app home page and view the task schedule
  Given they are on the teachersheet homepage
  When they start to add a task
  Then they should see the task schedule

If you need to log in as different teachers, you'll have to move the log in step into the Scenarios, as they won't be the same and you'll have to provide details for who is logging in.

As a side note, think about the wording that you are using. Clicking buttons is all well and good if you are testing out the design of the site, but the main reason for using Cucumber is to express intent - to describe how a user should move through the site, without worrying about the implementation details. It's to bridge the communication gap between the business and the development team, so they can figure out what scenarios are being tested. Implementation details hide the intent of the test.

KyleFairns
  • 2,947
  • 1
  • 15
  • 35
  • I have 2 env to run i,e Dev and QA . How can use the example value on the basic of tag at runtime ? @Kyle Fairns – Little bird Jul 05 '18 at 11:43
  • 1
    You could run the suite twice, use an environment variable stating which environment you are using, run with an external script that changes that environment variable. If you’re using the Page Object Model, you’d be able to easily store a base url for each of the sites, and just have the end section of the url for the pages. – KyleFairns Jul 05 '18 at 11:49
  • Yes , I'm using the Page Object Model only . How to use environment variable for running Dev env only ? Also how to use the tag ? – Little bird Jul 05 '18 at 12:08
  • For using them: https://stackoverflow.com/questions/531694/how-can-i-get-system-variable-value-in-java For setting them up, it’s dependent on whether you’re on windows or unix based system (like Mac or Linux). I’m assuming here that you are on Windows: https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt – KyleFairns Jul 05 '18 at 13:06