-
Notifications
You must be signed in to change notification settings - Fork 2
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
485 selenium test statistic #493
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b8ee64e
add folder tests
MarinaProsche 2218ad6
add test folder and first test
MarinaProsche e095e91
first version of auyh tests
MarinaProsche 10950d7
added param in commandline and class
MarinaProsche 3dc0bb7
from basic test
MarinaProsche 05c504f
first version of test_statistic
MarinaProsche c216d92
requrements.txt and def authorization() added
MarinaProsche ed59b0f
Merge branch '481_first_selenium_test' into 485_selenium_test_statistic
MarinaProsche 0145493
test_statistic improved
MarinaProsche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 page /version: | ||
class StatisticTestSelenium(BasicSeleniumTest) with 1 test | ||
|
||
Test check: if page "/check_list" opens | ||
|
||
## Run run_tests | ||
|
||
use login and password from .env | ||
|
||
```bash | ||
$ python tests/main.py --host host --login login --password password | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_statistic import StatisticTestSelenium | ||
|
||
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(StatisticTestSelenium, 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
from basic_selenium_test import BasicSeleniumTest | ||
from selenium.webdriver.common.by import By | ||
|
||
class StatisticTestSelenium(BasicSeleniumTest): | ||
|
||
def test_open_statistic(self): | ||
self.authorization() | ||
URL = self.getUrl('/check_list') | ||
self.getDriver().get(URL) | ||
self.getDriver().implicitly_wait(30) | ||
obj = self.getDriver().find_element(By.CLASS_NAME, "fixed-table-container") | ||
self.assertNotEquals(obj, None) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я бы предложил усилить тест - проверить наличие строк в таблице (или их отсутствие, если проверок нет) - т.е. дождаться загрузки данных таблицы
Loading, please wait
- было бы хорошо, если этот (или другой тест) проверял бы этот моментThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправила.