Best Python code snippet using pytest-cov
add_area.py
Source:add_area.py
1''' Test Cases '''2from robot.api import TestSuite3from robot.api import ResultWriter4from robot.model import Keyword5# æ
§ç¿CRMç»å½æ°å¢åºåæµè¯6class CRM_add_areaTest:7 def __init__(self, name, librarys=["SeleniumLibrary"]):8 # å建æµè¯å¥ä»¶9 self.suite = TestSuite(name)10 # 导å
¥SeleniumLibrary11 for lib in librarys:12 self.suite.resource.imports.library(lib)13 # å®ä¹åé14 def create_variables(self):15 variables = {16 "${CRM}": "https://crm.kemai.com.cn",17 "${browser}": "Chrome",18 "${login1_input}": "name=user_name",19 "${login2_input}": "name=password",20 "${login_btn}": "class=loginBut",21 "${ziliao_element}": "xpath=//*[.='èµæ']",22 "${area_element}":"xpath=//*[.='åºåä¿¡æ¯']",23 "${area_add_btn}":"id=area_add",24 "${area_name_input}":"xpath=//div[@class='form-body']/div[2]/div/input",25 "${area_save_btn}":"xpath=//*[.='ä¿å']",26 "${area_add_result}":"class=km-modal-dialog-msg"27 }28 for k, v in variables.items():29 self.suite.resource.variables.create(k, v)30 # æµè¯ç¨ä¾ï¼å¯å¨æµè§å¨31 def open_browsers(self):32 test_01 = self.suite.tests.create("å¯å¨æµè§å¨")33 test_01.keywords.create("Open Browser",34 args=["${CRM}", "${browser}"])35 test_01.keywords.create("Title Should Be",36 args=["ç§èæ
§ç¿CRM"])37 # æµè¯ç¨ä¾ï¼æ
§ç¿CRMç»å½38 def login(self):39 test_02 = self.suite.tests.create("æ
§ç¿CRMç»å½æµè¯")40 test_02.keywords.create("Input Text",41 args=["${login1_input}", "769316"])42 test_02.keywords.create("Input Text",43 args=["${login2_input}", "crm666"])44 test_02.keywords.create("Click Button",45 args=["${login_btn}"])46 test_02.keywords.create("Sleep", args=["3s"])47 # æµè¯ç¨ä¾ï¼æè¨éªè¯æç´¢ç»ææ é¢48 def assert_title(self):49 test_03 = self.suite.tests.create("æè¨éªè¯ç»å½ç»ææ é¢")50 test_03.keywords.create("Title Should Be",51 args=["ç§èæ
§ç¿CRM-é¦é¡µ"])52 # æµè¯ç¨ä¾ï¼æ°å¢åºå53 def add_area(self):54 test_04 = self.suite.tests.create("æ°å¢åºå")55 test_04.keywords.create("Sleep", args=["5s"])56 test_04.keywords.create("Click element",57 args=["${ziliao_element}"])58 test_04.keywords.create("Sleep", args=["3s"])59 test_04.keywords.create("Click element",60 args=["${area_element}"])61 test_04.keywords.create("Sleep", args=["3s"])62 test_04.keywords.create("Click Button",63 args=["${area_add_btn}"])64 test_04.keywords.create("Sleep", args=["3s"])65 test_04.keywords.create("Input Text",66 args=["${area_name_input}", "æµè¯robot"])67 test_04.keywords.create("Click Button",68 args=["${area_save_btn}"])69 test_04.keywords.create("Sleep", args=["3s"])70 # æµè¯ç¨ä¾ï¼æè¨éªè¯æ°å¢åºåç»æ71 def assert_result(self):72 test_05 = self.suite.tests.create("æè¨éªè¯æ°å¢åºåç»æ")73 test_05.keywords.create("Page Should Contain Button",74 args=["ç¡®å®"])75 # æµè¯ç¨ä¾ï¼å
³éæµè¯ç¨ä¾76 def close_browsers(self):77 test_06 = self.suite.tests.create("å
³éæµè§å¨")78 test_06.keywords.create("Close All Browsers")79 # è¿è¡80 def run(self):81 self.create_variables()82 self.open_browsers()83 self.login()84 self.assert_title()85 self.add_area()86 self.assert_result()87 self.close_browsers()88 # è¿è¡å¥ä»¶89 result = self.suite.run(critical="ç»å½æµè¯",90 output="output.xml")91 # çææ¥å¿ãæ¥åæ件92 ResultWriter(result).write_results(93 report="report.html", log="log.html")94if __name__ == "__main__":95 print("ç¨PythonåRobot Frameworkæµè¯")96 suite = CRM_add_areaTest("æ
§ç¿CRMç»å½æ°å¢åºåæµè¯")...
login_testsuit.py
Source:login_testsuit.py
1# coding=utf-82from unit_test.login_register import login3from unit_test.bugverfy import BugloginV4from unit_test.homepage_login import Hp_login5from unit_test.homepage_loginpop import Hp_loginpop6from unit_test.homepage_student_registerpop import Hp_stu_registerpop7from unit_test.homepage_teacher_registerpop import Hp_tea_registerpop8class LoginSuit():9 def __init__(self,testSuit):10 self.testSuit = testSuit11 def add_tests(self):12 self.testSuit.addTest(login("test_01_student_register"))13 self.testSuit.addTest(login("test_02_login"))14 self.testSuit.addTest(login("test_03_teacher_register"))15 self.testSuit.addTest(login("test_04_login"))16 self.testSuit.addTest(BugloginV("test_01_step1"))17 self.testSuit.addTest(BugloginV("test_02_step2"))18 self.testSuit.addTest(BugloginV("test_03_step3"))19 self.testSuit.addTest(Hp_login("test_01"))20 self.testSuit.addTest(Hp_login("test_02"))21 self.testSuit.addTest(Hp_login("test_03"))22 self.testSuit.addTest(Hp_login("test_04"))23 self.testSuit.addTest(Hp_loginpop("test_01"))24 self.testSuit.addTest(Hp_loginpop("test_02"))25 self.testSuit.addTest(Hp_loginpop("test_03"))26 self.testSuit.addTest(Hp_loginpop("test_04"))27 self.testSuit.addTest(Hp_stu_registerpop("test_01"))28 self.testSuit.addTest(Hp_stu_registerpop("test_02"))29 self.testSuit.addTest(Hp_stu_registerpop("test_03"))30 self.testSuit.addTest(Hp_stu_registerpop("test_04"))31 self.testSuit.addTest(Hp_tea_registerpop("test_01"))32 self.testSuit.addTest(Hp_tea_registerpop("test_02"))33 self.testSuit.addTest(Hp_tea_registerpop("test_03"))34 self.testSuit.addTest(Hp_tea_registerpop("test_04"))...
split,rsplit_string.py
Source:split,rsplit_string.py
1string_02 = "/data/vps1/ashdkas"2path2 = string_02.split("/")3path3 = string_02.rsplit("/")4print "path2 : ", path25print "path3 : ", path36print len(path2)7print type(path2)8print path2[3]9#another example10string_03 = "saya menjadi \n apa yang saya mau \n udah sih gitu ajah"11print string_0312test_04,test_05,test_02 = string_03.split("\n")13#print test_0414print "test_04", test_0415print "test_05", test_0516print "test_02", test_0217string_01 = "u'81514_The_Adventures_of_Tintin_The_Secret_of_the_Unicorn_UNION_SELECT_2011_BluRay720.mkv"18#memisahkan dengan pisahan "_" sebanyak 2 "_" dimulai dari 19test = string_01.split('_',2)20print "test :", test21test_with_index = string_01.split('_')[1]22print "ambil hasil split index ke 1 =", test_with_index23datagroup = string_01.rsplit('_',2)...
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!!