コード例 #1
0
 def get_value(self, locator):
     elem = self.get_element_by(locator, 15)
     if elem.tag_name == 'select':
         select = Select(elem).first_selected_option
         return select.get_attribute("value")
     elif elem.tag_name in ('textarea', 'div'):
         return elem.text
     else:
         return elem.get_attribute('value')
コード例 #2
0
    def test_field_add():

        model_href = chrome.find_element_by_xpath('//a[text()="test_model"]')
        model_href.click()
        field_input = chrome.find_element_by_xpath('//div[@class="input-group"]/input')
        field_add_btn = chrome.find_element_by_xpath('//div[contains(@class,"input-group")]//button')
        invalid_input(field_input, field_add_btn)

        field_name = 'text'
        field_input.send_keys(field_name)
        field_add_btn.click()

        same_object(field_input, field_add_btn, field_name)
        field_tr = chrome.find_elements_by_xpath('//td//input/ancestor::tr')[0]
        type_field = field_tr.find_element_by_xpath('.//select')
        assert "TextField" == type_field.get_attribute('value')
        select = Select(type_field)
        select.select_by_visible_text("CharField")
        assert "CharField" == type_field.get_attribute('value')

        null_span = field_tr.find_element_by_xpath('.//span[contains(text(),"N")]')
        blank_span = field_tr.find_element_by_xpath('.//span[contains(text(),"B")]')
        unique_span = field_tr.find_element_by_xpath('.//span[contains(text(),"U")]')
        index_span = field_tr.find_element_by_xpath('.//span[contains(text(),"I")]')
        spans = [null_span, blank_span, unique_span, index_span]
        for span in spans:
            span.click()

        null_select = chrome.find_element_by_xpath(
            '//tr[contains(@class,"field-attr")]/td[contains(text(),"null")]/parent::tr//select')
        blank_select = chrome.find_element_by_xpath(
            '//tr[contains(@class,"field-attr")]/td[contains(text(),"blank")]/parent::tr//select')
        unique_select = chrome.find_element_by_xpath(
            '//tr[contains(@class,"field-attr")]/td[contains(text(),"unique")]/parent::tr//select')
        db_index_select = chrome.find_element_by_xpath(
            '//tr[contains(@class,"field-attr")]/td[contains(text(),"db_index")]/parent::tr//select')
        selects = [null_select, blank_select, unique_select, db_index_select]
        for select in selects:
            assert "true" in select.get_attribute('value').lower()
        for span in spans:
            span.click()
        for select in selects:
            assert not "true" in select.get_attribute('value').lower()
コード例 #3
0
def test_geo_zones_sorting(driver):
    driver.get('http://localhost/litecart/admin/?app=geo_zones&doc=geo_zones')
    links = driver.find_elements_by_css_selector('tr.row a')
    urls = []
    for link in links:
        if link.get_attribute('title') == '':
            urls.append(link.get_attribute('href'))
    for url in urls:
        driver.get(url)
        unsorted_list = []
        zones = driver.find_elements_by_css_selector(
            'select[name*=\'zone_code\']')
        for zone in zones:
            selected = Select(zone).first_selected_option
            unsorted_list.append(selected.get_attribute('textContent'))
        sorted_list = sorted(unsorted_list)
        assert sorted_list == unsorted_list
        driver.get(
            'http://localhost/litecart/admin/?app=geo_zones&doc=geo_zones')
コード例 #4
0
    def assert_(self, assertions, values=None, find_displayed=False):
        """
        :assertions
            A list of keys for which to apply assertions.
            Defaults to check if the element is present.
        """
        self.find_displayed = find_displayed

        assertions = assertions or [a.PRESENT]
        for assertion in assertions:
            if assertion == a.WAIT:
                self.select()

            elif assertion == a.PRESENT:
                self.testcase.assertTrue(self.select_quick())

            elif assertion == a.NOT_PRESENT:
                self.testcase.assertFalse(self.select_quick())

            elif assertion == a.ENABLED:
                self.testcase.assertTrue(self.select_quick().is_enabled())

            elif assertion == a.DISABLED:
                self.testcase.assertFalse(self.select_quick().is_enabled())

            elif assertion == a.CHECKED:
                self.testcase.assertTrue(self.select_quick().is_selected())

            elif assertion == a.UNCHECKED:
                self.testcase.assertFalse(self.select_quick().is_selected())

            elif assertion == a.TEXT:
                self.testcase.assertRegexpMatches(self.select_quick().text, values[assertion])

            elif assertion == a.CONTAINS:
                self.testcase.assertIn(values[assertion], self.select_quick().text)

            elif assertion == a.NOT_CONTAINS:
                self.testcase.assertNotIn(values[assertion], self.select_quick().text)

            elif assertion == a.CLASS:
                self.testcase.assertTrue(values[assertion] in self.select_quick().get_attribute('class'))

            elif assertion == a.DISPLAYED:
                self.testcase.assertTrue(self.select_quick().is_displayed())

            elif assertion == a.NOT_DISPLAYED:
                self.testcase.assertFalse(self.select_quick().is_displayed())

            elif assertion == a.GTE:
                self.testcase.assertTrue(int(self.select_quick().text) >= values[assertion])

            elif assertion == a.LTE:
                self.testcase.assertTrue(int(self.select_quick().text) <= values[assertion])

            elif assertion == a.EXPECTED_INVISIBLE:
                try:
                    WebDriverWait(self.driver, settings.IMPLICITLY_WAIT).until(
                        expected_conditions.invisibility_of_element_located((self.locator()))
                    )
                finally:
                    pass

            elif assertion == a.EXPECTED_VISIBLE:
                try:
                    WebDriverWait(self.driver, settings.IMPLICITLY_WAIT).until(
                        expected_conditions.visibility_of_element_located((self.locator()))
                    )
                finally:
                    pass

            elif assertion == a.SELECTED_OPTION:
                selected_option = Select(self.select_quick()).first_selected_option
                self.testcase.assertNotEqual(values[assertion], selected_option.get_attribute('value'))

            else:
                raise Exception('AssertElement unknown assertion: %s' % assertion)
コード例 #5
0
 def assert_field(name, value):
     element = self.wd.BY_NAME(name)
     if element.tag_name == 'select':
         element = Select(element).first_selected_option
     actual_value = element.get_attribute('value')
     assert actual_value == value