We appreciate your visit to Implement a class LoginForm that simulates a login form commonly found on web pages The LoginForm must include the following public methods assume valid non. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!
Answer :
The implementation of the LoginForm class:
The LoginForm Class
class LoginForm:
def __init__(self, expectedUsername, expectedPassword):
self.expectedUsername = expectedUsername
self.expectedPassword = expectedPassword
self.username = None
self.password = None
self.logged_in = False
def input(self, text):
if self.username is None:
self.username = text
elif self.password is None:
self.password = text
def click(self, button):
if button == "Submit":
if self.username == self.expectedUsername and self.password == self.expectedPassword:
self.logged_in = True
else:
self.username = None
self.password = None
elif button == "Reset":
self.username = None
self.password = None
def isLoggedIn(self):
return self.logged_in
And here's the LoginFormTest class with the required test methods:
import unittest
class LoginFormTest(unittest.TestCase):
def testCorrectUsernameIncorrectPassword(self):
login = LoginForm("admin", "admin123")
login.input("admin")
login.input("wrongpassword")
login.click("Submit")
self.assertFalse(login.isLoggedIn())
def testIncorrectUsernameCorrectPassword(self):
login = LoginForm("admin", "admin123")
login.input("wrongusername")
login.input("admin123")
login.click("Submit")
self.assertFalse(login.isLoggedIn())
def testCorrectCredentialsFirstTry(self):
login = LoginForm("admin", "admin123")
login.input("admin")
login.input("admin123")
login.click("Submit")
self.assertTrue(login.isLoggedIn())
def testIncorrectFirstCorrectSecond(self):
login = LoginForm("admin", "admin123")
login.input("wrongusername")
login.input("wrongpassword")
login.click("Submit")
login.input("admin")
login.input("admin123")
login.click("Submit")
self.assertTrue(login.isLoggedIn())
def testCorrectFirstIncorrectSecond(self):
login = LoginForm("admin", "admin123")
login.input("admin")
login.input("admin123")
login.click("Submit")
login.input("wrongusername")
login.input("wrongpassword")
login.click("Submit")
self.assertTrue(login.isLoggedIn())
if __name__ == '__main__':
unittest.main()
This code snippet furnishes the LoginForm class with necessary functions and imparts the defined test methods to the LoginFormTest class through the integration of the unittest framework.
Read more about login forms here:
https://brainly.com/question/10639375
#SPJ4
Thanks for taking the time to read Implement a class LoginForm that simulates a login form commonly found on web pages The LoginForm must include the following public methods assume valid non. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!
- Why do Businesses Exist Why does Starbucks Exist What Service does Starbucks Provide Really what is their product.
- The pattern of numbers below is an arithmetic sequence tex 14 24 34 44 54 ldots tex Which statement describes the recursive function used to..
- Morgan felt the need to streamline Edison Electric What changes did Morgan make.
Rewritten by : Barada