Best Python code snippet using SeleniumBase
core_test.py
Source:core_test.py
...46 """47 # Test default algorithm48 # {Algorithm: "", Period: 30, UnixTime: 20000000000, Secret: "12345678901234567890", Digits: 8}, Output: "65353130"}49 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=&digits=8&period=30&counter=20000000000'50 totp = get_totp_code(url)51 self.assertEqual(totp.code, '65353130') # using default algorithm SHA152 # Test default digits53 # { Algorithm: "SHA1", Period: 30, UnixTime: 20000000000, Secret: "12345678901234567890", Digits: 0}, Output: "353130"}54 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=0&period=30&counter=20000000000'55 totp = get_totp_code(url)56 self.assertEqual(totp.code, '353130') # using default digits = 657 # Test default period58 # {Algorithm: "SHA1", Period: 0, UnixTime: 20000000000, Secret: "12345678901234567890", Digits: 8}, Output: "65353130"}59 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=8&period=0&counter=20000000000'60 totp = get_totp_code(url)61 self.assertEqual(totp.code, '65353130') # using default period = 3062 # Test empty secret63 # {Algorithm: "SHA1", Period: 30, UnixTime: 0, Secret: "", Digits: 8}, Output: "no secret key provided"}64 url = 'otpauth://totp/ACME:john.doe@email.com?secret=&issuer=ACME&algorithm=SHA1&digits=8&period=30'65 try:66 totp = get_totp_code(url)67 except ValueError as err:68 self.assertEqual(str(err), 'TOTP secret not found in URI')69 # Test invalid algorithm70 # { Algorithm: "SHA1024", Period: 30, UnixTime: 0, Secret: "12345678901234567890", Digits: 8}, Output: "invalid algorithm - use one of SHA1/SHA256/SHA512"}71 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1024&digits=8&period=30'72 try:73 totp = get_totp_code(url)74 except ValueError as err:75 self.assertRegex(str(err), r'Invalid value "[^"]*" for TOTP algorithm, must be SHA1, SHA256 or SHA512', 'did not get correct error message')76 # Test invalid secret77 # { Algorithm: "SHA1", Period: 30, UnixTime: 0, Secret: "1NVAL1D", Digits: 8}, Output: "bad secret key"}78 url = 'otpauth://totp/ACME:john.doe@email.com?secret=1NVAL1D&issuer=ACME&algorithm=SHA1&digits=8&period=30'79 try:80 totp = get_totp_code(url)81 except ValueError as err:82 self.assertEqual(str(err), 'Non-base32 digit found')83 # Check seconds left84 # {Algorithm: "SHA1", Period: 30, UnixTime: 59, Secret: "12345678901234567890", Digits: 8}, Output: "94287082"}85 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=8&period=30&counter=59'86 totp = get_totp_code(url)87 self.assertEqual("94287082", totp.code)88 self.assertEqual(1, totp.time_left)89 # {Algorithm: "SHA256", Period: 30, UnixTime: 59, Secret: "12345678901234567890123456789012", Digits: 8}, Output: "46119246"}90 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA&issuer=ACME&algorithm=SHA256&digits=8&period=30&counter=59'91 totp = get_totp_code(url)92 self.assertEqual("46119246", totp.code)93 self.assertEqual(1, totp.time_left)94 # {Algorithm: "SHA512", Period: 30, UnixTime: 59, Secret: "1234567890123456789012345678901234567890123456789012345678901234", Digits: 8}, Output: "90693936"}95 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA=&issuer=ACME&algorithm=SHA512&digits=8&period=30&counter=59'96 totp = get_totp_code(url)97 self.assertEqual("90693936", totp.code)98 self.assertEqual(1, totp.time_left)99 # Check different periods - 1 sec. before split100 # {Algorithm: "SHA1", Period: 30, UnixTime: 1111111109, Secret: "12345678901234567890", Digits: 8}, Output: "07081804"}101 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=8&period=30&counter=1111111109'102 totp = get_totp_code(url)103 self.assertEqual("07081804", totp.code)104 # {Algorithm: "SHA256", Period: 30, UnixTime: 1111111109, Secret: "12345678901234567890123456789012", Digits: 8}, Output: "68084774"}105 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA&issuer=ACME&algorithm=SHA256&digits=8&period=30&counter=1111111109'106 totp = get_totp_code(url)107 self.assertEqual("68084774", totp.code)108 # {Algorithm: "SHA512", Period: 30, UnixTime: 1111111109, Secret: "1234567890123456789012345678901234567890123456789012345678901234", Digits: 8}, Output: "25091201"}109 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA=&issuer=ACME&algorithm=SHA512&digits=8&period=30&counter=1111111109'110 totp = get_totp_code(url)111 self.assertEqual("25091201", totp.code)112 # Check different periods - 1 sec. after split113 # {Algorithm: "SHA1", Period: 30, UnixTime: 1111111111, Secret: "12345678901234567890", Digits: 8}, Output: "14050471"}114 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=8&period=30&counter=1111111111'115 totp = get_totp_code(url)116 self.assertEqual("14050471", totp.code)117 # {Algorithm: "SHA256", Period: 30, UnixTime: 1111111111, Secret: "12345678901234567890123456789012", Digits: 8}, Output: "67062674"}118 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA&issuer=ACME&algorithm=SHA256&digits=8&period=30&counter=1111111111'119 totp = get_totp_code(url)120 self.assertEqual("67062674", totp.code)121 # {Algorithm: "SHA512", Period: 30, UnixTime: 1111111111, Secret: "1234567890123456789012345678901234567890123456789012345678901234", Digits: 8}, Output: "99943326"}122 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA=&issuer=ACME&algorithm=SHA512&digits=8&period=30&counter=1111111111'123 totp = get_totp_code(url)124 self.assertEqual("99943326", totp.code)125 # Check different time periods126 # {Algorithm: "SHA1", Period: 30, UnixTime: 1234567890, Secret: "12345678901234567890", Digits: 8}, Output: "89005924"}127 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=8&period=30&counter=1234567890'128 totp = get_totp_code(url)129 self.assertEqual("89005924", totp.code)130 # {Algorithm: "SHA256", Period: 30, UnixTime: 1234567890, Secret: "12345678901234567890123456789012", Digits: 8}, Output: "91819424"}131 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA&issuer=ACME&algorithm=SHA256&digits=8&period=30&counter=1234567890'132 totp = get_totp_code(url)133 self.assertEqual("91819424", totp.code)134 # {Algorithm: "SHA512", Period: 30, UnixTime: 1234567890, Secret: "1234567890123456789012345678901234567890123456789012345678901234", Digits: 8}, Output: "93441116"}135 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA=&issuer=ACME&algorithm=SHA512&digits=8&period=30&counter=1234567890'136 totp = get_totp_code(url)137 self.assertEqual("93441116", totp.code)138 # {Algorithm: "SHA1", Period: 30, UnixTime: 2000000000, Secret: "12345678901234567890", Digits: 8}, Output: "69279037"}139 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=8&period=30&counter=2000000000'140 totp = get_totp_code(url)141 self.assertEqual("69279037", totp.code)142 # {Algorithm: "SHA256", Period: 30, UnixTime: 2000000000, Secret: "12345678901234567890123456789012", Digits: 8}, Output: "90698825"}143 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA&issuer=ACME&algorithm=SHA256&digits=8&period=30&counter=2000000000'144 totp = get_totp_code(url)145 self.assertEqual("90698825", totp.code)146 # {Algorithm: "SHA512", Period: 30, UnixTime: 2000000000, Secret: "1234567890123456789012345678901234567890123456789012345678901234", Digits: 8}, Output: "38618901"}147 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA=&issuer=ACME&algorithm=SHA512&digits=8&period=30&counter=2000000000'148 totp = get_totp_code(url)149 self.assertEqual("38618901", totp.code)150 # {Algorithm: "SHA1", Period: 30, UnixTime: 20000000000, Secret: "12345678901234567890", Digits: 8}, Output: "65353130"}151 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=ACME&algorithm=SHA1&digits=8&period=30&counter=20000000000'152 totp = get_totp_code(url)153 self.assertEqual("65353130", totp.code)154 # {Algorithm: "SHA256", Period: 30, UnixTime: 20000000000, Secret: "12345678901234567890123456789012", Digits: 8}, Output: "77737706"}155 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA&issuer=ACME&algorithm=SHA256&digits=8&period=30&counter=20000000000'156 totp = get_totp_code(url)157 self.assertEqual("77737706", totp.code)158 # {Algorithm: "SHA512", Period: 30, UnixTime: 20000000000, Secret: "1234567890123456789012345678901234567890123456789012345678901234", Digits: 8}, Output: "47863826"}159 url = 'otpauth://totp/ACME:john.doe@email.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA=&issuer=ACME&algorithm=SHA512&digits=8&period=30&counter=20000000000'160 totp = get_totp_code(url)...
get_changes.py
Source:get_changes.py
...8load_dotenv()9url = "https://kosenjp.sharepoint.com/sites/002967/Lists/List2/view.aspx?FilterField1=%5Fx30af%5F%5Fx30e9%5F%5Fx30b9%5F&FilterValue1=4%2D5"10mail = os.environ["MAIL"]11password = os.environ["pass"]12totp_code = get_totp_code()13async def get_change():14 browser = await launch(headless=False)15 try:16 page = await browser.newPage()17 file_path = './' # file storage path, but also to detect whether the download is successful, it is recommended to download a unique path to prevent conflict18 # ãã¼ã¸ã¢ã¯ã»ã¹19 await page.goto(url, waitUntil='networkidle0')20 # mailå
¥å21 await page.type('#i0116', mail)22 await page.waitFor(2000)23 await page.click('#idSIButton9')24 # await page.click('#idSIButton')25 # passå
¥å26 await page.type('#i0118', password)27 await page.waitFor(2000)28 await page.click('#idSIButton9')29 await page.waitFor(2000)30 # now = datetime.datetime.now()31 # await print(now.time()) # 09:55:2832 # await print("num", totp_code, now, get_totp_code())33 # TOTPã³ã¼ãå
¥å34 await page.type('#idTxtBx_SAOTCC_OTC', get_totp_code())35 await page.click('#idSubmit_SAOTCC_Continue')36 await page.waitFor(2000)37 await page.click('#idBtn_Back')38 await page.waitFor(3000)39 cdp = await page.target.createCDPSession()40 await cdp.send('Page.setDownloadBehavior', {41 'behavior': 'allow',42 'downloadPath': file_path43 }) # Set download path44 # csvãã¦ã³ãã¼ã45 await page.click('button[name="CSV ã«ã¨ã¯ã¹ãã¼ã"]')46 await page.waitFor(3000)47 print("success!!!!")48 except:...
gen_htop_code.py
Source:gen_htop_code.py
1import pyotp2import os3from dotenv import load_dotenv4load_dotenv()5def get_totp_code():6 totp_secret = os.environ["TOTP_SECRET"]7 totp = pyotp.TOTP(totp_secret)8 totp_now = totp.now()9 return totp_now10if __name__ == "__main__":...
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!!