From f00946d58a9a2490e92b0ab7d2b5cc2ded677a03 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Sun, 26 Mar 2023 09:55:04 -0600 Subject: [PATCH 1/7] refactor: improve file check to be more helpful --- setup/01-manual_testing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup/01-manual_testing.py b/setup/01-manual_testing.py index d9609ad..4629a23 100755 --- a/setup/01-manual_testing.py +++ b/setup/01-manual_testing.py @@ -5,8 +5,11 @@ def check_file_exists(): if not os.path.isfile(LOGIN_ROBOT_FILE): - print(f"login.robot not found under {LOGIN_ROBOT_FILE}, please create one") + print(f"❌ Hmm. I don't see your 'login.robot' file. I was expecting to see it at '{LOGIN_ROBOT_FILE}'") + print("Double-check that it's in the right place and named correctly and try again.") sys.exit(1) + else: + print("✔️ Found your 'login.robot' file.") def check_content(): is_browser = False From d6bb54658eea4b32d59a713bc4e2464e98f33702 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Sun, 26 Mar 2023 10:19:54 -0600 Subject: [PATCH 2/7] feat: give feedback when found correct step Yet we're not "giving the answers to the test" by telling them exactly what they're missing. --- setup/01-manual_testing.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/setup/01-manual_testing.py b/setup/01-manual_testing.py index 4629a23..c1cf2de 100755 --- a/setup/01-manual_testing.py +++ b/setup/01-manual_testing.py @@ -35,10 +35,24 @@ def check_content(): is_login = True elif "welcome" in lowered_line: is_welcome = True + + if is_browser: + print("✔️ Found open browser step.") + if is_url: + print("✔️ Found specific URL in steps.") + if is_username: + print("✔️ Found mention of username field in steps.") + if is_password: + print("✔️ Found mention of password field in steps.") + if is_login: + print("✔️ Found login step.") + if is_welcome: + print("✔️ Found welcome page step.") + if is_browser and is_url and is_password and is_username and is_login and is_welcome: - print("Ready to proceed!") + print("✅ Ready to proceed!") else: - print("Not quite there yet! Did you remember browser, username, password or perhaps missing url? Did you verify your login succeeded?") + print("❌ Not quite there yet! Did you remember browser, username, password or perhaps missing url? Did you verify your login succeeded?") sys.exit(1) def main(): From 07bedb2183b0687e1c3105e7d4687b7f4107590f Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Sun, 26 Mar 2023 10:23:44 -0600 Subject: [PATCH 3/7] fix: allow combination of steps in one line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, if you reasonably had two steps in one line—like if you said "Open browser to localhost:7272"—the check would never pass. Now, instead, we check every line for the criteria. --- setup/01-manual_testing.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup/01-manual_testing.py b/setup/01-manual_testing.py index c1cf2de..f5d7d13 100755 --- a/setup/01-manual_testing.py +++ b/setup/01-manual_testing.py @@ -25,15 +25,15 @@ def check_content(): lowered_line = line.lower() if re.search(r"(new|open) (page|browser)", lowered_line): is_browser = True - elif re.search(r"localhost:7272", lowered_line): + if re.search(r"localhost:7272", lowered_line): is_url = True - elif "username" in lowered_line: + if "username" in lowered_line: is_username = True - elif "password" in lowered_line: + if "password" in lowered_line: is_password = True - elif "click" in lowered_line or "login" in lowered_line: + if "click" in lowered_line or "login" in lowered_line: is_login = True - elif "welcome" in lowered_line: + if "welcome" in lowered_line: is_welcome = True if is_browser: From 6b6f101c4e8726f043ee26304523f58e09ccc80f Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Sun, 26 Mar 2023 10:56:40 -0600 Subject: [PATCH 4/7] fix: improve browser/page/app check to allow for words between Before, "Open the browser..." would not have passed this check; now it will. --- setup/01-manual_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/01-manual_testing.py b/setup/01-manual_testing.py index f5d7d13..09af460 100755 --- a/setup/01-manual_testing.py +++ b/setup/01-manual_testing.py @@ -23,7 +23,7 @@ def check_content(): data = f.readlines() for line in data: lowered_line = line.lower() - if re.search(r"(new|open) (page|browser)", lowered_line): + if re.search(r"(new|open).+(page|browser|app)", lowered_line): is_browser = True if re.search(r"localhost:7272", lowered_line): is_url = True From 50a1cbed805b08b312e259be315653291aabcded Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Sun, 26 Mar 2023 11:13:48 -0600 Subject: [PATCH 5/7] fix: mention welcome page in "not quite there" message Previously, if you hadn't checked for the welcome page in your steps, you'd have no hint as to what you were missing. Now, we give you a hint --- setup/01-manual_testing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup/01-manual_testing.py b/setup/01-manual_testing.py index 09af460..c92e5a6 100755 --- a/setup/01-manual_testing.py +++ b/setup/01-manual_testing.py @@ -52,7 +52,8 @@ def check_content(): if is_browser and is_url and is_password and is_username and is_login and is_welcome: print("✅ Ready to proceed!") else: - print("❌ Not quite there yet! Did you remember browser, username, password or perhaps missing url? Did you verify your login succeeded?") + print("❌ Not quite there yet! Did you remember browser, username, password or perhaps missing url? Did you " + "verify your login succeeded and took you to the welcome page?") sys.exit(1) def main(): From 9725c403f2bd77c65378a99ebcc36e418e677839 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Sun, 26 Mar 2023 11:30:10 -0600 Subject: [PATCH 6/7] fix: allow "login" or "log in" or "button" This allows people to say to "Log in" or to use the "login button" --- setup/01-manual_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/01-manual_testing.py b/setup/01-manual_testing.py index c92e5a6..8a7723d 100755 --- a/setup/01-manual_testing.py +++ b/setup/01-manual_testing.py @@ -31,7 +31,7 @@ def check_content(): is_username = True if "password" in lowered_line: is_password = True - if "click" in lowered_line or "login" in lowered_line: + if re.search("(log ?in)|button", lowered_line): is_login = True if "welcome" in lowered_line: is_welcome = True From 167deb115fb55d8ee8826b1652c656b3d0acee88 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Sun, 26 Mar 2023 13:32:23 -0600 Subject: [PATCH 7/7] feat: check that script is being run in root of repo I found that if you run the script from another folder, things react unexpectedly. So it seems like a good idea to double-check. --- setup/01-manual_testing.py | 4 +++- setup/static.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/setup/01-manual_testing.py b/setup/01-manual_testing.py index 8a7723d..ed03008 100755 --- a/setup/01-manual_testing.py +++ b/setup/01-manual_testing.py @@ -1,7 +1,8 @@ import os import sys import re -from setup.static import LOGIN_ROBOT_FILE +from setup.static import LOGIN_ROBOT_FILE, check_running_in_root + def check_file_exists(): if not os.path.isfile(LOGIN_ROBOT_FILE): @@ -57,6 +58,7 @@ def check_content(): sys.exit(1) def main(): + check_running_in_root() check_file_exists() check_content() diff --git a/setup/static.py b/setup/static.py index dae946d..f5d97ed 100755 --- a/setup/static.py +++ b/setup/static.py @@ -1,4 +1,6 @@ import os +import sys + ROBOT_ROOT_PATH = os.path.abspath(os.path.join(".", "robot")) LOGIN_ROBOT_FILE = os.path.abspath(os.path.join(ROBOT_ROOT_PATH, "login.robot")) INVALID_LOGIN_ROBOT = os.path.abspath(os.path.join(ROBOT_ROOT_PATH, "invalid_login.robot")) @@ -8,5 +10,20 @@ else: CURRENT_ENV["PYTHONPATH"] = f"setup{os.pathsep}" + def normalize(keyword): - return keyword.strip().title() \ No newline at end of file + return keyword.strip().title() + + +def check_running_in_root(): + current_folder = os.getcwd() + supposed_exercises_folder = os.path.abspath(os.path.join(current_folder, "exercises")) + supposed_setup_folder = os.path.abspath(os.path.join(current_folder, "setup")) + + in_root = os.path.isdir(supposed_exercises_folder) and os.path.isdir(supposed_setup_folder) + if not in_root: + print(f"🚩 Hmm. It looks like the script is running in '{current_folder}' instead of the repo root folder.") + print("For the verification to work correctly, you need to run the script from the root of the repository (" + "probably named 'rf-katas').") + print("Try again, but double-check that you're running the verify script from the repository root.") + sys.exit(1)