Best Python code snippet using Airtest
functional_test.py
Source:functional_test.py
...15 self.browser.quit()16 def test_title(self):17 self.assertIn('Welcome Page', self.browser.title, 'Wrong Title')18 def makeUser(self):19 createUserBtn = self.browser.find_element_by_id('createUser')20 createUserBtn.click()21 #Form Page22 first = self.browser.find_element_by_id('firstName')23 last = self.browser.find_element_by_id('lastName')24 email = self.browser.find_element_by_id('email')25 password = self.browser.find_element_by_id('password')26 first.send_keys('David')27 last.send_keys('Cloak')28 email.send_keys('email@email.com')29 password.send_keys('thePassword')30 confermBtn = self.browser.find_element_by_id('submit')31 confermBtn.click()32 def testMakeUser(self):33 self.makeUser()34 #Confermaiton Page35 self.assertIn('David Cloak', self.browser.find_element_by_id('name').text, 'Name Not Found')36 self.assertIn('email@email.com', self.browser.find_element_by_id('email').text, 'Email Not Found')37 self.assertIn('XXXXXXXXXXX', self.browser.find_element_by_id('password').text, 'Password Not Found')38 returnHomeBtn = self.browser.find_element_by_id('home')39 returnHomeBtn.click()40 #Home Page41 self.assertIn('David', self.browser.find_element_by_id('user').text, 'Name Not Found')42class LoginTest(unittest.TestCase):43 def setUp(self):44 fireFoxOptions = webdriver.FirefoxOptions()45 fireFoxOptions.headless=True46 self.browser = webdriver.Firefox(options=fireFoxOptions)47 self.browser.get('http://127.0.0.1:8000')48 49 def tearDown(self):50 self.browser.quit()51 #to unsure the user is made before hand since I am not52 #using a database yet53 def makeUser(self):54 createUserBtn = self.browser.find_element_by_id('createUser')55 createUserBtn.click()56 #Form Page57 first = self.browser.find_element_by_id('firstName')58 last = self.browser.find_element_by_id('lastName')59 email = self.browser.find_element_by_id('email')60 password = self.browser.find_element_by_id('password')61 first.send_keys('David')62 last.send_keys('Cloak')63 email.send_keys('email@email.com')64 password.send_keys('thePassword')65 confermBtn = self.browser.find_element_by_id('submit')66 confermBtn.click()67 def testLogin(self):68 self.makeUser()69 self.browser.get('http://127.0.0.1:8000')70 loginBtn = self.browser.find_element_by_id('login')71 loginBtn.click()72 email = self.browser.find_element_by_id('email')73 password = self.browser.find_element_by_id('password')74 email.send_keys('email@email.com')75 password.send_keys('thePassword')76 confermBtn = self.browser.find_element_by_id('submit')77 confermBtn.click()78 #Home Page79 self.assertIn('David', self.browser.find_element_by_id('user').text, 'Name Not Found')80class GameTest(unittest.TestCase):81 def setUp(self):82 fireFoxOptions = webdriver.FirefoxOptions()83 fireFoxOptions.headless=True84 self.browser = webdriver.Firefox(options=fireFoxOptions)85 self.browser.get('http://127.0.0.1:8000')86 87 def tearDown(self):88 self.browser.quit()89 #to unsure the user is made before hand since I am not90 #using a database yet91 def makeUser(self):92 createUserBtn = self.browser.find_element_by_id('createUser')93 createUserBtn.click()94 #Form Page95 first = self.browser.find_element_by_id('firstName')96 last = self.browser.find_element_by_id('lastName')97 email = self.browser.find_element_by_id('email')98 password = self.browser.find_element_by_id('password')99 first.send_keys('David')100 last.send_keys('Cloak')101 email.send_keys('email@email.com')102 password.send_keys('thePassword')103 confermBtn = self.browser.find_element_by_id('submit')104 confermBtn.click()105 def testGameSecond(self):106 self.makeUser()107 #puts us on home page108 self.browser.get('http://127.0.0.1:8000/Home')109 #goes to game110 gameLink = self.browser.find_element_by_id('gamebtn')111 gameLink.click()112 firstList = self.browser.find_element_by_id('options')113 self.assertIn('Shall you adventure into the woods?', firstList.text, 'First Option not found')114 self.assertIn('Shall you adventure into the sea?', firstList.text, 'Second Option not found')115 self.assertIn('Shall you adventure into the cave?', firstList.text, 'Third Option not found')116 gameLink = self.browser.find_element_by_id('second')117 gameLink.click()118 secondList = self.browser.find_element_by_id('options')119 self.assertIn('Capture the Squid', secondList.text, 'First Option not found')120 self.assertIn('Flee', secondList.text, 'Second Option not found')121 self.assertIn('Kill and have him for supper', secondList.text, 'Third Option not found')122 gameLink = self.browser.find_element_by_id('second')123 gameLink.click()124 self.assertIn('Trying to run attracted the squids attention and it came and ate everyone on board.', self.browser.find_element_by_id('endMessage').text, 'End Message missing')125 def testGameFirst(self):126 self.makeUser()127 #puts us on home page128 self.browser.get('http://127.0.0.1:8000/Home')129 #goes to game130 gameLink = self.browser.find_element_by_id('gamebtn')131 gameLink.click()132 firstList = self.browser.find_element_by_id('options')133 self.assertIn('Shall you adventure into the woods?', firstList.text, 'First Option not found')134 self.assertIn('Shall you adventure into the sea?', firstList.text, 'Second Option not found')135 self.assertIn('Shall you adventure into the cave?', firstList.text, 'Third Option not found')136 gameLink = self.browser.find_element_by_id('first')137 gameLink.click()138 secondList = self.browser.find_element_by_id('options')139 self.assertIn('Run', secondList.text, 'First Option not found')140 self.assertIn('Stand your ground!', secondList.text, 'Second Option not found')141 self.assertIn('Throw a rock at it.', secondList.text, 'Third Option not found')142 gameLink = self.browser.find_element_by_id('second')143 gameLink.click()144 self.assertIn('What were you think standing your grand you have no armor or weapons to defend yourself? He ate you in short.', self.browser.find_element_by_id('endMessage').text, 'End Message missing')145 def testGameThird(self):146 self.makeUser()147 #puts us on home page148 self.browser.get('http://127.0.0.1:8000/Home')149 #goes to game150 gameLink = self.browser.find_element_by_id('gamebtn')151 gameLink.click()152 firstList = self.browser.find_element_by_id('options')153 self.assertIn('Shall you adventure into the woods?', firstList.text, 'First Option not found')154 self.assertIn('Shall you adventure into the sea?', firstList.text, 'Second Option not found')155 self.assertIn('Shall you adventure into the cave?', firstList.text, 'Third Option not found')156 gameLink = self.browser.find_element_by_id('third')157 gameLink.click()158 secondList = self.browser.find_element_by_id('options')159 self.assertIn('Become one with the bats', secondList.text, 'First Option not found')160 self.assertIn('Play dead', secondList.text, 'Second Option not found')161 self.assertIn('You are deathly afraid of bats.', secondList.text, 'Third Option not found')162 gameLink = self.browser.find_element_by_id('second')163 gameLink.click()164 self.assertIn('Most bats are not human eaters. But these bats know a free meal when they see it and ate what they thought was long dead.', self.browser.find_element_by_id('endMessage').text, 'End Message missing')165class StyleAndLayoutTest(unittest.TestCase):166 def setUp(self):167 fireFoxOptions = webdriver.FirefoxOptions()168 fireFoxOptions.headless=True169 self.browser = webdriver.Firefox(options=fireFoxOptions)170 self.browser.get('http://127.0.0.1:8000')171 172 def tearDown(self):173 self.browser.quit()174 def testIndexPage(self):175 self.browser.set_window_size(1024, 768)176 buttons = self.browser.find_element_by_id('buttons')177 self.assertAlmostEqual(178 buttons.location['x'] + buttons.size['width'] / 2,179 512,180 delta=10181 )182 def testConferm(self):183 self.browser.get('http://127.0.0.1:8000/Conferm')184 self.browser.set_window_size(1024, 768)185 context = self.browser.find_element_by_id('context')186 self.assertAlmostEqual(187 context.location['x'] + context.size['width'] / 2,188 512,189 delta=10190 )191 def testGamePage(self):192 self.browser.get('http://127.0.0.1:8000/Game')193 self.browser.set_window_size(1024, 768)194 items = self.browser.find_element_by_id('context')195 self.assertAlmostEqual(196 items.location['x'] + items.size['width'] / 2,197 512,198 delta=10199 )200 self.browser.get('http://127.0.0.1:8000/Game')201 202 background = self.browser.find_element_by_id('background').value_of_css_property('background-color')203 self.assertEquals("rgb(0, 0, 0)", background, "Background color is incorrect.")204 backgroundImg = self.browser.find_element_by_id('image').value_of_css_property('background-image')205 self.assertEquals('url("https://davidcloak.github.io/DjangoStaticFile/Interactive/images/Welcome.jpg")', backgroundImg, "Image is incorrect. Welcome")206 gameLink = self.browser.find_element_by_id('first')207 gameLink.click()208 background = self.browser.find_element_by_id('background').value_of_css_property('background-color')209 self.assertEquals("rgb(0, 0, 0)", background, "Background color is incorrect. Forsest")210 backgroundImg = self.browser.find_element_by_id('image').value_of_css_property('background-image')211 self.assertEquals('url("https://davidcloak.github.io/DjangoStaticFile/Interactive/images/Forest.jpg")', backgroundImg, "Image is incorrect. Forest")212 self.browser.get('http://127.0.0.1:8000/Game')213 gameLink = self.browser.find_element_by_id('second')214 gameLink.click()215 background = self.browser.find_element_by_id('background').value_of_css_property('background-color')216 self.assertEquals("rgb(0, 0, 0)", background, "Background color is incorrect. Sea")217 backgroundImg = self.browser.find_element_by_id('image').value_of_css_property('background-image')218 self.assertEquals('url("https://davidcloak.github.io/DjangoStaticFile/Interactive/images/Sea.jpg")', backgroundImg, "Image is incorrect. Sea")219 self.browser.get('http://127.0.0.1:8000/Game')220 gameLink = self.browser.find_element_by_id('third')221 gameLink.click()222 background = self.browser.find_element_by_id('background').value_of_css_property('background-color')223 self.assertEquals("rgb(0, 0, 0)", background, "Background color is incorrect. Cave")224 backgroundImg = self.browser.find_element_by_id('image').value_of_css_property('background-image')225 self.assertEquals('url("https://davidcloak.github.io/DjangoStaticFile/Interactive/images/Cave.jpg")', backgroundImg, "Image is incorrect. Cave")226 def testGameEndPage(self):227 self.browser.get('http://127.0.0.1:8000/GameEnd')228 self.browser.set_window_size(1024, 768)229 context = self.browser.find_element_by_id('context')230 self.assertAlmostEqual(231 context.location['x'] + context.size['width'] / 2,232 512,233 delta=10234 )235 background = self.browser.find_element_by_id('background').value_of_css_property('background-color')236 self.assertEquals("rgb(0, 0, 0)", background, "Background color is incorrect.")237 endScreen = self.browser.find_element_by_id('endMessage').value_of_css_property('color')238 self.assertEquals("rgb(255, 0, 0)", endScreen, "Color of text is incorrect.")239class MarioGameAddonTests(unittest.TestCase):240 def setUp(self):241 fireFoxOptions = webdriver.FirefoxOptions()242 fireFoxOptions.headless=True243 self.browser = webdriver.Firefox(options=fireFoxOptions)244 self.browser.get('http://127.0.0.1:8000')245 246 def tearDown(self):247 self.browser.quit()248 def testMarioGameNavLinkHome(self):249 self.browser.get('http://127.0.0.1:8000/Home')250 self.browser.set_window_size(1024, 768)251 button = self.browser.find_element_by_id('MarioGameBtn')252 button.click()253 254 screan = self.browser.find_element_by_id('content')255 self.assertAlmostEqual(256 screan.location['x'] + screan.size['width'] / 2,257 512,258 delta=10259 )260 def testMarioGameNavLinkGame(self):261 self.browser.get('http://127.0.0.1:8000/Game')262 self.browser.set_window_size(1024, 768)263 button = self.browser.find_element_by_id('MarioGameBtn')264 button.click()265 screan = self.browser.find_element_by_id('content')266 self.assertAlmostEqual(267 screan.location['x'] + screan.size['width'] / 2,268 512,269 delta=10270 )271 def testMarioGameNavLinkGameEnd(self):272 self.browser.get('http://127.0.0.1:8000/GameEnd')273 self.browser.set_window_size(1024, 768)274 button = self.browser.find_element_by_id('MarioGameBtn')275 button.click()276 screan = self.browser.find_element_by_id('content')277 self.assertAlmostEqual(278 screan.location['x'] + screan.size['width'] / 2,279 512,280 delta=10281 )282class UserReLoginTest(unittest.TestCase):283 def setUp(self):284 fireFoxOptions = webdriver.FirefoxOptions()285 fireFoxOptions.headless=True286 self.browser = webdriver.Firefox(options=fireFoxOptions)287 self.browser.get('http://127.0.0.1:8000')288 289 def tearDown(self):290 self.browser.quit()291 def testMakeNewUser(self):292 createUserBtn = self.browser.find_element_by_id('createUser')293 createUserBtn.click()294 #Form Page295 first = self.browser.find_element_by_id('firstName')296 last = self.browser.find_element_by_id('lastName')297 email = self.browser.find_element_by_id('email')298 password = self.browser.find_element_by_id('password')299 rand = randint(1, 10000)300 first.send_keys('David')301 last.send_keys('Cloak')302 email.send_keys('email'+str(rand)+'@email.com')303 password.send_keys('thePassword')304 confermBtn = self.browser.find_element_by_id('submit')305 confermBtn.click()306 self.browser.get('http://127.0.0.1:8000/Logout')307 btn = self.browser.find_element_by_id('logout')308 btn.click()309 login = self.browser.find_element_by_id('login')310 login.click()311 email = self.browser.find_element_by_id('email')312 password = self.browser.find_element_by_id('password')313 email.send_keys('email'+str(rand)+'@email.com')314 password.send_keys('thePassword')315 btn = self.browser.find_element_by_id('submit')316 btn.click()317 user = self.browser.find_element_by_id('user').text318 self.assertIn('David', user, 'User Not Loged in')319 def testOldUser(self):320 login = self.browser.find_element_by_id('login')321 login.click()322 email = self.browser.find_element_by_id('email')323 password = self.browser.find_element_by_id('password')324 email.send_keys('email@email.com')325 password.send_keys('thePassword')326 btn = self.browser.find_element_by_id('submit')327 btn.click()328 user = self.browser.find_element_by_id('user').text329 self.assertIn('David', user, 'User Not Loged in')330if __name__ == '__main__':331 #calls the class if it is not instantiated elsewhere...
test_views_admin.py
Source:test_views_admin.py
...7 driver = webdriver.Chrome()8 driver.get('http://127.0.0.1:5000')9 dig_confirm = driver.switch_to.alert10 dig_confirm.accept()11 driver.find_element_by_id('x1').clear()12 # è¾å
¥ç¨æ·å13 driver.find_element_by_id('x1').send_keys('13086618316')14 # æ¸
空å¯ç è¾å
¥15 driver.find_element_by_id('pwd').clear()16 # è¾å
¥å¯ç 17 driver.find_element_by_id('pwd').send_keys('123')18 driver.find_element_by_id('x2').click()19 a = "http://127.0.0.1:5000/admin_index/"20 b = driver.current_url21 assert a == b22 driver.quit()2324def test_login02():25 driver = webdriver.Chrome()26 driver.get('http://127.0.0.1:5000')27 dig_confirm = driver.switch_to.alert28 dig_confirm.accept()29 driver.find_element_by_id('x1').clear()30 # æ¸
空å¯ç è¾å
¥31 driver.find_element_by_id('pwd').clear()32 # è¾å
¥å¯ç 33 driver.find_element_by_id('pwd').send_keys('123')34 driver.find_element_by_id('x2').click()35 result = EC.alert_is_present()(driver)36 assert result != False37 driver.quit()3839def test_login03():40 driver = webdriver.Chrome()41 driver.get('http://127.0.0.1:5000')42 dig_confirm = driver.switch_to.alert43 dig_confirm.accept()44 driver.find_element_by_id('x1').clear()45 # è¾å
¥ç¨æ·å46 driver.find_element_by_id('x1').send_keys('13086618316')47 # æ¸
空å¯ç è¾å
¥48 driver.find_element_by_id('pwd').clear()49 # è¾å
¥å¯ç 50 driver.find_element_by_id('x2').click()51 result = EC.alert_is_present()(driver)52 assert result != False53 driver.quit()5455def test_list_all_movie():56 driver = webdriver.Chrome()57 driver.get('http://127.0.0.1:5000')58 dig_confirm = driver.switch_to.alert59 dig_confirm.accept()60 driver.find_element_by_id('x1').clear()61 # è¾å
¥ç¨æ·å62 driver.find_element_by_id('x1').send_keys('13086618316')63 # æ¸
空å¯ç è¾å
¥64 driver.find_element_by_id('pwd').clear()65 # è¾å
¥å¯ç 66 driver.find_element_by_id('pwd').send_keys('123')67 driver.find_element_by_id('x2').click()68 driver.get('http://127.0.0.1:5000/admin_list_all_movies/')69 a = "http://127.0.0.1:5000/admin_list_all_movies/"70 b = driver.current_url71 assert a == b72 driver.quit()7374def test_add_a_movie01():75 driver = webdriver.Chrome()76 driver.get('http://127.0.0.1:5000')77 dig_confirm = driver.switch_to.alert78 dig_confirm.accept()79 driver.find_element_by_id('x1').clear()80 driver.find_element_by_id('x1').send_keys('13086618316')81 driver.find_element_by_id('pwd').clear()82 driver.find_element_by_id('pwd').send_keys('123')83 driver.find_element_by_id('x2').click()84 driver.get("http://127.0.0.1:5000/admin_add_new_movie/")85 driver.find_element_by_id('name').send_keys('testName')86 driver.find_element_by_id('submit').click()87 a = "http://127.0.0.1:5000/admin_add_new_movie/"88 b = driver.current_url89 assert a == b90 driver.find_element_by_id('blurb').send_keys('testBlurb')91 driver.find_element_by_id('submit').click()92 b = driver.current_url93 assert a == b94 driver.find_element_by_id('certificate').send_keys('testCertificate')95 driver.find_element_by_id('submit').click()96 b = driver.current_url97 assert a == b98 driver.find_element_by_id('director').send_keys('testDirector')99 driver.find_element_by_id('submit').click()100 b = driver.current_url101 assert a == b102 driver.find_element_by_id('actors').send_keys('testActors')103 driver.find_element_by_id('submit').click()104 b = driver.current_url105 assert a == b106 driver.find_element_by_name('picture').send_keys(r'C:\Users\39285\Desktop\testPicture.jpg')107 driver.find_element_by_name('poster').send_keys(r'C:\Users\39285\Desktop\testPicture.jpg')108 driver.find_element_by_id('name').clear()109 driver.find_element_by_id('submit').click()110 assert a == b111 driver.quit()112113def test_add_a_movie02():114 driver = webdriver.Chrome()115 driver.get('http://127.0.0.1:5000')116 dig_confirm = driver.switch_to.alert117 dig_confirm.accept()118 driver.find_element_by_id('x1').clear()119 driver.find_element_by_id('x1').send_keys('13086618316')120 driver.find_element_by_id('pwd').clear()121 driver.find_element_by_id('pwd').send_keys('123')122 driver.find_element_by_id('x2').click()123 driver.get("http://127.0.0.1:5000/admin_add_new_movie/")124 driver.find_element_by_id('name').send_keys('testName')125 driver.find_element_by_id('blurb').send_keys('testBlurb')126 driver.find_element_by_id('certificate').send_keys('testCertificate')127 driver.find_element_by_id('director').send_keys('testDirector')128 driver.find_element_by_id('actors').send_keys('testActors')129 driver.find_element_by_name('picture').send_keys(r'C:\Users\39285\Desktop\testPicture.jpg')130 driver.find_element_by_name('poster').send_keys(r'C:\Users\39285\Desktop\testPicture.jpg')131 driver.find_element_by_id('submit').click()132 a = "http://127.0.0.1:5000/admin_index/"133 b = driver.current_url134 assert a == b135 driver.quit()136137def test_delete_a_movie():138 driver = webdriver.Chrome()139 driver.get('http://127.0.0.1:5000')140 dig_confirm = driver.switch_to.alert141 dig_confirm.accept()142 driver.find_element_by_id('x1').clear()143 driver.find_element_by_id('x1').send_keys('13086618316')144 driver.find_element_by_id('pwd').clear()145 driver.find_element_by_id('pwd').send_keys('123')146 driver.find_element_by_id('x2').click()147 driver.get("http://127.0.0.1:5000/admin_list_all_movies/")148 hyperlinks_list = driver.find_element_by_class_name("table")149 # get images from the banner_list150 hyperlinks = hyperlinks_list.find_elements_by_tag_name("a")151 i = len(hyperlinks)152 hyperlinks[i-1].click()153 hyperlinks_list0 = driver.find_element_by_class_name("table")154 hyperlinks0 = hyperlinks_list0.find_elements_by_tag_name("a")155 assert len(hyperlinks) == len(hyperlinks0) + 1156 driver.quit()157158def test_add_a_hall01():159 driver = webdriver.Chrome()160 driver.get(r'http://127.0.0.1:5000')161 dig_confirm = driver.switch_to.alert162 dig_confirm.accept()163 driver.find_element_by_id('x1').clear()164 driver.find_element_by_id('x1').send_keys('13086618316')165 driver.find_element_by_id('pwd').clear()166 driver.find_element_by_id('pwd').send_keys('123')167 driver.find_element_by_id('x2').click()168 driver.get(r"http://127.0.0.1:5000/admin_add_new_hall/")169 driver.find_element_by_id('submit').click()170 a = "http://127.0.0.1:5000/admin_add_new_hall/"171 b = driver.current_url172 assert a == b173 driver.find_element_by_id('name').send_keys('testName')174 driver.find_element_by_id('submit').click()175 assert a == b176 driver.find_element_by_id('is_vip').send_keys('1')177 driver.find_element_by_id('name').clear()178 driver.find_element_by_id('submit').click()179 b = driver.current_url180 assert a == b181 driver.quit()182183def test_add_a_hall02():184 driver = webdriver.Chrome()185 driver.get(r'http://127.0.0.1:5000')186 dig_confirm = driver.switch_to.alert187 dig_confirm.accept()188 driver.find_element_by_id('x1').clear()189 driver.find_element_by_id('x1').send_keys('13086618316')190 driver.find_element_by_id('pwd').clear()191 driver.find_element_by_id('pwd').send_keys('123')192 driver.find_element_by_id('x2').click()193 driver.get(r"http://127.0.0.1:5000/admin_add_new_hall/")194 driver.find_element_by_id('submit').click()195 a = "http://127.0.0.1:5000/admin_index/"196 b = driver.current_url197 driver.find_element_by_id('name').send_keys('testName')198 driver.find_element_by_id('is_vip').send_keys('1')199 driver.find_element_by_id('submit').click()200 b = driver.current_url201 assert a == b202 driver.quit()203204def test_add_a_schedule01():205 driver = webdriver.Chrome()206 driver.get('http://127.0.0.1:5000')207 dig_confirm = driver.switch_to.alert208 dig_confirm.accept()209 driver.find_element_by_id('x1').clear()210 driver.find_element_by_id('x1').send_keys('13086618316')211 driver.find_element_by_id('pwd').clear()212 driver.find_element_by_id('pwd').send_keys('123')213 driver.find_element_by_id('x2').click()214 driver.get("http://127.0.0.1:5000/admin_add_new_schedule/")215 driver.find_element_by_id('submit').click()216 a = "http://127.0.0.1:5000/admin_add_new_schedule/"217 b = driver.current_url218 assert a == b219 driver.quit()220221def test_add_a_schedule02():222 driver = webdriver.Chrome()223 driver.get('http://127.0.0.1:5000')224 dig_confirm = driver.switch_to.alert225 dig_confirm.accept()226 driver.find_element_by_id('x1').clear()227 driver.find_element_by_id('x1').send_keys('13086618316')228 driver.find_element_by_id('pwd').clear()229 driver.find_element_by_id('pwd').send_keys('123')230 driver.find_element_by_id('x2').click()231 driver.get("http://127.0.0.1:5000/admin_add_new_schedule/")232 a = "http://127.0.0.1:5000/admin_index/"233 driver.find_element_by_id('date').send_keys('1.1.2020')234 driver.find_element_by_id('start_time').send_keys('8:00')235 driver.find_element_by_id('end_time').send_keys('22:00')236 driver.find_element_by_id('price').send_keys('20')237 b = driver.current_url238 assert a == b239 driver.quit()240241def test_pie_graph():242 driver = webdriver.Chrome()243 driver.get('http://127.0.0.1:5000')244 dig_confirm = driver.switch_to.alert245 dig_confirm.accept()246 driver.find_element_by_id('x1').clear()247 driver.find_element_by_id('x1').send_keys('13086618316')248 driver.find_element_by_id('pwd').clear()249 driver.find_element_by_id('pwd').send_keys('123')250 driver.find_element_by_id('x2').click()251 driver.get("http://127.0.0.1:5000/admin_pie_graph/")252 a = "http://127.0.0.1:5000/admin_pie_graph/"253 b = driver.current_url254 assert a == b255 driver.quit()256257def test_list_all_user():258 driver = webdriver.Chrome()259 driver.get('http://127.0.0.1:5000')260 dig_confirm = driver.switch_to.alert261 dig_confirm.accept()262 driver.find_element_by_id('x1').clear()263 driver.find_element_by_id('x1').send_keys('13086618316')264 driver.find_element_by_id('pwd').clear()265 driver.find_element_by_id('pwd').send_keys('123')266 driver.find_element_by_id('x2').click()267 driver.get("http://127.0.0.1:5000/list_all_user")268 a = "http://127.0.0.1:5000/list_all_user"269 b = driver.current_url270 assert a == b271 driver.quit()272273def test_logout():274 driver = webdriver.Chrome()275 driver.get('http://127.0.0.1:5000')276 dig_confirm = driver.switch_to.alert277 dig_confirm.accept()278 driver.find_element_by_id('x1').clear()279 driver.find_element_by_id('x1').send_keys('13086618316')280 driver.find_element_by_id('pwd').clear()281 driver.find_element_by_id('pwd').send_keys('123')282 driver.find_element_by_id('x2').click()283 driver.find_element_by_link_text("Logout").click()284 result = EC.alert_is_present()(driver)285 assert result != False286 driver.quit()
...
admin_test.py
Source:admin_test.py
...11def testLoginAdminPage():12 driver = webdriver.Firefox(executable_path="./geckodriver.exe")13 driver.get(f"{ADMIN_ENDPOINT}/login")14 time.sleep(2)15 elem = driver.find_element_by_id(id_="login-login")16 elem.send_keys("admin")17 time.sleep(2)18 elem = driver.find_element_by_id(id_="login-password")19 elem.send_keys("admin")20 time.sleep(2)21 elem = driver.find_element_by_id(id_="login-button-confirm")22 elem.click()23 time.sleep(5)24 driver.quit()25def testLogoutAdminPage():26 driver = webdriver.Firefox(executable_path="./geckodriver.exe")27 driver.get(f"{ADMIN_ENDPOINT}/login")28 elem = driver.find_element_by_id(id_="login-login")29 elem.send_keys("admin")30 elem = driver.find_element_by_id(id_="login-password")31 elem.send_keys("admin")32 time.sleep(2)33 elem = driver.find_element_by_id(id_="login-button-confirm")34 elem.click()35 time.sleep(2)36 elem = driver.find_element_by_id(id_="logout-button-confirm")37 elem.click()38 time.sleep(5)39 driver.quit()40def testAddStationPage():41 driver = webdriver.Firefox(executable_path="./geckodriver.exe")42 driver.get(f"{ADMIN_ENDPOINT}/login")43 elem = driver.find_element_by_id(id_="login-login")44 elem.send_keys("admin")45 elem = driver.find_element_by_id(id_="login-password")46 elem.send_keys("admin")47 elem = driver.find_element_by_id(id_="login-button-confirm")48 elem.click()49 time.sleep(1)50 elem = driver.find_element_by_id(id_="topbar-stations")51 elem.click()52 elem = driver.find_element_by_id(id_="stations-new")53 elem.click()54 elem = driver.find_element_by_id(id_="stations-add-name")55 elem.send_keys("Palisadowa")56 time.sleep(2)57 elem = driver.find_element_by_id(id_="stations-add-limit")58 elem.send_keys(20)59 time.sleep(2)60 elem = driver.find_element_by_id(id_="stations-add-confirm")61 elem.click()62 time.sleep(5)63 driver.quit()64def testRemoveStationPage():65 driver = webdriver.Firefox(executable_path="./geckodriver.exe")66 driver.get(f"{ADMIN_ENDPOINT}/login")67 elem = driver.find_element_by_id(id_="login-login")68 elem.send_keys("admin")69 elem = driver.find_element_by_id(id_="login-password")70 elem.send_keys("admin")71 elem = driver.find_element_by_id(id_="login-button-confirm")72 elem.click()73 time.sleep(1)74 elem = driver.find_element_by_id(id_="topbar-stations")75 elem.click()76 elem = driver.find_element_by_id(id_="stations-new")77 elem.click()78 elem = driver.find_element_by_id(id_="stations-add-name")79 elem.send_keys("Wola Park")80 time.sleep(1)81 elem = driver.find_element_by_id(id_="stations-add-limit")82 elem.send_keys(20)83 time.sleep(1)84 elem = driver.find_element_by_id(id_="stations-add-confirm")85 elem.click()86 time.sleep(3)87 elem = driver.find_element_by_id(id_="station-remove-0")88 elem.click()89 time.sleep(1)90 elem = driver.find_element_by_id(id_="station-remove-confirm")91 elem.click()92 driver.quit()93def testBlockStationPage():94 driver = webdriver.Firefox(executable_path="./geckodriver.exe")95 driver.get(f"{ADMIN_ENDPOINT}/login")96 elem = driver.find_element_by_id(id_="login-login")97 elem.send_keys("admin")98 elem = driver.find_element_by_id(id_="login-password")99 elem.send_keys("admin")100 time.sleep(1)101 elem = driver.find_element_by_id(id_="topbar-stations")102 elem.click()103 time.sleep(2)104 elem = driver.find_element_by_id(id_="stations-block-confirm-2")105 elem.click()106 time.sleep(1)107 elem = driver.find_element_by_id(id_="stations-block-confirm")108 elem.click()109 time.sleep(2)110 driver.quit()111def testUnblockStationPage():112 driver = webdriver.Firefox(executable_path="./geckodriver.exe")113 driver.get(f"{ADMIN_ENDPOINT}/login")114 elem = driver.find_element_by_id(id_="login-login")115 elem.send_keys("admin")116 elem = driver.find_element_by_id(id_="login-password")117 elem.send_keys("admin")118 time.sleep(1)119 elem = driver.find_element_by_id(id_="topbar-stations")120 elem.click()121 elem = driver.find_element_by_id(id_="stations-block-confirm-2")122 elem.click()123 elem = driver.find_element_by_id(id_="stations-switch-blocked")124 elem.click()125 time.sleep(2)126 elem = driver.find_element_by_id(id_="stations-unblock-confirm-0")127 elem.click()128 time.sleep(2)129 elem = driver.find_element_by_id(id_="stations-unblock-confirm")130 elem.click()131 driver.quit()132def testAddBikePage():133 driver = webdriver.Firefox(executable_path="./geckodriver.exe")134 driver.get(f"{ADMIN_ENDPOINT}/login")135 elem = driver.find_element_by_id(id_="login-login")136 elem.send_keys("admin")137 elem = driver.find_element_by_id(id_="login-password")138 elem.send_keys("admin")139 elem = driver.find_element_by_id(id_="login-button-confirm")140 elem.click()141 time.sleep(1)142 elem = driver.find_element_by_id(id_="topbar-bikes")143 elem.click()144 elem = driver.find_element_by_id(id_="bikes-new")145 elem.click()146 elem = driver.find_element_by_id(id_="stations-add-name")147 elem.send_keys("Palisadowa")148 time.sleep(2)149 elem = driver.find_element_by_id(id_="stations-add-limit")150 elem.send_keys(20)151 time.sleep(2)152 elem = driver.find_element_by_id(id_="stations-add-confirm")153 elem.click()154 time.sleep(5)155 driver.quit()156def testRemoveBikePage():157 driver = webdriver.Firefox(executable_path="./geckodriver.exe")158 driver.get(f"{ADMIN_ENDPOINT}/login")159 elem = driver.find_element_by_id(id_="login-login")160 elem.send_keys("admin")161 elem = driver.find_element_by_id(id_="login-password")162 elem.send_keys("admin")163 elem = driver.find_element_by_id(id_="login-button-confirm")164 elem.click()165 time.sleep(1)166 elem = driver.find_element_by_id(id_="topbar-bikes")167 elem.click()168 elem = driver.find_element_by_id(id_="bikes-new")169 elem.click()170 elem = driver.find_element_by_id(id_="bikes-add-station")171 stationListSelect = Select(driver.find_element_by_id(id_="select-return-bike-station"))172 stationListSelect.select_by_visible_text("Uniwersytet")173 elem.send_keys()174 time.sleep(1)175 elem = driver.find_element_by_id(id_="stations-add-limit")176 elem.send_keys(20)177 time.sleep(1)178 elem = driver.find_element_by_id(id_="stations-add-confirm")179 elem.click()180 time.sleep(3)181 elem = driver.find_element_by_id(id_="station-remove-0")182 elem.click()183 time.sleep(1)184 elem = driver.find_element_by_id(id_="station-remove-confirm")185 elem.click()186 driver.quit()187def testDetailStationPage():188 driver = webdriver.Firefox(executable_path="./geckodriver.exe")189 driver.get(f"{ADMIN_ENDPOINT}/login")190 elem = driver.find_element_by_id(id_="login-login")191 elem.send_keys("admin")192 elem = driver.find_element_by_id(id_="login-password")193 elem.send_keys("admin")194 time.sleep(1)195 elem = driver.find_element_by_id(id_="topbar-stations")196 elem.click()197 time.sleep(20)198 driver.quit()199def testDetailBikePage():200 driver = webdriver.Firefox(executable_path="./geckodriver.exe")201 driver.get(f"{ADMIN_ENDPOINT}/login")202 elem = driver.find_element_by_id(id_="login-login")203 elem.send_keys("admin")204 elem = driver.find_element_by_id(id_="login-password")205 elem.send_keys("admin")206 time.sleep(1)207 elem = driver.find_element_by_id(id_="topbar-stations")208 elem.click()209 time.sleep(20)210 driver.quit()211def testUserListPage():212 driver = webdriver.Firefox(executable_path="./geckodriver.exe")213 driver.get(f"{ADMIN_ENDPOINT}/login")214 elem = driver.find_element_by_id(id_="login-login")215 elem.send_keys("admin")216 elem = driver.find_element_by_id(id_="login-password")217 elem.send_keys("admin")218 time.sleep(1)219 elem = driver.find_element_by_id(id_="topbar-users")220 elem.click()221 time.sleep(20)222 driver.quit()223def testAddTechPage():224 driver = webdriver.Firefox(executable_path="./geckodriver.exe")225 driver.get(f"{ADMIN_ENDPOINT}/login")226 elem = driver.find_element_by_id(id_="login-login")227 elem.send_keys("admin")228 elem = driver.find_element_by_id(id_="login-password")229 elem.send_keys("admin")230 time.sleep(1)231 elem = driver.find_element_by_id(id_="topbar-users")232 elem.click()233 elem = driver.find_element_by_id(id_="users-add-tech")234 elem.click()235 time.sleep(2)236 elem = driver.find_element_by_id(id_="users-add-tech-login")237 elem.send_keys("tech")238 time.sleep(2)239 elem = driver.find_element_by_id(id_="users-add-tech-password")240 elem.send_keys("tech")241 time.sleep(1)242 elem = driver.find_element_by_id(id_="users-add-tech-confirm")243 elem.click()244 time.sleep(5)245 driver.quit()246 ADDED_TECH=True247def testRemoveTechPage():248 if not ADDED_TECH:249 testAddTechPage()250 driver = webdriver.Firefox(executable_path="./geckodriver.exe")251 driver.get(f"{ADMIN_ENDPOINT}/login")252 elem = driver.find_element_by_id(id_="login-login")253 elem.send_keys("admin")254 elem = driver.find_element_by_id(id_="login-password")255 elem.send_keys("admin")256 time.sleep(1)257 elem = driver.find_element_by_id(id_="topbar-users")258 elem.click()259 elem = driver.find_element_by_id(id_="users-remove-tech-1")260 elem.click()261 time.sleep(2)262 elem = driver.find_element_by_id(id_="users-remove-tech-confirm")263 elem.click()264 time.sleep(5)265 driver.quit()266def testBlockUserPage():267 driver = webdriver.Firefox(executable_path="./geckodriver.exe")268 driver.get(f"{ADMIN_ENDPOINT}/login")269 elem = driver.find_element_by_id(id_="login-login")270 elem.send_keys("admin")271 elem = driver.find_element_by_id(id_="login-password")272 elem.send_keys("admin")273 time.sleep(1)274 elem = driver.find_element_by_id(id_="topbar-users")275 elem.click()276 elem = driver.find_element_by_id(id_="users-block-confirm-0")277 elem.click()278 time.sleep(2)279 elem = driver.find_element_by_id(id_="users-block-confirm")280 elem.click()281 time.sleep(2)282 driver.quit()283def testUnblockUserPage():284 driver = webdriver.Firefox(executable_path="./geckodriver.exe")285 driver.get(f"{ADMIN_ENDPOINT}/login")286 elem = driver.find_element_by_id(id_="login-login")287 elem.send_keys("admin")288 elem = driver.find_element_by_id(id_="login-password")289 elem.send_keys("admin")290 time.sleep(1)291 elem = driver.find_element_by_id(id_="topbar-users")292 elem.click()293 elem = driver.find_element_by_id(id_="users-block-confirm-0")294 elem.click()295 elem = driver.find_element_by_id(id_="users-block-confirm")296 elem.click()297 elem = driver.find_element_by_id(id_="users-switch-blocked")298 elem.click()299 time.sleep(2)300 elem = driver.find_element_by_id(id_="users-unblock-confirm-0")301 elem.click()302 time.sleep(2)303 driver.quit()304def testAll():305 testLoginAdminPage()306 testLogoutAdminPage()307 testAddStationPage()308 testRemoveStationPage()309 testBlockStationPage()310 testUnblockStationPage()311 #testAddBikePage()312 #testRemoveBikePage()313 testDetailStationPage()314 testDetailBikePage()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!