|
| 1 | +from seleniumbase import BaseCase |
| 2 | + |
| 3 | + |
| 4 | +class ParseTestCase(BaseCase): |
| 5 | + |
| 6 | + def setUp(self): |
| 7 | + super(ParseTestCase, self).setUp() |
| 8 | + |
| 9 | + def get_login_credentials(self, user_type): |
| 10 | + # Example of parsing data from a file |
| 11 | + f = open('qa_login_example.txt', "r") |
| 12 | + file_data = f.read() |
| 13 | + file_lines = file_data.split('\n') |
| 14 | + for line in file_lines: |
| 15 | + line_items = line.split(',') |
| 16 | + if line_items[0] == user_type: |
| 17 | + return line_items[1], line_items[2] |
| 18 | + f.close() |
| 19 | + |
| 20 | + def get_all_login_credentials(self): |
| 21 | + # Example of parsing data from a file (Method 2) |
| 22 | + keys = {} |
| 23 | + f = open("staging_login_example.txt") |
| 24 | + file_data = f.read() |
| 25 | + file_lines = file_data.split('\n') |
| 26 | + for line in file_lines: |
| 27 | + line_items = line.split(',') |
| 28 | + if line_items[0] == 'admin': |
| 29 | + keys['admin'] = ( |
| 30 | + {'username': line_items[1], 'password': line_items[2]}) |
| 31 | + if line_items[0] == 'employee': |
| 32 | + keys['employee'] = ( |
| 33 | + {'username': line_items[1], 'password': line_items[2]}) |
| 34 | + if line_items[0] == 'customer': |
| 35 | + keys['customer'] = ( |
| 36 | + {'username': line_items[1], 'password': line_items[2]}) |
| 37 | + f.close() |
| 38 | + return keys |
| 39 | + |
| 40 | + |
| 41 | +class ParseTests(ParseTestCase): |
| 42 | + |
| 43 | + def test_get_login_credentials(self): |
| 44 | + print("\nExample 1 of getting login info from parsing a config file:") |
| 45 | + print("") |
| 46 | + username, password = self.get_login_credentials("admin") |
| 47 | + print("Getting Admin User login data:") |
| 48 | + print("Username: %s" % username) |
| 49 | + print("Password: %s" % password) |
| 50 | + |
| 51 | + print("\nExample 2 of getting login info from parsing a config file:") |
| 52 | + print("") |
| 53 | + keys = self.get_all_login_credentials() |
| 54 | + print("Getting Customer login data:") |
| 55 | + print("Username: %s" % keys["customer"]["username"]) |
| 56 | + print("Password: %s" % keys["customer"]["password"]) |
0 commit comments