diff --git a/backend/secfit/geckodriver.log b/backend/secfit/geckodriver.log index caab77308571efbc053d187af8cdb5eda09f30ce..b4612ac99470835b8a2381e609a2d8e86d9c2a39 100644 --- a/backend/secfit/geckodriver.log +++ b/backend/secfit/geckodriver.log @@ -2565,3 +2565,206 @@ JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: ###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost +1615043077659 geckodriver INFO Listening on 127.0.0.1:61737 +1615043080693 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofilek5jXe0" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043084124 Marionette INFO Listening on port 61746 +1615043084360 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043084756 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +Marionette threw an error: TypeError: browsingContextFn().currentWindowGlobal is null +getMarionetteCommandsActorProxy/get/<@chrome://marionette/content/actors/MarionetteCommandsParent.jsm:332:29 + +1615043097511 Marionette INFO Stopped listening on port 61741615043098560 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileOi8vYv" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043103877 Marionette INFO Listening on port 61823 +1615046078547 Marionette INFO Stopped listening on port 61823 +5043108791 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileieDe7n" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043113321 Marionette INFO Listening on port 61881 +1615043113576 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043113917 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +Marionette threw an error: TypeError: browsingContextFn().currentWindowGlobal is null +getMarionetteCommandsActorProxy/get/<@chrome://marionette/content/actors/MarionetteCommandsParent.jsm:332:29 + +1615043125604 Marionette INFO Stopped listening on port 61881 + +###!!! [Child][RunMessage] Error: Channel closing: too lat1615043128687 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileSJur4s" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043133801 Marionette INFO Listening on port 61961 +1615043133960 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043134305 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615046081074 Marionette INFO Stopped listening on port 61961 +5043140288 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileZcDvrS" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043144285 Marionette INFO Listening on port 62049 +1615043144481 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043144862 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: , line 0: TypeError: NetworkError when attempting to fetch resource. +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +JavaScript error: , line 0: TypeError: NetworkError when attempting to fetch resource. +1615043169071 Marionette INFO Stopped listening on port 62049 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615043170103 geckodriver INFO Listening on 127.0.0.1:62140 +1615043173146 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofiles4SLu8" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043176734 Marionette INFO Listening on port 62149 +1615043176795 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043177163 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: , line 0: TypeError: NetworkError when attempting to fetch resource. +1615043199907 Marionette INFO Stopped listening on port 62149 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615043200853 geckodriver INFO Listening on 127.0.0.1:62249 +1615043203885 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofilevgapmm" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043207290 Marionette INFO Listening on port 62258 +1615043207530 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043207841 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615043223977 Marionette INFO Stopped listening on port 62258 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615043692269 geckodriver INFO Listening on 127.0.0.1:62572 +1615043695302 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileV0YROd" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615043699196 Marionette INFO Listening on port 62582 +1615043699447 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043699807 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615043701992 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615043708556 Marionette INFO Stopped listening on port 62582 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615047055785 geckodriver INFO Listening on 127.0.0.1:63999 +1615047059454 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileQo57ZN" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615047063057 Marionette INFO Listening on port 64008 +1615047063108 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615047063530 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615047065725 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615047072314 Marionette INFO Stopped listening on port 64008 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615047967933 geckodriver INFO Listening on 127.0.0.1:64531 +1615047970977 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileQtNWv5" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615047973642 Marionette INFO Listening on port 64541 +1615047974102 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615047974424 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615047976575 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615047994911 Marionette INFO Stopped listening on port 64541 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615048449240 geckodriver INFO Listening on 127.0.0.1:64830 +1615048452275 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileevVRax" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615048454827 Marionette INFO Listening on port 64839 +1615048454904 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615048455335 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615048457507 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615048491401 Marionette INFO Stopped listening on port 64839 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615050844856 geckodriver INFO Listening on 127.0.0.1:49873 +1615050847900 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofilePTDkPq" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615050851900 Marionette INFO Listening on port 49882 +1615050852072 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615050852489 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615050854682 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615050870720 Marionette INFO Stopped listening on port 49882 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615050910676 geckodriver INFO Listening on 127.0.0.1:49999 +1615050913721 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofile2yCdPj" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615050916670 Marionette INFO Listening on port 50068 +1615050916850 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615050917238 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615050919423 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615050967669 Marionette INFO Stopped listening on port 50068 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615051183174 geckodriver INFO Listening on 127.0.0.1:50261 +1615051186215 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofile7YjQoR" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615051189691 Marionette INFO Listening on port 50270 +1615051189843 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051190148 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051192314 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615051210379 Marionette INFO Stopped listening on port 50270 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615051317927 geckodriver INFO Listening on 127.0.0.1:50394 +1615051320948 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofilelamOPA" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615051323677 Marionette INFO Listening on port 50404 +1615051324074 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051324407 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051326549 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615051344620 Marionette INFO Stopped listening on port 50404 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615051423820 geckodriver INFO Listening on 127.0.0.1:50524 +1615051426867 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileDDas5O" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615051429347 Marionette INFO Listening on port 50533 +1615051429500 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051429823 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051432010 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615051513660 Marionette INFO Stopped listening on port 50533 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +1615051685641 geckodriver INFO Listening on 127.0.0.1:50719 +1615051688688 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Tmfwa\\AppData\\Local\\Temp\\rust_mozprofileWICtGJ" +console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)")) +1615051691392 Marionette INFO Listening on port 50728 +1615051691819 Marionette WARN TLS certificate errors will be ignored for this session +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051692165 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +JavaScript error: http://localhost:9090/scripts/scripts.js, line 36: TypeError: document.getElementById(...) is null +1615051694311 Marionette WARN Ignoring event 'DOMContentLoaded' because document has an invalid readyState of 'complete'. +1615051712385 Marionette INFO Stopped listening on port 50728 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + diff --git a/backend/secfit/workouts/seleniumLeaderboardIntegrationTest.py b/backend/secfit/workouts/seleniumLeaderboardIntegrationTest.py new file mode 100644 index 0000000000000000000000000000000000000000..54bafb28b829b70bb232690f8dccf8764e4400fe --- /dev/null +++ b/backend/secfit/workouts/seleniumLeaderboardIntegrationTest.py @@ -0,0 +1,209 @@ +import unittest +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from webdriver_manager.firefox import GeckoDriverManager +import time +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +from datetime import datetime + +# <---------- IMPORTANT ---------> +# MUST HAVE FIREFOX, SELENIUM AND WEBDRIVER INSTALLED TO RUN THESE TESTS: +# pip install selenium +# pip install webdriver-manager + +# Before running this test, remember to host the application on http://localhost:9090 using docker-compose up --build +# in the main project folder + +# Test is run by: python seleniumLeaderboardIntegrationTest.py (when in the workouts-folder) +class TestExerciseLeaderboard(unittest.TestCase): + + # Creates two unique usernames to be used in the tests; + # by appending the current exact time to the username, we will always have unique usernames + uniqueUsername1 = "LikeTestUser1-" + datetime.utcnow().strftime("%m-%d-%Y-%H-%M-%S.%f") + uniqueUsername2 = "LikeTestUser2-" + datetime.utcnow().strftime("%m-%d-%Y-%H-%M-%S.%f") + + + # Runs before each test + def setUp(self): + self.driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()) + + # Sets an implicit wait of 10 seconds (Test will wait for up to 10 seconds for an expected DOM element) + self.driver.implicitly_wait(10) + + # Tests that a user auto-likes his own workout + def test_is_on_leaderboard(self): + driver = self.driver + + # Opens the web browser, and logs out just in case someone was already logged in + driver.get("http://localhost:9090/logout.html") + time.sleep(2) + + # Registers a new user + self.registerUser(self.__class__.uniqueUsername1) + + # Find and clicks the button to go to the exercise page + exerciseNavButton = driver.find_element_by_id("nav-exercises") + exerciseNavButton.click() + time.sleep(2) + + # Find and clicks the button to go the the "create new exercise" page + createExerciseButton = driver.find_element_by_id("btn-create-exercise") + createExerciseButton.click() + time.sleep(2) + + # Finds the input fields + exerciseNameField = driver.find_element_by_id("inputName") + exerciseDescriptionField = driver.find_element_by_id("inputDescription") + exerciseUnitField = driver.find_element_by_id("inputUnit") + + # Inputs values into the input fields + exerciseNameField.send_keys("TestLeaderboardExercise") + exerciseDescriptionField.send_keys("This exercise is only meant for testing purposes") + exerciseUnitField.send_keys("Test") + time.sleep(1) + + # Submits the new exerice + submitExerciseButton = driver.find_element_by_id("btn-ok-exercise") + submitExerciseButton.click() + time.sleep(2) + + self.scroll_down() + + # Inspects the newest exercise + exercise = driver.find_elements_by_css_selector("a.list-group-item")[-1] + exercise.click() + time.sleep(2) + + # All the rows in the leaderboard + leaderboardRows = driver.find_elements_by_tag_name("tr") + + # Tests that the leaderboard has 2 rows; one is the header, and the other should be the user's entry + self.assertEqual(2, len(leaderboardRows)) + + print([ele.text for ele in leaderboardRows]) + + leaderboard = [] + + # Converts the text into a list of dictionaries for easy testing purposes + for i in range(1, len(leaderboardRows)): + row = leaderboardRows[i].text.split(" ") + leaderboard.append({"rank": row[0], "username": row[1], "score": row[2]}) + + # Tests that the rank is correct in the leaderboard + self.assertEqual("1", leaderboard[0]["rank"]) + + # Tests that the username is correct in the leaderboard + self.assertEqual(self.__class__.uniqueUsername1, leaderboard[0]["username"]) + + #Tests that the score is correct in the leaderboard + self.assertEqual("0", leaderboard[0]["score"]) + + time.sleep(100) + + + # <---------Deletes the newest exercise--------> + # Find and clicks the button to go to the exercise page + exerciseNavButton = driver.find_element_by_id("nav-exercises") + exerciseNavButton.click() + time.sleep(2) + + self.scroll_down() + + # Inspects the newest exercise + exerciseToDelete = driver.find_elements_by_css_selector("a.list-group-item")[-1] + exerciseToDelete.click() + time.sleep(2) + + # Starts editing the exercise + editButton = driver.find_element_by_id("btn-edit-exercise") + editButton.click() + time.sleep(1) + + # Deletes the exercise + deleteWorkoutButton = driver.find_element_by_id("btn-delete-exercise") + deleteWorkoutButton.click() + time.sleep(1) + # >---------------------------< + + + + + + + # Function used to register a new user + def registerUser(self, uniqueUsername): + + print(uniqueUsername) + driver = self.driver + + # Logs out, just in case a user is already logged in + driver.get("http://localhost:9090/logout.html") + time.sleep(2) + + # Goes to the register page + driver.get("http://localhost:9090/register.html") + time.sleep(2) + + # Finds all the input fields in the register form + usernameField = driver.find_element_by_name('username') + emailField = driver.find_element_by_name('email') + passwordField = driver.find_element_by_name('password') + repeatPasswordField = driver.find_element_by_name('password1') + phoneNumberField = driver.find_element_by_name('phone_number') + countryField = driver.find_element_by_name('country') + cityField = driver.find_element_by_name('city') + streetAddressField = driver.find_element_by_name('street_address') + + # Inputs values in all the registration fields + usernameField.send_keys(uniqueUsername) + emailField.send_keys(uniqueUsername + "@test.test") + passwordField.send_keys("123") + repeatPasswordField.send_keys("123") + phoneNumberField.send_keys("12312312") + countryField.send_keys("Norway") + cityField.send_keys("Narvik") + streetAddressField.send_keys("Kvartslia") + + # Finds and clicks the button that creates the account + createAccountButton = driver.find_element_by_id("btn-create-account") + createAccountButton.click() + time.sleep(2) + + + + # Runs after running the tests + def tearDown(self): + self.driver.close() + + # Code for scrolling to the end of a dynamically loading page; + # from https://stackoverflow.com/questions/48850974/selenium-scroll-to-end-of-page-in-dynamically-loading-webpage + def scroll_down(self): + """A method for scrolling the page.""" + + # Get scroll height. + last_height = self.driver.execute_script("return document.body.scrollHeight") + + while True: + + # Scroll down to the bottom. + self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") + + # Wait to load the page. + time.sleep(2) + + # Calculate new scroll height and compare with last scroll height. + new_height = self.driver.execute_script("return document.body.scrollHeight") + + if new_height == last_height: + break + + last_height = new_height + + +if __name__ == "__main__": + unittest.main() + + diff --git a/backend/secfit/workouts/seleniumLikeIntegrationTest.py b/backend/secfit/workouts/seleniumLikeIntegrationTest.py index b63e0f2624384300b3377cfac7a1ab067a690081..5b77e12c39b4284c05c486f2c68ad33242be32e1 100644 --- a/backend/secfit/workouts/seleniumLikeIntegrationTest.py +++ b/backend/secfit/workouts/seleniumLikeIntegrationTest.py @@ -17,7 +17,7 @@ from datetime import datetime # Before running this test, remember to host the application on http://localhost:9090 using docker-compose up --build # in the main project folder -# Test is run by: python seleniumLikeIntegrationTest.py (when in the workouts-folder) +# Test is run by: python seleniumLikeIntegrationTest.py (when in the workouts-folder and while website is live with docker) class TestWorkoutLikes(unittest.TestCase): # Creates two unique usernames to be used in the tests; @@ -90,7 +90,7 @@ class TestWorkoutLikes(unittest.TestCase): # Inputs values into fields workoutNameField.send_keys("TestWorkout") workoutDateField.clear(); - workoutDateField.send_keys("2020-01-01 12:00"); + workoutDateField.send_keys("1111-01-01 00:01"); workoutNotesField.send_keys("This is an auto-generated workout meant for testing") time.sleep(1) diff --git a/backend/secfit/workouts/views.py b/backend/secfit/workouts/views.py index 1ec5a605f0d66b475c3ad859961aae08030da73e..cf284c6ec62bf1e2828997368453659cf545f239 100644 --- a/backend/secfit/workouts/views.py +++ b/backend/secfit/workouts/views.py @@ -255,7 +255,8 @@ class Leaderboards(APIView): for j in range(0, len(leaderboardNumbers)): if leaderboardNumbers[j]['workout__owner__pk'] == currentLoggedInUser.pk: - leaderboardResult.append({"name": currentLoggedInUser.username, "value": leaderboardNumbers[j]["amount"], "rank": j+1}) + if j+1 > 5: + leaderboardResult.append({"name": currentLoggedInUser.username, "value": leaderboardNumbers[j]["amount"], "rank": j+1}) break else: leaderboardResult.append({"name": currentLoggedInUser.username, "value": 0, "rank": len(leaderboardNumbers) + 1})