Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. QA Tools
  3. Squish
  4. Is it possible to use for loop in the step function in Squish (python)
Forum Updated to NodeBB v4.3 + New Features

Is it possible to use for loop in the step function in Squish (python)

Scheduled Pinned Locked Moved Solved Squish
3 Posts 3 Posters 627 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SquishHammer
    wrote on last edited by
    #1

    I tried to do a for loop in Squish step function to repeat several steps for different parameter, but it didn't work. This step function was called in the Background, so I also couldn't use the parameterization there with "Example". Any solution there?

    N 1 Reply Last reply
    0
    • S SquishHammer

      I tried to do a for loop in Squish step function to repeat several steps for different parameter, but it didn't work. This step function was called in the Background, so I also couldn't use the parameterization there with "Example". Any solution there?

      N Offline
      N Offline
      Nuno Mendes
      wrote on last edited by
      #2

      @SquishHammer you can do something very simple.

      Let's say you have 3 functions:

      @Given("foo")
      def step(context):
          pass
      
      @When("bar")
      def step(context):
          pass
      
      @Then("baz '|any|'")
      def step(context, value):
          print(value)
      

      First rename all the steps, so you don't have name collisions like so:

      @Given("foo")
      def foo(context):
          pass
      
      @When("bar")
      def bar(context):
          pass
      
      @Then("baz '|any|'")
      def baz(context, value):
          print(value)
      

      Then you can have another step that calls these functions:

      @Given("my step '|any|'")
      def step(context, value):
          for i in range(10):
               foo(context)
               bar(context)
               baz(context, value)
      
      C 1 Reply Last reply
      0
      • N Nuno Mendes

        @SquishHammer you can do something very simple.

        Let's say you have 3 functions:

        @Given("foo")
        def step(context):
            pass
        
        @When("bar")
        def step(context):
            pass
        
        @Then("baz '|any|'")
        def step(context, value):
            print(value)
        

        First rename all the steps, so you don't have name collisions like so:

        @Given("foo")
        def foo(context):
            pass
        
        @When("bar")
        def bar(context):
            pass
        
        @Then("baz '|any|'")
        def baz(context, value):
            print(value)
        

        Then you can have another step that calls these functions:

        @Given("my step '|any|'")
        def step(context, value):
            for i in range(10):
                 foo(context)
                 bar(context)
                 baz(context, value)
        
        C Offline
        C Offline
        clanhuth
        wrote on last edited by
        #3

        @Nuno-Mendes, @SquishHammer, I advise against this, and instead suggest to create separate Python functions that do the needful, and calling those instead as desired.

        1 Reply Last reply
        0
        • C clanhuth has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved