Skip to content

Commit 1d1a57e

Browse files
committed
Removed secrets and used .env file to pass these in
Added users to users.json
1 parent ee21c8b commit 1d1a57e

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

pages/login_page.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from playwright.sync_api import Page
1+
import os
22

3+
from playwright.sync_api import Page
4+
from utils.user_tools import UserTools
5+
from dotenv import load_dotenv
36

47
class BcssLoginPage:
58

@@ -23,6 +26,26 @@ def login(self, username, password):
2326

2427
def login_as_user_bcss401(self):
2528
"""Logs in to bcss as the test user 'BCSS401'"""
26-
self.username.fill("BCSS401")
27-
self.password.fill("changeme")
29+
# Take environment variables from .env
30+
load_dotenv()
31+
# Retrieve and enter username from users.json
32+
user_details = UserTools.retrieve_user("BCSS401")
33+
self.username.fill(user_details["username"])
34+
# Retrieve and enter password from .env file
35+
password = os.getenv("BCSS_PASS")
36+
self.password.fill(password)
37+
# Click submit button
38+
self.submit_button.click()
39+
40+
def login_as_user_bcss118(self):
41+
"""Logs in to bcss as the test user 'BCSS118'"""
42+
# Take environment variables from .env
43+
load_dotenv()
44+
# Retrieve and enter username from users.json
45+
user_details = UserTools.retrieve_user("BCSS118")
46+
self.username.fill(user_details["username"])
47+
# Retrieve and enter password from .env file
48+
password = os.getenv("BCSS_PASS")
49+
self.password.fill(password)
50+
# Click submit button
2851
self.submit_button.click()

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
pytest-playwright>=0.5.1
22
pytest-html>=4.1.1
33
pytest-json-report>=1.5.0
4+
5+
playwright~=1.47.0
6+
dotenv~=0.9.9
7+
python-dotenv~=1.0.1
8+
pytest~=8.3.3
9+
Flask~=3.0.3

tests/test_login_to_bcss.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
3+
from dotenv import load_dotenv
14
from playwright.sync_api import Page, expect
25
from pages.login_page import BcssLoginPage
36

@@ -16,9 +19,13 @@ def test_login_to_bcss_with_invalid_username(page: Page) -> None:
1619
"""
1720
Confirms that a user with a valid password, and invalid username, can NOT log in to bcss
1821
"""
19-
# Enter a valid password with an invalid username and click 'sign in' button
22+
# Take environment variables from .env
23+
load_dotenv()
24+
# Set an invalid username
2025
username = "BCSSZZZ"
21-
password = "changeme"
26+
# Retrieve valid password from .env file
27+
password = os.getenv("BCSS_PASS")
28+
# Enter valid password with an invalid username and click 'sign in' button
2229
BcssLoginPage(page).login(username, password)
2330
# Confirm error message is displayed
2431
expect(page.locator("body")).to_contain_text("Incorrect username or password.")

users.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
2-
"_comment": "This file can be used to store data on users for your application, and then pulled through using the utils.user_tools UserTools utility. The documentation for this utility explains how this file is read.",
3-
"Example User 1": {
4-
"username": "EXAMPLE_USER1",
5-
"roles": ["Example Role A"]
6-
},
7-
"Example User 2": {
8-
"username": "EXAMPLE_USER2",
9-
"roles": ["Example Role B", "Example Role C"]
10-
}
2+
"_comment": "This file can be used to store data on users for your application, and then pulled through using the utils.user_tools UserTools utility. The documentation for this utility explains how this file is read.",
3+
4+
"BCSS401": {
5+
"username": "BCSS401",
6+
"roles": [
7+
"Hub Manager State Registered, Midlands and North West"
8+
]
9+
},
10+
"BCSS118": {
11+
"username": "BCSS118",
12+
"roles": [
13+
"Screening Centre Manager for Wolverhampton, Midlands and North West"
14+
]
15+
}
1116
}

0 commit comments

Comments
 (0)