Skip to content

Commit

Permalink
FileInput class
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Falešník committed Jan 12, 2017
1 parent 5b56e27 commit d6194af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/widgetastic/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from collections import defaultdict, namedtuple
from copy import copy
from jsmin import jsmin
from selenium.webdriver.remote.file_detector import LocalFileDetector
from smartloc import Locator
from wait_for import wait_for

Expand Down Expand Up @@ -676,6 +677,7 @@ class BaseInput(Widget):
Args:
name: If you want to look the input up by name, use this parameter, pass the name.
id: If you want to look the input up by id, use this parameter, pass the id.
locator: If you have specific locator, use it here.
"""
def __init__(self, parent, name=None, id=None, locator=None, logger=None):
if (locator and (name or id)) or (name and (id or locator)) or (id and (name or locator)):
Expand Down Expand Up @@ -703,6 +705,7 @@ class TextInput(BaseInput):
Args:
name: If you want to look the input up by name, use this parameter, pass the name.
id: If you want to look the input up by id, use this parameter, pass the id.
locator: If you have specific locator, use it here.
"""
@property
def value(self):
Expand All @@ -726,12 +729,31 @@ def fill(self, value):
return True


class FileInput(BaseInput):
"""This represents the file input.
Args:
name: If you want to look the input up by name, use this parameter, pass the name.
id: If you want to look the input up by id, use this parameter, pass the id.
locator: If you have specific locator, use it here.
"""

def read(self):
raise DoNotReadThisWidget()

def fill(self, value):
with self.browser.selenium.file_detector_context(LocalFileDetector):
self.browser.send_keys(value, self)
return True


class Checkbox(BaseInput, ClickableMixin):
"""This widget represents the bogo-standard form checkbox.
Args:
name: If you want to look the input up by name, use this parameter, pass the name.
id: If you want to look the input up by id, use this parameter, pass the id.
locator: If you have specific locator, use it here.
"""

@property
Expand Down
8 changes: 7 additions & 1 deletion testing/test_basic_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest
import re

from widgetastic.widget import View, Table, Text, TextInput, Checkbox, Select
from widgetastic.exceptions import DoNotReadThisWidget
from widgetastic.widget import View, Table, Text, TextInput, FileInput, Checkbox, Select
from widgetastic.utils import Fillable, ParametrizedString


Expand All @@ -12,6 +13,7 @@ class TestForm(View):
h3 = Text('.//h3')
input1 = TextInput(name='input1')
input2 = Checkbox(id='input2')
fileinput = FileInput(id='fileinput')

class AFillable(Fillable):
def __init__(self, text):
Expand Down Expand Up @@ -44,6 +46,10 @@ def as_fill_value(self):
assert not form.input1.fill(AFillable('a_test'))
assert form.input1.read() == 'a_test'

assert form.fileinput.fill('foo')
with pytest.raises(DoNotReadThisWidget):
form.fileinput.read()


def test_nested_views_read_fill(browser):
class TestForm(View):
Expand Down

0 comments on commit d6194af

Please sign in to comment.