Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

486 selenium single check card #499

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ echo "{
\"message\": \"$COMMIT_MSG\",
\"date\": \"$DATE\",
\"version\": \"$VERSION\"
}"
}"
23 changes: 23 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## For beginning:

You should have Firefox, installed not in 'snap'.

Install requirements.txt:

```bash
$ pip install -r tests/requirements.txt
```


## Test for open single check card:
class SingleCheckTestSelenium(BasicSeleniumTest) with 1 test

Test check: if page with random single check opens (from "/check_list")

## Run run_tests

use login and password from .env

```bash
$ python tests/main.py --host host --login login --password password
```
47 changes: 47 additions & 0 deletions tests/basic_selenium_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import unittest
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.common.by import By
from webdriver_manager.firefox import GeckoDriverManager #pip install webdriver-manager

class BasicSeleniumTest(unittest.TestCase):

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install())) #you should have Firefox, installed not from snap

def authorization(self):
host, login_param, password_param = self.param
URL = self.getUrl('/login')
self.getDriver().get(URL)
self.getDriver().implicitly_wait(30)
login = self.getDriver().find_element(By.ID, "login_text_field")
login.clear()
login.send_keys(login_param)
password = self.getDriver().find_element(By.ID, "password_text_field")
password.clear()
password.send_keys(password_param)
login_button = self.getDriver().find_element(By.ID, "login_button")
login_button.click()


def __init__(self, methodName='runTest', param=None):
super(BasicSeleniumTest, self).__init__(methodName)
self.param = param

@staticmethod
def parametrize(testcase_class, param=None):
testloader = unittest.TestLoader()
testnames = testloader.getTestCaseNames(testcase_class)
suite = unittest.TestSuite()
for name in testnames:
suite.addTest(testcase_class(name, param=param))
return suite

def getUrl(self, relativePath):
return self.param[0] + relativePath

def getDriver(_):
return BasicSeleniumTest.driver

@classmethod
def closeDriver(cls):
cls.driver.close()
26 changes: 26 additions & 0 deletions tests/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest
import sys
import argparse
from basic_selenium_test import BasicSeleniumTest
from test_single_card_check import SingleCheckTestSelenium

def parse_arguments():
parser = argparse.ArgumentParser(description='Run Selenium tests with specified host, login, and password.')
parser.add_argument('--host', type=str, default='http://127.0.0.1:8080', help='Host address for testing')
parser.add_argument('--login', type=str, required=True, help='insert Username')
parser.add_argument('--password', type=str, required=True, help='insert Password')
return parser.parse_args()

def main():
args = parse_arguments()

suite = unittest.TestSuite()
suite.addTest(BasicSeleniumTest.parametrize(SingleCheckTestSelenium, param=(args.host, args.login, args.password)))

returnCode = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful()

BasicSeleniumTest.closeDriver()
sys.exit(returnCode)

if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
selenium==4.16.0 #in this version you don't need to download geckodriver
webdriver-manager==4.0.1 #to avoid problem with binary
18 changes: 18 additions & 0 deletions tests/test_single_card_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from basic_selenium_test import BasicSeleniumTest
from selenium.webdriver.common.by import By

class SingleCheckTestSelenium(BasicSeleniumTest):

def test_open_check_card(self):
self.authorization()
URL = self.getUrl('/check_list')
self.getDriver().get(URL)
self.getDriver().implicitly_wait(30)
single_check = self.getDriver().find_element(By.XPATH, "//table[@id='check-list-table']//tr/td/a")
id_check_button = single_check.get_attribute("href").split("/")[-1]
URL = self.getUrl(f'/results/{id_check_button}')
self.getDriver().get(URL)
obj = self.getDriver().find_element(By.ID, 'results_holder')
self.assertNotEquals(obj, None)

Loading