Function Parameters

It is always a good practice to pass parameters when calling the method, rather than providing parameters inside the method. We can pass parameters through methods, just as in normal programming code. The code below will show us how we can login with parameterized username and password.

How to do it…

1) First let’s have a look over our previous example of SignIn_Action class.

Note: Please visit First Test CasePage Object Model Modularity first, in case you are finding it hard to understand the above used SignIn_Action class.

2) Modify the above Execute method of class SignIn_Action to accept string Arguments (Username & Password).

3) Create a New Class and name it as Param_TC by right click on the ‘automationFramework‘ Package and select New > Class. We will be creating all our test cases under this package.

Now convert your old Module_TCin to the new passing parameters based test case.

You see how easy it is to pass arguments to your methods. It increase you code readability.

Now your Project explorer window will look like this:

Param-1

Note: But it is still not the best idea to hardcode your input anywhere in your test script, as it will still impact the bulk of your test scripts if there is any change in user data. I used this example just to give you an idea to how we use arguments in method.

In the next chapter of Constant Variable we will learn how to avoid hardcode values in our code.

 

navigate-left-icon

navigate-right-icon