Skip to content

Commit 423ea14

Browse files
committed
Add file-parsing examples
1 parent f7abd5a commit 423ea14

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

examples/boilerplates/file_parsing/__init__.py

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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"])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
admin,admin_username_qa,admin_password_qa
2+
employee,employee_username_qa,employee_password_qa
3+
customer,customer_username_qa,customer_password_qa
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
admin,admin_username_staging,admin_password_staging
2+
employee,employee_username_staging,employee_password_staging
3+
customer,customer_username_staging,customer_password_staging

0 commit comments

Comments
 (0)