0
votes

I have a scenario where I want to log in with multiple users, cucumber provides Scenario Outline with Examples to perform this action but this requires the user details to be entered in the feature file. Is there a way to keep the user details in a properties file and call it from there in the Step definition class?

If there is, can someone please provide me with example code say with gmail login scenario? I am using Junit with my cucumber framework,any suggestion with Junit will be highly appreciated.

Thanks Fola

3

3 Answers

0
votes

I've been searching sorta the same thing and I found a lot of ridiculous "answers" to this. Overly complicated, when its actually super easy.

My goal was to read from a .txt file Here is my solution in ruby.

#inject environment properties
Given /^I enter the environment url into a field$/ do 
File.open("/PATH/TO/YOUR/env.txt") do |envFile|
    envFile.each_line do |environment|
        puts environment
        keyboard_enter_text environment
        end
    end
end

Now from Jenkins you can create a parameterized build that writes to a properties file. Viola you're tests are dynamic, enjoy!

0
votes

Yes.

In a step definition, you can do whatever you want. In your case, just use some regular Java code to read a properties file.

But note that this is not a "best practice" in terms of BDD as your scenario cannot be read anymore by a reader that doesn't have access to the properties file.

0
votes
Below is the way you can call the users from property file, still you need to pass the key in your feature file, but you will be able to get the users from property file.

file.Properties
$password =  Test@1
$TestUser_1= TestUser1

 Scenario Outline: Verify that Retail
And "User" performs login in SignIn page with "<Test_User>" & "Password"
      | Fields         | Input_Value |
      | input_email    | <User_Type> |
      | input_password | <password>  |
      | btn_Sign       |             |
      | img_Tick       |             |

    Examples: 
   | password  | User_Type           |
   | $password | $TestUser_1 |   //User these key in a same way in you property file

Create your step def in a way below
to read DataTable from Ghekin
elements = locatorType.raw();
String userName = elements.get(1).get(1);  //here you will get $TestUser_1
String password = elements.get(2).get(1);   // Here you will get $password
if (userName.contains("$")) 
            {

    userName = webPropHelper.getTestDataProperty(elements.get(1).get(1));
// here you will get the userName defined in you property file against the key TestUser_1
            }
            if (password.contains("$")) {

                password = webPropHelper.getTestDataProperty(elements.get(2).get(1));
// here you will get the Password defined in you property file against the key $password
            }
    WebElement emailinputbox = getBDDElement(pageName, userName);
    WebElement pwdbox = getBDDElement(pageName, password);