Skip to content

Commit e0cd6b6

Browse files
committed
Improve choose_file to work also when using directly from a library
1 parent 35db4ba commit e0cd6b6

File tree

6 files changed

+24
-44
lines changed

6 files changed

+24
-44
lines changed

atest/acceptance/keywords/choose_file.robot

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ Choose File With Grid
3131
Textfield Value Should Be file_to_upload C:\\fakepath\\temp2.txt
3232
[Teardown] Remove File ${CURDIR}${/}temp2.txt
3333

34+
Choose File With Grid From Library Using SL choose_file method
35+
[Documentation]
36+
... LOG 4:6 DEBUG GLOB: POST*/session/*/file*"file": "*
37+
[Tags] OnlyGrid
38+
[Setup] Go To Page "forms/file_upload_form.html"
39+
Touch ${CURDIR}${/}temp42.txt
40+
Import Library ${CURDIR}/../../resources/testlibs/ChooseFileLib.py
41+
ChooseFileLib.my_choose_file file_to_upload ${CURDIR}${/}temp42.txt
42+
Textfield Value Should Be file_to_upload C:\\fakepath\\temp42.txt
43+
[Teardown] Remove File ${CURDIR}${/}temp42.txt
44+
3445
Input Text Should Work Same Way When Not Using Grid
3546
[Documentation]
3647
... LOG 2:5 DEBUG GLOB: POST*/session/*/clear {"*
@@ -51,32 +62,6 @@ Input Text Should Work Same Way When Using Grid
5162
Textfield Value Should Be file_to_upload C:\\fakepath\\temp3.txt
5263
[Teardown] Remove File ${CURDIR}${/}temp3.txt
5364

54-
Running Keyword Is Saved Correctly
55-
${keyword_method} = get_running_keyword
56-
Should Be Equal get_running_keyword ${keyword_method}
57-
${keyword_method} = Get Running Keyword
58-
Should Be Equal get_running_keyword ${keyword_method}
59-
${keyword_method} = Get Running Keyword By Decorator
60-
Should Be Equal Get Running Keyword By Decorator ${keyword_method}
61-
${keyword_method} = get_running_keyword_by_decorator
62-
Should Be Equal Get Running Keyword By Decorator ${keyword_method}
63-
64-
Running Keyword Is Cleared Correctly
65-
${sl} = Get Library Instance SeleniumLibrary
66-
Should Be Equal ${sl._running_keyword} ${None}
67-
${keyword_method} = Get Running Keyword
68-
Should Be Equal get_running_keyword ${keyword_method}
69-
${sl} = Get Library Instance SeleniumLibrary
70-
Should Be Equal ${sl._running_keyword} ${None}
71-
72-
Running Keyword Is Cleared Correctly When Error
73-
${sl} = Get Library Instance SeleniumLibrary
74-
Should Be Equal ${sl._running_keyword} ${None}
75-
Run Keyword And Expect Error Page should have contained text 'Is not here' but did not.
76-
... Page Should Contain Is not here
77-
${sl} = Get Library Instance SeleniumLibrary
78-
Should Be Equal ${sl._running_keyword} ${None}
79-
8065
*** Keywords ***
8166
Navigate To File Upload Form And Create Temp File To Upload
8267
Cannot Be Executed in IE

atest/acceptance/resource.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*** Setting ***
2-
Library SeleniumLibrary run_on_failure=Nothing implicit_wait=0.2 seconds plugins=RunningKeyword.RunningKeyword
2+
Library SeleniumLibrary run_on_failure=Nothing implicit_wait=0.2 seconds
33
Library Collections
44
Library OperatingSystem
55
Library DateTime
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from robot.libraries.BuiltIn import BuiltIn
2+
3+
4+
def my_choose_file(locator, path):
5+
sl = BuiltIn().get_library_instance('SeleniumLibrary')
6+
sl.choose_file(locator, path)

atest/resources/testlibs/RunningKeyword.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/SeleniumLibrary/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,11 @@ def __init__(self, timeout=5.0, implicit_wait=0.0,
467467
DynamicCore.__init__(self, libraries)
468468

469469
def run_keyword(self, name, args, kwargs):
470-
self._running_keyword = name
471470
try:
472471
return DynamicCore.run_keyword(self, name, args, kwargs)
473472
except Exception:
474473
self.failure_occurred()
475474
raise
476-
finally:
477-
self._running_keyword = None
478475

479476
def get_keyword_tags(self, name):
480477
tags = list(DynamicCore.get_keyword_tags(self, name))

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,12 @@ def choose_file(self, locator, file_path):
212212
Example:
213213
| `Choose File` | my_upload_field | ${CURDIR}/trades.csv |
214214
"""
215-
self.info('Sending %s to browser.' % os.path.abspath(file_path))
216-
self.find_element(locator).send_keys(file_path)
215+
self.ctx._running_keyword = 'choose_file'
216+
try:
217+
self.info('Sending %s to browser.' % os.path.abspath(file_path))
218+
self.find_element(locator).send_keys(file_path)
219+
finally:
220+
self.ctx._running_keyword = None
217221

218222
@keyword
219223
def input_password(self, locator, password, clear=True):

0 commit comments

Comments
 (0)