I'm using Python Behave to run automated tests against a web application.
There is a login page that takes a username and password.
The Behave scenarios have different login requirements, for example;
Given I am logged on as user1
Then do something
I created a csv file to hold the username and passwords for each login, but I'm having trouble getting it to read only the details that I want.
The csv file is like this;
usertype,username,password
user1,somename1,somepassword1
user2,somename2,somepassword2
The required user is passed in the Behave step definition;
@given('I am logged on as {login}')
I have tried the following implementation;
def do_login(context, login):
driver = context.browser
user_data = csv.DictReader(open('users.csv'))
for row in user_data:
row['user'] = login
uname = row['username']
pword = row['password']
driver.find_element_by_name('username').send_keys(uname)
driver.find_element_by_name('password').send_keys(pword)
But this just logs in with the first user in the table.
I don't know how to get it to select only the username and password corresponding to the login.
So for example, I pass the login as user2 and I want the username as somename2 and the password as password2.
I've read other questions relating to reading from csv files, but I couldn't find one that was the same as this.
I'm quite new to Python.