Best Python code snippet using fMBT_python
scenarios.py
Source:scenarios.py
...9def scenario3():10 seq = 5511 sender = Sender(useTracking=True, isVerbose=1);12 sender.sendReset()13 sender.sendInput("SA", seq, 1) #SA svar seq+1 | SYN_REC14 sender.sendInput("S", seq + 1, seqVar + 1) #A svar+1 seq+2 | CLOSE_WAIT15# S 55 116# SA 3000004891 5617# FA 56 300000489218# A 3000004892 5719# SA 57 300000489320# timeout21# S 57 300000489322# SA 3002936060 5823def scenario1():24 seq = 5525 global isVerbose, seqVar26 isVerbose = 127 sender = Sender(useTracking=True, isVerbose=1);28 sender.sendReset()29 sender.sendInput("S", seq, 1) #SA svar seq+1 | SYN_REC30 sender.sendInput("FA", seq + 1, seqVar + 1) #A svar+1 seq+2 | CLOSE_WAIT31 sender.sendInput("SA", seq + 2, seqVar + 2) # [AUS] RST svar+2 | CLOSED32# S 55 133# SA 3228886825 5634# FA 56 322888682635# A 3228886826 5736# A 57 322888682737# SA 3307790927 5638def scenario2():39 seq = 5540 global seqVar41 sender = Sender(useTracking=True, isVerbose=1);42 sender.sendReset()43 sender.sendInput("S", seq, 1) #SA svar seq+1 | SYN_REC44 sender.sendInput("FA", seq + 1, seqVar + 1) #A svar+1 seq+2 | CLOSE_WAIT45 sender.sendInput("A", seq + 2, seqVar + 1) # [AUS] RST svar+2 | CLOSED46# target SYN+ACK(V,V)/timeout transition47def scenario4():48 seq = 5549 global seqVar50 sender = Sender(useTracking=False, isVerbose=1);51 sender.sendReset()52 sender.sendInput("S", seq, 1) #SA svar seq+1 | SYN_REC53 sender.sendInput("SA", seq + 1, seqVar + 1) #A svar+1 seq+2 | CLOSE_WAIT54#S 256873882 232571192655#SA 2359696765 25687388356#S 0 235969676657#SA 2359696765 25687388358# target SYN+ACK(V,V)/timeout transition59def scenario5():60 seq = 25687388261 global seqVar62 sender = Sender(useTracking=True, isVerbose=1);63 sender.sendReset()64 sender.sendInput("S", seq, 1) #SA svar seq+1 | SYN_REC65 sender.sendInput("S", 0, 30) #A svar+1 seq+2 | CLOSE_WAIT66# it believes SYN/ACK wasn't received, so decides to retransmit it.67# second SYN with INV INV always leads to re-transmission68# S 2195024002 402705066369# SA 2012154486 219502400370# R 896739962 300612513371# timeout72# SA 1907624083 154737181073# timeout74# FA 2804750325 351744070375# timeout76# F 3509051224 40454383777# A 2012154487 219502400378# R 207753863 347085050179# timeout80# R 1912718391 354772487881# timeout82# FA 1111900754 80996032383# timeout84# SA 2370638902 112097300085# timeout86# A 3519400106 129173807287# timeout88# SA 2682686870 8188867689# timeout90# F 2375991952 44707620991# A 2012154487 219502400392# FA 2195024003 201215448893# SA 2012154486 219502400394def scenario6():95 seq = 25687388296 global seqVar97 sender = Sender(useTracking=True, isVerbose=1);98 sender.sendReset()99 sender.sendInput("S", seq, 1)100 sender.sendInput("RA", seq + 1, 334)101 #sender.sendInput("SA", )102# S 4182706173 2198067953103# A 1324802308 4092203593104# A 0 1324802309105# A 1324802308 4092203593106def scenario7():107 seq = 4182706173108 global seqVar109 sender = Sender(useTracking=True, isVerbose=1)110 sender.sendReset()111 print(sender.sendInput("S", seq, 2198067953).ack)112 #sender.sendInput("A", seq + 1, 334)113def scenario8():114 seq = 4294967295115 global seqVar116 sender = Sender(useTracking=True, isVerbose=1)117 sender.sendReset()118 sender.sendInput("S", seq, 0)119# S 341566692 277277600120# SA 2738973448 341566693121# R 764295758 2738973449122# timeout123# S 1218267894 1420096704124# SA 2738973448 341566693125def scenario9():126 seq = 1200;127 global seqVar128 sender = Sender(useTracking=True, isVerbose=1)129 sender.sendReset()130 sender.sendInput("S", seq, 0);131 sender.sendInput("R", seq+1, seqVar+1);132 sender.sendInput("S", seq-100, 9090);133# S 1923506209 1980570823134# SA 3975181246 1923506210135# F 2536736535 3518618248136# A 3975181247 1923506210137def scenario10():138 seq = 120034;139 global seqVar140 sender = Sender(useTracking=True, isVerbose=1)141 sender.sendReset()142 sender.sendInput("S", seq, 10)143 sender.sendInput("F", seq+100, seqVar+100)144 sender.sendReset()145 sender.sendInput("S", seq, 10)146 sender.sendInput("F", seq+100, seqVar+100)147 sender.sendReset()148 sender.sendInput("S", seq, 10)149 sender.sendInput("F", seq+100, seqVar+100)150 sender.sendReset()151 sender.sendInput("S", seq, 10)152 sender.sendInput("F", seq+100, seqVar+100)153 sender.sendReset()154 sender.sendInput("S", seq, 10)155 sender.sendInput("F", seq+100, seqVar+100)156 sender.sendReset()157 sender.sendInput("S", seq, 10)158 sender.sendInput("F", seq+100, seqVar+100)159 sender.sendReset()160 sender.sendInput("S", seq, 10)161 sender.sendInput("F", seq+100, seqVar+100)162 sender.sendReset()163 sender.sendInput("S", seq, 10)164 sender.sendInput("F", seq+100, seqVar+100)165# =========Trace 150=========166# S 637250740 2233230871167# SA 1797254657 637250741168# F 3711991173 1797254658169# A 1797254658 637250741170# S 637250741 1797254659171# RA 0 637250742172# S 2783591730 403749488173# SA 1797267031 2783591731174#175#176# SYN(V,V)177# SYN+ACK(V,V)178# FIN(INV,V)179# ACK(V,V)180# SYN(V,V)181# RST+ACK(V,V)182# SYN(V,V)183# SYN+ACK(V,V)184#185# =========Trace 151=========186# S 2036987655 3265500663187# SA 4266394843 2036987656188# F 2240251580 4266394844189# A 4266394844 2036987656190# A 2036987656 4266394845191# R 4266394845 4266394845192#193#194# SYN(V,V)195# SYN+ACK(V,V)196# FIN(INV,V)197# ACK(V,V)198# ACK(V,V)199# RST(V,V)200#201# S 2616307222 10202# SA 1480899272 2616307223203# F 2616307322 1480899273204# timeout205# A 2616307223 1480899273206# timeout207# S 2616307122 1480899172208# A 1480899273 2616307223209# =========Trace 152=========210# S 3765233380 3045359813211# SA 3383820359 3765233381212# F 2361382207 3383820360213# A 3383820360 3765233381214# A 3765233381 3383820361215# R 3383820361 3383820361216# S 2976589857 1620152520217# SA 3383820359 3765233381218#219#220# SYN(V,V)221# SYN+ACK(V,V)222# FIN(INV,V)223# ACK(V,V)224# ACK(V,V)225# RST(V,V)226# SYN(V,V)227# SYN+ACK(V,INV)228def scenario101():229 global seqVar230 sender = Sender(useTracking=True, isVerbose=1, networkPortMinimum=20000)231 random.seed(10)232 for i in range(1,400):233 seq = random.randrange(0,1000000)234 sender.sendReset()235 sender.sendInput("S", seq, 10000)236 sender.sendInput("F", seq+100, seqVar+1)237 sender.sendInput("A", seq+1, seqVar+1)238 sender.sendInput("S", seq-100, seqVar-100)...
hotkeys.py
Source:hotkeys.py
1def returnkeylistdown():2 keylistdown = []3 keylistdown.append(['SendInput {. down}'])4 keylistdown.append(['SendInput {a DOWN}{. down}'])5 keylistdown.append(['SendInput {a DOWN}{w DOWN}{. down}'])6 keylistdown.append(['SendInput {w DOWN}{. down}'])7 keylistdown.append(['SendInput {w DOWN}{d DOWN}{. down}'])8 keylistdown.append(['SendInput {d DOWN}{. down}'])9 keylistdown.append(['SendInput {d DOWN}{s DOWN}{. down}'])10 keylistdown.append(['SendInput {s DOWN}{. down}'])11 keylistdown.append(['SendInput {s DOWN}{a DOWN}{. down}'])1213 keylistdown.append(['SendInput {u DOWN}{. down}']) #rolls, 'u'14 keylistdown.append(['SendInput {a DOWN}{u DOWN}{. down}'])15 keylistdown.append(['SendInput {a DOWN}{w DOWN}{u DOWN}{. down}'])16 keylistdown.append(['SendInput {w DOWN}{u DOWN}{. down}'])17 keylistdown.append(['SendInput {w DOWN}{d DOWN}{u DOWN}{. down}'])18 keylistdown.append(['SendInput {d DOWN}{u DOWN}{. down}'])19 keylistdown.append(['SendInput {d DOWN}{s DOWN}{u DOWN}{. down}'])20 keylistdown.append(['SendInput {s DOWN}{u DOWN}{. down}'])21 keylistdown.append(['SendInput {s DOWN}{a DOWN}{u DOWN}{. down}'])222324 keylistdown.append(['SendInput {p DOWN}{. down}']) #running/charging, 'p' char25 keylistdown.append(['SendInput {a DOWN}{p DOWN}{. down}'])26 keylistdown.append(['SendInput {a DOWN}{w DOWN}{p DOWN}{. down}'])27 keylistdown.append(['SendInput {w DOWN}{p DOWN}{. down}'])28 keylistdown.append(['SendInput {w DOWN}{d DOWN}{p DOWN}{. down}'])29 keylistdown.append(['SendInput {d DOWN}{p DOWN}{. down}'])30 keylistdown.append(['SendInput {d DOWN}{s DOWN}{p DOWN}{. down}'])31 keylistdown.append(['SendInput {s DOWN}{p DOWN}{. down}'])32 keylistdown.append(['SendInput {s DOWN}{a DOWN}{p DOWN}{. down}'])3334 keylistdown.append(['SendInput {j DOWN}{. down}']) #hits, 'k' char35 keylistdown.append(['SendInput {a DOWN}{j DOWN}{. down}'])36 keylistdown.append(['SendInput {a DOWN}{w DOWN}{j DOWN}{. down}'])37 keylistdown.append(['SendInput {w DOWN}{j DOWN}{. down}'])38 keylistdown.append(['SendInput {w DOWN}{d DOWN}{j DOWN}{. down}'])39 keylistdown.append(['SendInput {d DOWN}{j DOWN}{. down}'])40 keylistdown.append(['SendInput {d DOWN}{s DOWN}{j DOWN}{. down}'])41 keylistdown.append(['SendInput {s DOWN}{j DOWN}{. down}'])42 keylistdown.append(['SendInput {s DOWN}{a DOWN}{j DOWN}{. down}'])434445 keylistdown.append(['SendInput {i DOWN}{. down}']) #sheathes, 'i' char, reduced amount.46 '''47 keylistdown.append(['SendInput {w DOWN}{i DOWN}{. down}'])48 keylistdown.append(['SendInput {d DOWN}{i DOWN}{. down}'])49 keylistdown.append(['SendInput {s DOWN}{i DOWN}{. down}'])50 '''5152 keylistdown.append(['SendInput {p DOWN}{j DOWN}{k DOWN}{. down}']) #r x y ,'p' 'j' 'k' char53 '''54 keylistdown.append(['SendInput {a DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])55 keylistdown.append(['SendInput {a DOWN}{w DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])56 keylistdown.append(['SendInput {w DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])57 keylistdown.append(['SendInput {w DOWN}{d DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])58 keylistdown.append(['SendInput {d DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])59 keylistdown.append(['SendInput {d DOWN}{s DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])60 keylistdown.append(['SendInput {s DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])61 keylistdown.append(['SendInput {s DOWN}{a DOWN}{p DOWN}{j DOWN}{k DOWN}{. down}'])62 '''63 return keylistdown64def returnkeylistup():65#####KEYLISTup6667 keylistup = []68 keylistup.append(['SendInput{. up}'])69 keylistup.append(['SendInput {a UP}{. up}'])70 keylistup.append(['SendInput {a UP}{w UP}{. up}'])71 keylistup.append(['SendInput {w UP}{. up}'])72 keylistup.append(['SendInput {w UP}{d UP}{. up}'])73 keylistup.append(['SendInput {d UP}{. up}'])74 keylistup.append(['SendInput {d UP}{s UP}{. up}'])75 keylistup.append(['SendInput {s UP}{. up}'])76 keylistup.append(['SendInput {s UP}{a UP}{. up}'])7778 keylistup.append(['SendInput {u UP}{. up}']) #rolls, 'u'79 keylistup.append(['SendInput {a UP}{u UP}{. up}'])80 keylistup.append(['SendInput {a UP}{w UP}{u UP}{. up}'])81 keylistup.append(['SendInput {w UP}{u UP}{. up}'])82 keylistup.append(['SendInput {w UP}{d UP}{u UP}{. up}'])83 keylistup.append(['SendInput {d UP}{u UP}{. up}'])84 keylistup.append(['SendInput {d UP}{s UP}{u UP}{. up}'])85 keylistup.append(['SendInput {s UP}{u UP}{. up}'])86 keylistup.append(['SendInput {s UP}{a UP}{u UP}{. up}'])878889 keylistup.append(['SendInput {p UP}{. up}']) #running/charging, 'p' char90 keylistup.append(['SendInput {a UP}{p UP}{. up}'])91 keylistup.append(['SendInput {a UP}{w UP}{p UP}{. up}'])92 keylistup.append(['SendInput {w UP}{p UP}{. up}'])93 keylistup.append(['SendInput {w UP}{d UP}{p UP}{. up}'])94 keylistup.append(['SendInput {d UP}{p UP}{. up}'])95 keylistup.append(['SendInput {d UP}{s UP}{p UP}{. up}'])96 keylistup.append(['SendInput {s UP}{p UP}{. up}'])97 keylistup.append(['SendInput {s UP}{a UP}{p UP}{. up}'])9899 keylistup.append(['SendInput {j UP}{. up}']) #hits, 'k' char100 keylistup.append(['SendInput {a UP}{j UP}{. up}'])101 keylistup.append(['SendInput {a UP}{w UP}{j UP}{. up}'])102 keylistup.append(['SendInput {w UP}{j UP}{. up}'])103 keylistup.append(['SendInput {w UP}{d UP}{j UP}{. up}'])104 keylistup.append(['SendInput {d UP}{j UP}{. up}'])105 keylistup.append(['SendInput {d UP}{s UP}{j UP}{. up}'])106 keylistup.append(['SendInput {s UP}{j UP}{. up}'])107 keylistup.append(['SendInput {s UP}{a UP}{j UP}{. up}'])108109110 keylistup.append(['SendInput {i UP}{. up}']) #sheathes, 'i' char, reduced amount.111 keylistup.append(['SendInput {p UP}{j UP}{k UP}{. up}']) #r x y ,'p' 'j' 'k' char
...
test_ps1.py
Source:test_ps1.py
...9 print("found\n")10def promptUser():11 if (raw_input("Type q to quit, any other key to continue... ") is 'q'):12 sys.exit()13def sendInput(inputstring):14 print('\n----------')15 print("For input\n\n%s\n" % inputstring)16 print("your program output is\n")17 val = os.system("echo '%s' | ./a.out" % inputstring)18 print('----------\n')19def test_N():20 print("\n*********************")21 print("*** TESTING N.cpp ***")22 print("*********************\n")23 checkForFile('N.cpp')24 print("Compiling and running N.cpp... ")25 if (os.system("c++ N.cpp") != 0):26 print("\n!!! TEST FAILED !!!\n")27 sys.exit()28 sendInput('10')29 promptUser()30 sendInput('-2')31def test_vsum():32 print("\n************************")33 print("*** TESTING vsum.cpp ***")34 print("************************\n")35 checkForFile('vsum.cpp')36 print("Compiling and running vsum.cpp... ")37 if (os.system("c++ vsum.cpp") != 0):38 print("\n!!! TEST FAILED !!!\n")39 sys.exit()40 inputstring = \41"""AMATH 583 VECTOR426430.444-1.3452.141463.14159474.048549THIS IS THE END"""50 sendInput(inputstring)51 promptUser()52 inputstring = \53"""INCORRECT HEADER546550.456-1.3572.141583.14159594.060561THIS IS THE END"""62 sendInput(inputstring)63 promptUser()64 inputstring = \65"""AMATH 583 VECTOR666670.468-1.3692.141703.14159714.072573INCORRECT TRAILER"""74 sendInput(inputstring)75def test_vector():76 print("\n***************************")77 print("*** TESTING vector.cpp ***")78 print("***************************\n")79 checkForFile('vector.cpp')80 print("Creating vector_driver.cpp... ")81 codestring = \82"""#include <iostream>83#include <vector>84std::vector<double> readVector();85int main()86{87 double sum;88 std::vector<double> double_vector = readVector();89 sum = 0.0;90 for (std::vector<double>::iterator vals = double_vector.begin();91 vals != double_vector.end(); vals++)92 sum += *vals;93 std::cout << sum << std::endl;94 return 0;95}"""96 if (os.system("echo '%s' > vector_driver.cpp" % codestring) != 0):97 print("\n!!! TEST FAILED !!!\n")98 sys.exit()99 print("\nCompiling and running vector_driver.cpp and vector.cpp...",)100 if (os.system("c++ vector_driver.cpp vector.cpp") != 0):101 print("\n!!! TEST FAILED !!!\n")102 sys.exit()103 inputstring = \104"""AMATH 583 VECTOR10561060.4107-1.31082.1411093.141591104.01115112THIS IS THE END"""113 sendInput(inputstring)114 promptUser()115 inputstring = \116"""INCORRECT HEADER11761180.4119-1.31202.1411213.141591224.01235124THIS IS THE END"""125 sendInput(inputstring)126 promptUser()127 inputstring = \128"""AMATH 583 VECTOR12961300.4131-1.31322.1411333.141591344.01355136INCORRECT TRAILER"""137 sendInput(inputstring)138def test_vsum2():139 print("\n*************************")140 print("*** TESTING vsum2.cpp ***")141 print("*************************\n")142 checkForFile('vsum2.cpp')143 checkForFile('vector.cpp')144 print("Compiling and running vsum2.cpp and vector.cpp... ")145 if (os.system("c++ vsum2.cpp vector.cpp") != 0):146 print("\n!!! TEST FAILED !!!\n")147 sys.exit()148 inputstring = \149"""AMATH 583 VECTOR15061510.4152-1.31532.1411543.141591554.01565157THIS IS THE END"""158 sendInput(inputstring)159def test_written():160 print("\n************************")161 print("*** TESTING ex1.txt ***")162 print("************************\n")163 checkForFile('ex1.txt')164 print("Reading ex1.txt...\n")165 os.system("cat ex1.txt")166if __name__ == "__main__":167 # 483/583 Tests168 test_N()169 promptUser()170 test_vsum()171 promptUser()172 # 583 Tests...
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!!