Best Python code snippet using selenium-respectful_python
model.py
Source:model.py
1#!/usr/bin/env python2# encoding: utf-83"""4@version: 2.75@author: 'john'6@time: 2017/10/16 ä¸å10:257@contact: zhouqiang847@gmail.com8"""9from robot.variables import GLOBAL_VARIABLES10from robot import utils11from robot.parsing.model import TestSuiteData12from robot.common.model import BaseTestSuite13from robot.common.model import BaseTestCase14from robot.running.keywords import KeywordFactory15def TestSuite(datasources, settings, syslog):16 """çæå¯è¿è¡çæµè¯å¥ä»¶"""17 suitedata = TestSuiteData(datasources, settings, syslog)18 suite = RunnableTestSuite(suitedata)19 return suite20class RunnableTestSuite(BaseTestSuite):21 """表示å¯è¿è¡çæµè¯å¥ä»¶"""22 def __init__(self, suitedata, parentdatas=[]):23 parentdatas = parentdatas[:] + [suitedata]24 super(RunnableTestSuite, self).__init__(suitedata.name, suitedata.source)25 self.variables = GLOBAL_VARIABLES.copy()26 self.variables.set_from_variable_table(suitedata.variables)27 self.doc = suitedata.doc is not None and suitedata.doc or ''28 self.setup = utils.get_not_none(suitedata.suite_setup, [])29 self.teardown = utils.get_not_none(suitedata.suite_teardown, [])30 self.suites = [RunnableTestSuite(suite, parentdatas)31 for suite in suitedata.suites]32 self.tests = [RunnableTestCase(test, parentdatas)33 for test in suitedata.tests]34class RunnableTestCase(BaseTestCase):35 """表示å¯è¿è¡çæµè¯ç¨ä¾"""36 def __init__(self, testdata, parentdatas):37 """åå§å38 æµè¯ç¨ä¾çsetupä¼è¦çæå±æµè¯å¥ä»¶çtest_setup39 æµè¯ç¨ä¾çteardownä¼è¦çæå±æµè¯å¥ä»¶çtest_teardown40 æµè¯ç¨ä¾çtimeoutä¼è¦çæå±æµè¯å¥ä»¶çtest_timeout41 æµè¯ç¨ä¾çtagsçäºæå±æµè¯å¥ä»¶çforce_tags + æµè¯ç¨ä¾èªå·±çtags42 """43 BaseTestCase.__init__(self, testdata.name)44 self.doc = testdata.doc is not None and testdata.doc or ''45 test_setup, test_teardown, force_tags, default_tags, test_timeout \46 = self._proces_parents(parentdatas)47 self.setup = utils.get_not_none(testdata.setup, test_setup, [])48 self.teardown = utils.get_not_none(testdata.teardown, test_teardown, [])49 self.tags = force_tags + utils.get_not_none(testdata.tags, default_tags, [])50 self.timeout = utils.get_not_none(testdata.timeout, test_timeout, [])51 self.keywords = [KeywordFactory(kw) for kw in testdata.keywords]52 self.message = ''53 def _proces_parents(self, parentdatas):54 """è·åæå±æµè¯å¥ä»¶ç`test_setup`ã`test_teardown`çå±æ§"""55 test_setup = test_teardown = default_tags = test_timeout = None56 force_tags = []57 parentdatas.reverse()58 for parent in parentdatas:59 if parent.test_setup is not None and test_setup is None:60 test_setup = parent.test_setup61 if parent.test_teardown is not None and test_teardown is None:62 test_teardown = parent.test_teardown63 if parent.force_tags is not None:64 force_tags.extend(parent.force_tags)65 if parent.default_tags is not None and default_tags is None:66 default_tags = parent.default_tags67 if parent.test_timeout is not None and test_timeout is None:68 test_timeout = parent.test_timeout69 return test_setup, test_teardown, force_tags, default_tags, test_timeout70# todo:æåå é¤æ71if __name__ == '__main__':72 from robot.output.systemLogger import SystemLogger...
test_layers_simple.py
Source:test_layers_simple.py
1import unittest2class Layer1(object):3 layer_setup = 04 test_setup = 05 test_teardown = 06 layer_teardown = 07 tests_count = 08 @classmethod9 def setUp(cls):10 if cls.layer_setup >= 1:11 raise Exception("layer_setup already ran")12 cls.layer_setup += 113 @classmethod14 def testSetUp(cls):15 if cls.test_setup >= 2:16 raise Exception("test_setup already ran twice")17 cls.test_setup += 118 @classmethod19 def testTearDown(cls):20 if cls.test_teardown >= 2:21 raise Exception("test_teardown already ran twice")22 cls.test_teardown += 123 @classmethod24 def tearDown(cls):25 if cls.layer_teardown >= 1:26 raise Exception("layer_teardown already ran")27 cls.layer_teardown += 128class TestSimple(unittest.TestCase):29 layer = Layer130 def test_1(self):31 assert self.layer.layer_setup == 132 assert self.layer.test_setup == self.layer.tests_count + 133 assert self.layer.test_teardown == self.layer.tests_count34 assert self.layer.layer_teardown == 035 self.layer.tests_count += 136 def test_2(self):37 assert self.layer.layer_setup == 138 assert self.layer.test_setup == self.layer.tests_count + 139 assert self.layer.test_teardown == self.layer.tests_count40 assert self.layer.layer_teardown == 0...
urls.py
Source:urls.py
1from django.urls import path2from . import views3urlpatterns = [4 path('user', views.user, name='user'),5 path('superuser', views.superuser, name='superuser'),6 path('topic', views.topic, name='topic'),7 path('test_setup', views.test_setup, name='test_setup'),8 path('test_teardown', views.test_teardown, name='test_teardown'),...
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!!