Skip to content

Commit

Permalink
add test folder and first test
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinaProsche committed Dec 11, 2023
1 parent b8ee64e commit 2218ad6
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ pytest~=7.1.2
filetype==1.2.0
language-tool-python==2.7.1
markdown==3.4.4
selenium==4.16.0
44 changes: 44 additions & 0 deletions tests/basic_selenium_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import unittest
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options

class BasicSeleniumTest(unittest.TestCase):

# options = Options()
# options.binary_location = r'~/home/snap/bin/firefox'
# driver = webdriver.Firefox(options=options)

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))

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

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

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

def getDriver(_):
return BasicSeleniumTest.driver

@classmethod
def closeDriver(cls):
cls.driver.close()



# def setUp(self):
# self.driver = webdriver.Firefox() # Chrome()

# def tearDown(self):
# self.driver.close()
24 changes: 24 additions & 0 deletions tests/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest
import sys
from basic_selenium_test import BasicSeleniumTest
from test_authorization import AuthTestSelenium


def main(host):
suite = unittest.TestSuite()

suite.addTest(
BasicSeleniumTest.parametrize(
AuthTestSelenium,
param=host))

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

BasicSeleniumTest.closeDriver()
sys.exit(returnCode)


if __name__ == '__main__':
host_arg = 'https://slides-checker.moevm.info'
main(host_arg)
Empty file removed tests/test_authoriation
Empty file.
36 changes: 36 additions & 0 deletions tests/test_authorization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
import time
from basic_selenium_test import BasicSeleniumTest
from selenium.webdriver.common.by import By

# AUTH_URL = 'https://slides-checker.moevm.info/login'

class AuthTestSelenium(BasicSeleniumTest):

def test_loading(self):
URL = self.getUrl('/login')
self.getDriver().get(URL)
self.getDriver().implicitly_wait(30)
obj = self.getDriver().find_element(By.CLASS_NAME, "form-group")
self.assertNotEquals(obj, None)
return True


def failed_auth(self):
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('wrong_login')

password = self.getDriver().find_element(By.ID, "password_text_field")
password.clear()
password.send_keys('wrong_password')

login_button = self.getDriver().find_element(By.ID, "login_button")
login_button.click()
obj = self.getDriver().find_element(By.CLASS_NAME, "invalid-feedback ins")
self.assertNotEquals(obj, None)

0 comments on commit 2218ad6

Please sign in to comment.