question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run `beforeScenario` only once before a scenario

See original GitHub issue

I thought that I can use the beforeScenario to call my auth service to get an access token and use that for each call to the service I’m load testing. However, my auth function is called before each endpoint call. That is suboptimal because I don’t want load test my auth service at the same time I load test all my other services.

Code example:

scenarios:
  - name: "Endpoint returns 200"
    beforeScenario: "auth"
    flow:
      - get:
          url: "/api/v1/endpoint"
          expect:
            - statusCode: 200
            - contentType: json

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
hassycommented, Jan 22, 2021

beforeScenario is indeed meant to be run before each scenario execution (by each virtual user).

There is a way to run a call just once via a before section at the top level of the test definition. The contents of the section can be an arbitrary scenario, but any variables captured by that scenario will be available to all virtual users.

Quick example:

config:
  target: https://artillery.io
  phases:
    - duration: 10
      arrivalRate: 1

before:
  flow:
    - log: "running a request before virtual users run"
    # Grab a random URL from the homepage:
    - get:
        url: "/"
        capture:
          - selector: "a"
            attr: "href"
            index: "random"
            as: "url"

scenarios:
  # All virtual users will make requests to the same URL
  - flow:
      - log: "URL is {{ url }}"
      - get:
          url: "{{ url }}"
6reactions
MarcoArredondocommented, Mar 20, 2021

Do you know if is there an “after” instruction too? I need to delete a parent element that I created in the “before” section. I looked through the documentation but I see nothing

I added this at the root level but seems to do nothing:

after:
  flow:
    - log: "Deleting project {{projectID}}"
    - delete: 
        url: /rest/v1/projects/{{projectID}}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Specflow beforeScenario in base class called multiple times ...
When I want a BeforeScenario to run only once per test run I will put it into its own "hooks" class. Since both...
Read more >
Hooks - SpecFlow's documentation
When running tests in multiple threads with SpecFlow+ Runner, Before and After hooks such as BeforeTestRun and AfterTestRun are executed once for each ......
Read more >
run background before scenario outline, but just one time
If I have a Background section and a Scenario Outline, the Background runs once before each example in the scenario outline. Is there...
Read more >
Before Scenario hook in specflow running twice multiple times
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >
Cucumber Hooks - Baeldung
Methods annotated with @Before will execute before every scenario. ... initialization() executes first, and beforeScenario() executes second ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found