Пример #1
0
class TestTBBaseStep(unittest.TestCase):
    def setUp(self):
        self.step_1 = TBBaseStep()
        self.step_2 = TBBaseStep()
        self.step_3 = TBBaseStep()

    def test_add_next_step(self):
        self.step_1.add_next_step(self.step_2)
        self.step_2.add_next_step(self.step_3)

        self.assertEqual(self.step_1.next_step, self.step_2,
                         "Step 2 does not follow step 1")
        self.assertEqual(self.step_2.next_step, self.step_3,
                         "Step 3 does not follow step 2")

    def test_add_next_step_wrong(self):
        with self.assertRaises(TypeError):
            self.step_1.add_next_step("Incorrect data")

    def test_is_last_step(self):
        self.step_1.add_next_step(self.step_2)
        self.assertTrue(self.step_2.is_last_step,
                        "Expected this step to be the last step")

    def test_is_first_step(self):
        self.step_1.add_next_step(self.step_2)
        self.assertTrue(self.step_1.is_first_step,
                        "Expected this step to be the first step")
Пример #2
0
    def setUp(self):
        self.step_1 = TBBaseStep()
        self.step_2 = TBBaseStep()

        self.step_1.add_next_step(self.step_2)

        self.test = TBBaseTest()
Пример #3
0
    def test_execute_step(self):
        self.test.load_interface(SampleInterface, "sample")

        step_1 = TBBaseStep(action="SampleAction")
        step_2 = TBBaseStep(action="SampleActionFail")

        step_1.add_next_step(step_2)

        c_x = StepContext(self.test)
        c_x.update_context(step_1, c_x)
        self.test.execute_step(c_x)  # No interface defined

        c_x = StepContext(self.test)
        c_x.update_context(step_1, c_x)
        c_x.action_interface = "sample"
        self.test.execute_step(c_x)  # Interface defined

        # Interface defined, but not installed
        with self.assertRaises(ImproperlyConfigured):
            c_x = StepContext(self.test)
            c_x.update_context(step_1, c_x)
            c_x.action_interface = "sample_fail"
            self.test.execute_step(c_x)

        # Action not defined
        with self.assertRaises(ImproperlyConfigured):
            c_x = StepContext(self.test)
            c_x.update_context(step_2, c_x)
            self.test.execute_step(c_x)
    def test_Exist(self):
        step_1 = TBBaseStep(action="Navigate",
                            argument_1="http://www.google.com")
        self.step_context.update_context(step_1, self.step_context)
        self.interface.Navigate(self.step_context)

        step_2 = TBBaseStep(action="Click", argument_1="Search")
        self.step_context.update_context(step_2, self.step_context)
        self.step_context.step_argument_1_mapped = "//input[@name='btnK']"

        self.interface.Exist(self.step_context)
    def test_LaunchDriver_Navigate_Chrome(self):
        step_1 = TBBaseStep(action="LaunchDriver", argument_1="Chrome")
        step_2 = TBBaseStep(action="Navigate",
                            argument_1="http://www.google.com")

        self.step_context.update_context(step_1, self.step_context)

        self.interface.LaunchDriver(self.step_context)

        self.step_context.update_context(step_2, self.step_context)
        self.interface.Navigate(self.step_context)
    def test_Type(self):
        step_1 = TBBaseStep(action="Navigate",
                            argument_1="http://www.google.com")
        self.step_context.update_context(step_1, self.step_context)

        self.interface.Navigate(self.step_context)

        step_2 = TBBaseStep(action="Type", argument_2="Testing Search")
        self.step_context.update_context(step_2, self.step_context)
        self.step_context.step_argument_1_mapped = "//input[@name='q']"

        self.interface.Type(self.step_context)
Пример #7
0
    def test_run(self):
        step_1 = TBBaseStep(action="SampleAction")
        step_2 = TBBaseStep(action="SampleAction")
        step_1.add_next_step(step_2)

        self.test.run_test = True
        self.test.load_interface(SampleInterface, "basic")
        self.test.load_middleware(SampleMiddleware)
        self.test.load_steps(step_1)
        self.test.load_tear_down_steps(step_1)

        self.test.run()
Пример #8
0
    def test_run_fail(self):
        with self.assertRaises(ImproperlyConfigured):
            self.test.run()

        step_1 = TBBaseStep(action="SampleAction")
        step_2 = TBBaseStep(action="FailAction")
        step_1.add_next_step(step_2)

        self.test.run_test = True
        self.test.load_interface(SampleInterface, "basic")
        self.test.load_middleware(SampleMiddleware)
        self.test.load_steps(step_1)

        self.test.run()
Пример #9
0
    def test_middleware_before_step_one_argument(self):
        step = TBBaseStep(action="SampleAction", argument_1="sample_element")
        self.step_context.update_context(step, self.step_context)

        self.middleware.before_step(self.step_context)
        self.assertEqual(self.step_context.step_argument_1_mapped, "//sample")
        self.assertEqual(self.step_context.action_interface, "basic")
Пример #10
0
    def test_if_equal(self):
        step_1 = TBBaseStep(action="If", argument_1="A", argument_2="A")
        step_2 = TBBaseStep(action="")
        step_3 = TBBaseStep(action="EndIf")

        step_1.add_next_step(step_2)
        step_2.add_next_step(step_3)

        s_c = StepContext(self.test)
        s_c.update_context(step_1, s_c)

        self.interface.If(s_c)
        self.assertEqual(s_c.next_step, step_2)
    def test_Exist_fail(self):
        step_1 = TBBaseStep(
            action="Navigate",
            argument_1=
            "http://maxdesign.com.au/jobs/sample-accessibility/05-forms/attribute-disabled.html"
        )
        self.step_context.update_context(step_1, self.step_context)
        self.interface.Navigate(self.step_context)

        step_2 = TBBaseStep(action="Click", argument_1="Search")
        self.step_context.update_context(step_2, self.step_context)
        self.step_context.step_argument_1_mapped = "//button[@text()='five']"

        # Speed up test a bit
        self.interface.set_implicit_wait(0.1)

        with self.assertRaises(Exception):
            self.interface.Exist(self.step_context)
    def setUp(self):
        self.interface = SeleniumInterface()

        test = TBBaseTest()
        step_1 = TBBaseStep(action="LaunchDriver", argument_1="Chrome")
        self.step_context = StepContext(test)

        self.step_context.update_context(step_1, self.step_context)
        self.interface.LaunchDriver(self.step_context)
    def test_search_google(self):
        step_1 = TBBaseStep(action="Navigate",
                            argument_1="http://www.google.com")
        self.step_context.update_context(step_1, self.step_context)
        self.interface.Navigate(self.step_context)

        step_2 = TBBaseStep(action="Type", argument_2="Testing Search")
        self.step_context.update_context(step_2, self.step_context)
        self.step_context.step_argument_1_mapped = "//input[@name='q']"
        self.interface.Type(self.step_context)

        step_3 = TBBaseStep(action="Click", argument_1="Search")
        self.step_context.update_context(step_3, self.step_context)
        self.step_context.step_argument_1_mapped = "//input[@name='btnK']"

        self.interface.Click(self.step_context)

        self.assertIn("Testing Search", self.interface.driver.title)
Пример #14
0
    def test_nested_if_not_equal(self):
        step_1 = TBBaseStep(action="If", argument_1="A", argument_2="B")
        step_2 = TBBaseStep(action="If", argument_1="A", argument_2="A")
        step_3 = TBBaseStep(action="")
        step_4 = TBBaseStep(action="EndIf")  # Skip this EndIf
        step_5 = TBBaseStep(action="EndIf")  # Close on this EndIf

        step_1.add_next_step(step_2)
        step_2.add_next_step(step_3)
        step_3.add_next_step(step_4)
        step_4.add_next_step(step_5)

        s_c = StepContext(self.test)
        s_c.update_context(step_1, s_c)

        self.interface.If(s_c)
        self.assertEqual(step_2.status, StepStatus.SKIPPED)
        self.assertEqual(step_3.status, StepStatus.SKIPPED)
        self.assertEqual(step_4.status, StepStatus.SKIPPED)

        self.assertNotEqual(step_5.status, StepStatus.SKIPPED)
        self.assertEqual(s_c.next_step, step_5)
Пример #15
0
 def setUp(self):
     self.step_1 = TBBaseStep()
     self.step_2 = TBBaseStep()
     self.step_3 = TBBaseStep()
Пример #16
0
class TestTBBaseTest(unittest.TestCase):
    def setUp(self):
        self.step_1 = TBBaseStep()
        self.step_2 = TBBaseStep()

        self.step_1.add_next_step(self.step_2)

        self.test = TBBaseTest()

    def test_add_step(self):
        self.test.load_steps(self.step_1)

        self.assertEqual(self.test.first_step, self.step_1,
                         "First step is not loaded")
        self.assertEqual(self.test.current_step, self.step_1,
                         "Current step is not loaded")

    def test_get_current_iteration(self):
        self.assertEqual(self.test.get_current_iteration(), 0)

    def test_configure_next_iteration(self):
        self.test.load_steps(self.step_1)
        self.assertEqual(self.test.get_current_iteration(), 0)

        self.test.current_step = self.step_2
        self.test.configure_next_iteration()

        self.assertEqual(self.test.get_current_iteration(), 1)
        self.assertEqual(self.test.current_step, self.step_1)

    def test_add_step_wrong(self):
        with self.assertRaises(StepException):
            self.test.load_steps(self.step_2)

        with self.assertRaises(TypeError):
            self.test.load_steps(None)

    def test_add_tear_down_steps(self):
        self.test.load_tear_down_steps(self.step_1)

        self.assertEqual(self.test.tear_down_first_step, self.step_1,
                         "First step is not loaded")

    def test_add_tear_down_steps_wrong(self):
        with self.assertRaises(StepException):
            self.test.load_tear_down_steps(self.step_2)

        with self.assertRaises(TypeError):
            self.test.load_tear_down_steps(None)

    def test_ready(self):
        self.assertFalse(self.test.ready())

        self.test.run_test = True
        self.assertFalse(self.test.ready())

        self.test.load_interface(SampleInterface, "basic")
        self.assertFalse(self.test.ready())

        self.test.load_middleware(SampleMiddleware)
        self.assertFalse(self.test.ready())

        self.test.load_steps(self.step_1)
        self.assertTrue(self.test.ready())

    def test_load_interface(self):
        self.test.load_interface(SampleInterface, "basic")

        with self.assertRaises(ImproperlyConfigured):
            # Try to load middleware as interface
            self.test.load_interface(SampleMiddleware, "basic_failure")

    def test_load_middleware(self):
        self.test.load_middleware(SampleMiddleware)

        with self.assertRaises(ImproperlyConfigured):
            # Try to load interface as middleware
            self.test.load_middleware(SampleInterface)

    def test_load_objectmap(self):
        object_map = TBBaseObjectMap("objectmap")

        self.test.load_object_map(object_map, "objectmap")

        with self.assertRaises(ImproperlyConfigured):
            # Try load middleware as objectmap
            self.test.load_object_map(SampleMiddleware(), "objectmap")

    def test_run_middlewares(self):
        def create_new_context():
            c_x = StepContext(self.test)
            c_x.additional_settings["MiddlewareRun"] = None
            return c_x

        self.test.load_middleware(SampleMiddleware)

        step_context = create_new_context()
        self.test.run_middlewares(step_context, MIDDLEWARE_MODE_AFTER_STEP)
        self.assertEqual(step_context.additional_settings["MiddlewareRun"],
                         "after_step")

        step_context = create_new_context()
        self.test.run_middlewares(step_context, MIDDLEWARE_MODE_BEFORE_STEP)
        self.assertEqual(step_context.additional_settings["MiddlewareRun"],
                         "before_step")

        step_context = create_new_context()
        self.test.run_middlewares(step_context, MIDDLEWARE_MODE_STEP_FAILURE)
        self.assertEqual(step_context.additional_settings["MiddlewareRun"],
                         "step_failure")

        step_context = create_new_context()
        self.test.run_middlewares(step_context,
                                  MIDDLEWARE_MODE_TEARDOWN_AFTER_STEP)
        self.assertEqual(step_context.additional_settings["MiddlewareRun"],
                         "tear_down_after_step")

        step_context = create_new_context()
        self.test.run_middlewares(step_context,
                                  MIDDLEWARE_MODE_TEARDOWN_BEFORE_STEP)
        self.assertEqual(step_context.additional_settings["MiddlewareRun"],
                         "tear_down_before_step")

    def test_execute_step(self):
        self.test.load_interface(SampleInterface, "sample")

        step_1 = TBBaseStep(action="SampleAction")
        step_2 = TBBaseStep(action="SampleActionFail")

        step_1.add_next_step(step_2)

        c_x = StepContext(self.test)
        c_x.update_context(step_1, c_x)
        self.test.execute_step(c_x)  # No interface defined

        c_x = StepContext(self.test)
        c_x.update_context(step_1, c_x)
        c_x.action_interface = "sample"
        self.test.execute_step(c_x)  # Interface defined

        # Interface defined, but not installed
        with self.assertRaises(ImproperlyConfigured):
            c_x = StepContext(self.test)
            c_x.update_context(step_1, c_x)
            c_x.action_interface = "sample_fail"
            self.test.execute_step(c_x)

        # Action not defined
        with self.assertRaises(ImproperlyConfigured):
            c_x = StepContext(self.test)
            c_x.update_context(step_2, c_x)
            self.test.execute_step(c_x)

    def test_run(self):
        step_1 = TBBaseStep(action="SampleAction")
        step_2 = TBBaseStep(action="SampleAction")
        step_1.add_next_step(step_2)

        self.test.run_test = True
        self.test.load_interface(SampleInterface, "basic")
        self.test.load_middleware(SampleMiddleware)
        self.test.load_steps(step_1)
        self.test.load_tear_down_steps(step_1)

        self.test.run()

    def test_run_fail(self):
        with self.assertRaises(ImproperlyConfigured):
            self.test.run()

        step_1 = TBBaseStep(action="SampleAction")
        step_2 = TBBaseStep(action="FailAction")
        step_1.add_next_step(step_2)

        self.test.run_test = True
        self.test.load_interface(SampleInterface, "basic")
        self.test.load_middleware(SampleMiddleware)
        self.test.load_steps(step_1)

        self.test.run()