Forum Discussion

RyKling's avatar
RyKling
New Contributor
7 years ago

Additional parameter causing Exception

Hello all,

 

This is the general structure of my tests:

 

Test A

- Test A has a bunch of steps

- Test A has a step which calls Utility Keyword Script A (Sets parameters)

 

Test B

- Test B has a bunch of steps

- Test B has a step which calls Utility Keyword Script A (Sets different parameters)

 

Utility Keyword Script A has multiple parameters.  I decided to add a few additional test parameters.  Now when I run Test A and Test B, i get an exception that its expecting a different number of parameters.  Is there an easy way to update all of the Test cases to at least use the default value for the added test parameters to avoid throwing this exception?  Obviously I have a lot more than two tests, just using this as an example.  I really dont want to go by each test at a time to update them.

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    When you add a new parameter, you need to make it "optional" if it's already in use if you don't want to "break" old test cases.  In KeywordTests, this is simply checking the "optional" flag and filling the default value.

     

    In Script code, it depends somewhat on the script language as to how you do it.  JavaScript looks like this.  The first parameter is required, second is optional with a default value of 'test'

    function Test(parameter1, optional = 'test'){
    
    }
  • If this is JS you can just work with objects. 

     

    a function that takes in a vehicle. You can come up with a spec for the object itself, and and have the function takes in the object and check if the object has certain properties. 

     

    Below, a car has 2 properties while a bike only has one. But the function takes care of both cases. It simply check if the vehicle you passed it has an engine...

     

     

    function upgradeVehicle(vehicle) {
    vehicle.speed ++
    if (vehicle.engine) {
    vehicle.engine === "V8"
    }
    }

    let bicycle = {
    speed : 1
    }

    let car = {
    speed : 4,
    engine : "oldrustyengine"
    }

    upgradeVehicle(bicycle) // bicycle.speed == 2
    upgradeVehicle(car) // car.speed == 5 ; car.engine == "V8"