예제 #1
0
 def login(self):
     self.page = SignIn(driver)
     self.page.open_and_sign_in(utils.settings.get_user(), utils.settings.get_pass())
예제 #2
0
 def open_http_test_page(self):
     self.page = HttpTest(driver)
     self.page.open()
     self.page.verify_test_type()
예제 #3
0
class SanityHttpTest(BaseTest):
    def __init__(self, testname):
        super(SanityHttpTest, self).__init__(testname)

    def test_create_http_test(self):
        global driver
        driver = StartBrowser().start()
        self.login()
        self.open_http_test_page()
        self.set_name(data["name"])

        # actions with Url fields
        self.set_urls(data["label"], data["url"], data["body"])
        self.delete_url_rows(2)

        # actions with Headers
        self.open_more_options_menu()
        self.verify_more_options_menu()
        self.close_more_options_menu_and_verify()
        self.add_header_rows()
        self.enter_headers(headers)
        self.delete_header_row()

        # Hosts Override
        self.open_hosts_override()
        self.enter_properties(data["hosts_override1"])
        self.enter_properties(data["hosts_override1"])
        self.enter_properties(data["hosts_override1"], 4)
        self.edit_properties(data["hosts_override2"])
        self.edit_properties(data["hosts_override3"], 2)
        self.add_delete_hosts_override_fields()
        self.close_hosts_override()
        # self.apply_host_override_props()

        # Thresholds
        self.add_thresholds()
        self.edit_thresholds()
        self.verify_thresholds()
        self.delete_thresholds()
        self.save_test()

    @step
    def login(self):
        self.page = SignIn(driver)
        self.page.open_and_sign_in(utils.settings.get_user(), utils.settings.get_pass())

    @step
    def open_http_test_page(self):
        self.page = HttpTest(driver)
        self.page.open()
        self.page.verify_test_type()

    @step
    def set_name(self, name):
        self.page.type_name(name)

    @step(description="set 4 url rows (1 with GET type, 1 empty, 1 with POST type and body, 1 with PUT type and body)")
    def set_urls(self, label, url, body=None):
        # set labels
        self.page.set_label(label)
        self.page.set_label(label, 3)
        self.page.set_label(label, 4)

        # set urls and types
        self.page.set_url(url[0])
        self.page.verify_request_type(self.page.types["get"], 1)
        self.page.set_url(url[1], 4, self.page.types["post"])
        self.page.verify_request_type(self.page.types["post"], 4)
        self.page.set_url(url[0], 3, self.page.types["put"])
        self.page.verify_request_type(self.page.types["put"], 3)

        # set body for PUT and POST requests
        if body:
            self.page.type_request_body(body, 4)
            self.page.type_request_body(body, 3)

            # verify body for PUT and POST requests
            self.assertEqual(self.page.get_request_body(3), body, "Failed to enter body correctly")
            self.page.verify_request_body(body, 4)

    @step(description="remove two url rows: the second one (it is empty) and the last row")
    def delete_url_rows(self, *args):
        self.page.delete_url_field()
        for i in args:
            self.page.delete_url_field(i)

    @step(description="open and close More Options menu for the first field, and open for the second one")
    def open_more_options_menu(self):
        self.page.open_more_options_menu()
        self.page.open_more_options_menu(2)
        self.page.close_more_options_menu()

    @step(description="verify that More Options menu is opened for the second field")
    def verify_more_options_menu(self):
        self.assertTrue(self.page.verify_more_options_is_opened(1, False), 'More Options menu is opened')

    @step(description="close More Options menu the second field")
    def close_more_options_menu_and_verify(self):
        self.page.close_more_options_menu(2)

    @step
    def add_header_rows(self):
        self.page.add_header_row()
        self.page.add_header_row(2)
        self.page.add_header_row(2)

    @step
    def enter_headers(self, header):
        self.page.type_header(header, 2)
        self.page.type_header(header)

    @step
    def delete_header_row(self):
        self.page.delete_header_row(2, 2)
        self.page.delete_header_row()

    @step
    def open_hosts_override(self):
        self.page.open_property_window(self.page.hosts_override)

    @step
    def apply_host_override_props(self):
        self.page.apply()
        self.assertFalse(self.page.is_property_window_open(), 'Failed to close Hosts Override window')

    @step
    def close_hosts_override(self):
        self.page.close_property_windows()
        self.assertFalse(self.page.is_property_window_open(), 'Failed to close Hosts Override window')

    @step(description="enter properties and verify them")
    def enter_properties(self, arguments, row=None):
        self.page.set_field(arguments)
        self.page.verify_field(arguments, row)

    @step
    def edit_properties(self, arguments, row=None):
        self.page.edit_field(arguments, row)
        self.page.verify_field(arguments, row)

    @step(description="add one row (the third) and remove 2 fields")
    def add_delete_hosts_override_fields(self):
        self.page.add_row()
        self.page.delete_row(3)
        self.page.delete_row()

    @step
    def add_thresholds(self):
        self.page.open_property_window(self.page.thresholds)
        self.page.add_thresholds("label", self.page.ThresholdOpt.errors.value, self.page.ThresholdSubopt.count.value,
                                 self.page.ComparisonOpts.equal_to.value, "10")
        self.page.add_thresholds("label", self.page.ThresholdOpt.hits.value, self.page.ThresholdSubopt.avg.value,
                                 self.page.ComparisonOpts.greater_than.value, "30", "message", True)
        self.page.add_thresholds("label", self.page.ThresholdOpt.errors.value, self.page.ThresholdSubopt.count.value,
                                 self.page.ComparisonOpts.equal_to.value, "10")
        self.page.add_thresholds("label", self.page.ThresholdOpt.errors.value, self.page.ThresholdSubopt.count.value,
                                 self.page.ComparisonOpts.equal_to.value, "10")

        self.page.apply()

    @step
    def edit_thresholds(self):
        self.page.open_property_window(self.page.thresholds)
        self.page.edit_thresholds("label", self.page.ThresholdOpt.respTime.value, self.page.ThresholdSubopt.std.value,
                                  self.page.ComparisonOpts.less_than.value, "30")
        self.page.edit_thresholds("label", self.page.ThresholdOpt.errors.value, self.page.ThresholdSubopt.rate.value,
                                  self.page.ComparisonOpts.not_equal_to.value, "40", 2, "message1", False)

        self.page.apply()

    @step
    def verify_thresholds(self):
        self.page.open_property_window(self.page.thresholds)
        self.page.verify_thresholds("label", self.page.ThresholdOpt.respTime.value, self.page.ThresholdSubopt.std.value,
                                    self.page.ComparisonOpts.less_than.value, "30")
        self.page.verify_thresholds("label", self.page.ThresholdOpt.errors.value, self.page.ThresholdSubopt.rate.value,
                                    self.page.ComparisonOpts.not_equal_to.value, "40", 2, "message1", False)
        self.page.apply()

    @step
    def delete_thresholds(self):
        self.page.open_property_window(self.page.thresholds)
        self.page.delete_thresholds(3)
        self.page.delete_thresholds()
        self.page.delete_thresholds("all")
        self.page.apply()
        self.page.open_property_window(self.page.thresholds)
        self.page.delete_thresholds(3)
        self.page.close_property_windows()

    @step
    def save_test(self):
        self.page.save_test()

    def tearDown(self):
        driver.close()