I am very new to robot framework, working it at pycharm.
I just want to input some text at current field. but none of these works.
I have tried
Press Keycode a
Press Keys text_field q
input text ${mylocator} ${string-abc}
If I am using the correct library?
*** Settings ***
Library AppiumLibrary run_on_failure=AppiumLibrary.CapturePageScreenshot
Library Selenium2Library run_on_failure=AppiumLibrary.CapturePageScreenshot
*** Variables ***
${MsgEditor} //*[#class='android.widget.RelativeLayout' and #resource-id='com.test.abc.work.cac:id/editor']
*** Test Cases ***
Add item
Press Keys text_field q <--error browser not open
\\or
appiumlibrary.Input Text ${MsgEditor} update <== error Message: Cannot set the element to 'update'. Did you interact with the correct element?
updated that Press Keys still failed. error:
KEYWORD Selenium2Library . Press Keys text_field, q
Documentation:
Simulates the user pressing key(s) to an element or on the active browser.
Start / End / Elapsed: 20201218 10:05:20.575 / 20201218 10:05:21.339 / 00:00:00.764
00:00:00.755KEYWORD AppiumLibrary . Capture Page Screenshot
10:05:20.575 TRACE Arguments: [ 'text_field' | 'q' ]
10:05:20.581 INFO Sending key(s) ('q',) to text_field element.
10:05:21.339 FAIL No browser is open.
10:05:21.339 DEBUG Traceback (most recent call last):
File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\__init__.py", line 471, in run_keyword
return DynamicCore.run_keyword(self, name, args, kwargs)
File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\robotlibcore.py", line 103, in run_keyword
return self.keywords[name](*args, **(kwargs or {}))
File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\keywords\element.py", line 895, in press_keys
element = self.find_element(locator)
File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\base\context.py", line 74, in find_element
return self.element_finder.find(locator, tag, True, required, parent)
File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\locators\elementfinder.py", line 74, in find
parent=parent or self.driver)
File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\base\context.py", line 32, in driver
return self.ctx.driver
File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\__init__.py", line 547, in driver
raise NoOpenBrowser('No browser is open.')
InputText failed. I have this same InputText at other field and works. I tried tap over different field with that locator and it works.
is the app has issue on that element? but i can press on keyboard manually after tap to the field.
I recommend reading the official documentation first: http://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html and the user guide as well: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
Press Keys is not a keyword from AppiumLibrary. It's a keyword from SeleniumLibrary (https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Press%20Keys), but you're not importing it to your project. And even if you imported it, this keyword takes two arguments (locator and keys), so you need to use it correctly.
*** Test Cases ***
Press Keys a
In addition to what I've said, there's no test case name, this is incorrect and won't work, it will in fact give you the following error:
Test case name cannot be empty.
You have correctly used Input Test keyword from AppiumLibrary. However, you might need to validate that your locator is correct. We can't say that since you didn't include that information in your question.
I have used another method. Adb shell input text to fire the text
Related
I'm trying to create a FOR Loop in Robot Framework that will click through a set of links on a page. Trying to avoid a string of "Click Element" lines and just make a loop out of it. I believe my base code is correct in the loop construction, but PyCharm is seeing the first line of the loop as its own keyword, which isn't right. It's not moving past that part. Any ideas here?
My variables are known, just stored off on another file.
Documentation Homepage
Library Zoomba.GUILibrary
Library Process
Resource ../../Pages/resource.robot
Suite Setup Browser Setup ${url}
*** Keywords ***
Menu Navigation
${list}= Create List ${TUAbout} ${TUAcademics} ${TUResearch}
:FOR ${item} IN #{list}
Wait For And Click Element ${item}
END
*** Test Cases ***
TC 001 Menu Navigation
Menu Navigation```
You need at least 2 spaces for the variables on the FOR line and FOR syntax has changed in more recent versions of RF so :FOR is deprecated syntax use just FOR e.g.
FOR ${item} IN #{list}
I believe that should be enough to fix the current error you're seeing
The source is this obstacle: https://obstaclecourse.tricentis.com/Obstacles/87912
What I got this far is:
*** Settings ***
Library Browser
Library XML
Library Collections
Library String
Documentation BE FAST AUTOMATE
*** Variables ***
${links}= <isbn>
${rechts}= </isbn>
*** Test Cases ***
Execute a for loop only three times
Open Browser https://obstaclecourse.tricentis.com/Obstacles/87912
Click id=loadbooks
${alles}= Get Text id=books
This one is mentioned: 'hard'
The Get Text literally gets all the text which is fine, but from that point I have no clue how the get the isbn (from the specific, or even ... any)
A bit further thanks to this page: Parse XML only returns first element
*** Settings ***
Library Browser enable_presenter_mode=False
Library XML
Library Collections
Library String
Documentation BE FAST AUTOMATE
*** Variables ***
##{ROBOTS}= 1 2 3
${links}= <isbn>
${rechts}= </isbn>
*** Test Cases ***
Find the isbn
Open Browser https://obstaclecourse.tricentis.com/Obstacles/87912
sleep 5s
Click id=loadbooks
${alles}= Get Text id=books
${x}= Parse Xml ${alles}
${el_my_value}= XML.Get Element ${x} .//isbn
Log ${el_my_value}
${first_text}= Get Element Text ${el_my_value}
but now I still need the isbn corresponding to the correct title.
because the response is: Multiple elements (6) matching './/isbn' found.
I don't think I should post this as you are suppose to build the answer to the exercise, not google it...
Nevertheless, here it goes.
The data is hidden and if you carefully look into the html of the page you will see that after clicking the button "Load books" a javascript function is kicked that will set the value into the xml and into a variable.
After knowing this information is very simple to get the value that we want just using simple robot + selenium:
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Insert Correct ISBN
Open Browser https://obstaclecourse.tricentis.com/Obstacles/87912 Chrome
Click Element id=loadbooks
${isbnValue} Execute Javascript return isbn
Input Text id=isbn ${isbnValue}
I've a situation in my app where I need to click on file name from a /div table which will save the file name internally and gets displayed in a /div grid. Every time I run the automation, I need to click on a new file.
I don't have any problem in clicking the file to be saved.
But after the click, the app stores the file in a /div grid and I want to select the file that I added.
For this I used this approach:
I am storing the file name in a global variable ${g_ExtractedFileName}
For eg: XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt
My complete Xpath to the file is something like this
xpath://div[#role='row']//span[contains(text(),'XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt')]
For this I have the below:-
${attachedFileXpath1}= set variable xpath://div[#role='row']//span[contains(text(),'
${attachedFileXpath2}= set variable ${g_ExtractedFileName}
${attachedFileXpath3}= set variable ')]'
${attachedFileXpath}= set variable ${attachedFileXpath1}${attachedFileXpath2}${attachedFileXpath3}
click element ${attachedFileXpath}
This throws an error
SyntaxError: Failed to execute 'evaluate' on 'Document': The string
'//div[#role='row']//span[contains(text(),'XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt
')]'' is not a valid XPath expression.
When I don't use the variables and simply use (hard coded value for file name)
click element xpath://div[#role='row']//span[contains(text(),'XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt')]
It works correctly.
I also tried this but same error
${attachedFileXpath}= catenate ${attachedFileXpath1}${attachedFileXpath2}${attachedFileXpath3}
I am not sure when the 3 variables are concatenated, it cuts off the variable value to a new line causing this problem.
Any help is much appreciated.
The simplest approach is to simply use the replace functionality that is already present in Robot Framework variables. The below example will result in an Element not found error, but that is expected.
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${g_ExtractedFileName} XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt
*** Test Cases ***
Use Global String in Locator
Open Browser https://google.com chrome
click element xpath://div[#role='row']//span[contains(text(),'${g_ExtractedFileName}')]
[Teardown] Close All Browsers
Simply create keyword which accept the file name as argument and returns complete valid xpath expression. It will be re-usable and elegant solution -
*** Test case ***
Select file saved in div grid
${attached_file_xpath}= GetAttachedFileXpath ${File_Name}
Click Element ${attached_file_xpath}
*** Keywords ***
GetAttachedFileXpath [Arguments] ${File_Name}
return from keyword xpath://div[#role='row']//span[contains(text(),'${File_Name}')]
I am trying to append data stored in a variable to a file. The file was successfully created and the data is stored in the variable; however, I continue to get the AttiributeError:
AttributeError: 'NoneType' object has no attribute 'replace'
here are my results
KEYWORD ${FileA} = OperatingSystem . Create File metrics/Live_RTT.txt, ${MT_Com_RTT_LB_Live_Topics}
00:00:05.233 KEYWORD Selenium2Library . Click Element ${BLANK_CANVAS}
00:00:05.129 KEYWORD Selenium2Library . Click Element //div[#title='${device1}']
00:00:05.063 KEYWORD Selenium2Library . Click Element //div[#title='${device2}']
00:00:00.045 KEYWORD ${MT_Com_RTT_LB_Live_Topics} = Selenium2Library . Get Text xpath=${REAL_TIME_TRENDING_TOPICS}
00:00:00.001 KEYWORD BuiltIn . Log ${MT_Com_RTT_LB_Live_Topics}
Documentation:
Logs the given message with the given level.
Start / End / Elapsed: 20181028 21:37:34.971 / 20181028 21:37:34.972 / 00:00:00.001
21:37:34.971 INFO Available Topics
Active Energy Delivered + Received
Active Energy Into the Load
Active Energy Out of the Load
Active Power
Active Power A
00:00:00.001 KEYWORD OperatingSystem . Append To File ${FileA}, ${MT_Com_RTT_LB_Live_Topics}
Documentation:
Appends the given content to the specified file.
Start / End / Elapsed: 20181028 21:37:34.972 / 20181028 21:37:34.973 / 00:00:00.001
21:37:34.973 FAIL AttributeError: 'NoneType' object has no attribute 'replace'
Looking at the library's source, the exception most probably is raised in the normalize_path() method, which does this string replacement:
path = os.path.normpath(os.path.expanduser(path.replace('/', os.sep)))
, where path is the filename - the first argument to the Append To File kw call. The exception says its value is None (e.g. no value set) while it should be some string.
Looking at the log, you're setting this value to the return value of Create File - but that keyword does not return one at all, it simply creates the file you specified in its first argument.
So to resolve - just set the value of ${FileA} yourself, pass it to the two keywords, and do not reassign in the Create File call.
I am trying to modify the PROMPT variable to include some additional information. My current PROMPT also includes git status on the right hand side. It looks like this:
ex2 ➤ git:master*
Screen shot of the same:
I would like to some text in front of the current folder-- like [Drone] for example. I am currently doing it as follows,
export PROMPT=%{"$fg[green] [Donre]"$fg[$NCOLOR]%}%c ➤ %{$reset_color%}
But this creates two issues.
1. The arrow character is not parsed correctly anymore and I get an error like
" not valid in this context: ➤"
2. The git status is pushed to the next line.
The new prompt appears as,
/home/arul/.zshrc:export:100: not valid in this context: ➤
[Drone]ex2 git:maste
r*
Screen shot of the same:
Could someone help me in modifying the PROMPT correctly?
%{...} does not escape any spaces contained therein; you should quote the entire value to ensure any enclosed whitespace is properly escaped for the assignment.
export PROMPT="%{$fg[green] [Donre]$fg[$NCOLOR]%}%c ➤ %{$reset_color%}"
As is, the arrow character is being treated as a separate argument (and an invalid parameter name at that) to the export command. export, by the way, is probably unnecessary. Each shell that needs the value of PROMPT is likely executing whatever configuration file contains this assignment.
Consider using zsh's own support for colors, so that you don't need %{...} at all.
PROMPT="%F{green} [Donre]%F{...}%c ➤ %f"
(where ... is whatever color $NCOLOR represents).