Пример #1
0
    def send_keys(self, *value):
        """Simulates typing into the element.

        :Args:
            - value - A string for typing, or setting form fields.  For setting
              file inputs, this could be a local file path.

        Use this to send simple key events or to fill out form fields::

            form_textfield = driver.find_element_by_name('username')
            form_textfield.send_keys("admin")

        This can also be used to set file inputs.

        ::

            file_input = driver.find_element_by_name('profilePic')
            file_input.send_keys("path/to/profilepic.gif")
            # Generally it's better to wrap the file path in one of the methods
            # in os.path to return the actual path to support cross OS testing.
            # file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))

        """
        WE.send_keys(self, *value)
        return self
Пример #2
0
    def test_send_key(self):
        driver = android_w3c_driver()
        httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/element/element_id/value'))

        element = MobileWebElement(driver, 'element_id', w3c=True)
        element.send_keys('happy testing')

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['text'] == ''.join(d['value'])
Пример #3
0
 def ie(self, element: WebElement, is_sent_keys: bool, value=None):
     if is_sent_keys and value is not None:
         logger.info(f'typing on {element} with {value}')
         element.send_keys(value)
     elif is_sent_keys is False:
         logger.info(f'clicking on {element}')
         element.click()
     else:
         raise ValueError('invalid values for function')
Пример #4
0
    def test_set_value(self):
        driver = android_w3c_driver()
        httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/element/element_id/value'))

        element = MobileWebElement(driver, 'element_id', w3c=True)
        value = 'happy testing'
        element.set_value(value)

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['value'] == [value]
Пример #5
0
    def test_find_element_by_windows_uiautomation(self):
        driver = android_w3c_driver()
        element = MobileWebElement(driver, 'element_id', w3c=True)
        httpretty.register_uri(
            httpretty.POST,
            appium_command('/session/1234567890/element/element_id/element'),
            body='{"value": {"element-6066-11e4-a52e-4f735466cecf": "win-element-id"}}'
        )
        el = element.find_element_by_windows_uiautomation('win_element')

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['using'] == '-windows uiautomation'
        assert el.id == 'win-element-id'
Пример #6
0
    def test_find_elements_by_android_data_matcher_no_value(self):
        driver = android_w3c_driver()
        element = MobileWebElement(driver, 'element_id', w3c=True)
        httpretty.register_uri(
            httpretty.POST,
            appium_command('/session/1234567890/element/element_id/elements'),
            body='{"value": []}')
        els = element.find_elements_by_android_data_matcher()

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['using'] == '-android datamatcher'
        assert d['value'] == '{}'
        assert len(els) == 0
Пример #7
0
    def test_send_key_with_file(self):
        driver = android_w3c_driver()
        # Should not send this file
        tmp_f = tempfile.NamedTemporaryFile()
        httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/element/element_id/value'))

        try:
            element = MobileWebElement(driver, 'element_id', w3c=True)
            element.send_keys(tmp_f.name)
        finally:
            tmp_f.close()

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['text'] == ''.join(d['value'])
Пример #8
0
    def test_find_elements_by_android_data_matcher_no_value(self):
        driver = android_w3c_driver()
        element = MobileWebElement(driver, 'element_id', w3c=True)
        httpretty.register_uri(
            httpretty.POST,
            appium_command('/session/1234567890/element/element_id/elements'),
            body='{"value": []}'
        )
        els = element.find_elements_by_android_data_matcher()

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['using'] == '-android datamatcher'
        assert d['value'] == '{}'
        assert len(els) == 0
Пример #9
0
    def test_get_attribute_with_dict(self):
        driver = android_w3c_driver()
        rect_dict = {'y': 200, 'x': 100, 'width': 300, 'height': 56}
        httpretty.register_uri(
            httpretty.GET,
            appium_command('/session/1234567890/element/element_id/attribute/rect'),
            body=json.dumps({"value": rect_dict}),
        )

        element = MobileWebElement(driver, 'element_id', w3c=True)
        ef = element.get_attribute('rect')

        d = httpretty.last_request()

        assert isinstance(ef, dict)
        assert ef == rect_dict
Пример #10
0
    def test_find_elements_by_android_data_matcher(self):
        driver = android_w3c_driver()
        element = MobileWebElement(driver, 'element_id', w3c=True)
        httpretty.register_uri(
            httpretty.POST,
            appium_command('/session/1234567890/element/element_id/elements'),
            body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "child-element-id1"}, {"element-6066-11e4-a52e-4f735466cecf": "child-element-id2"}]}'
        )
        els = element.find_elements_by_android_data_matcher(name='title', args=['title', 'Animation'])

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['using'] == '-android datamatcher'
        value_dict = json.loads(d['value'])
        assert value_dict['args'] == ['title', 'Animation']
        assert value_dict['name'] == 'title'
        assert els[0].id == 'child-element-id1'
        assert els[1].id == 'child-element-id2'
Пример #11
0
    def test_find_elements_by_android_data_matcher(self):
        driver = android_w3c_driver()
        element = MobileWebElement(driver, 'element_id', w3c=True)
        httpretty.register_uri(
            httpretty.POST,
            appium_command('/session/1234567890/element/element_id/elements'),
            body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "child-element-id1"}, {"element-6066-11e4-a52e-4f735466cecf": "child-element-id2"}]}'
        )
        els = element.find_elements_by_android_data_matcher(name='title', args=['title', 'Animation'])

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['using'] == '-android datamatcher'
        value_dict = json.loads(d['value'])
        assert value_dict['args'] == ['title', 'Animation']
        assert value_dict['name'] == 'title'
        assert els[0].id == 'child-element-id1'
        assert els[1].id == 'child-element-id2'
 def send_keys(el: WebElement, data: str):
     el.click()
     el.send_keys(data)
 def clear(el: WebElement):
     el.click()
     el.clear()