Pycharm : [Errno 10054] - robotframework

I try to Run a simple robot framework script in PyCharm.Here is my code:
*** Settings ***
Documentation This is some basic info about the whole suite
Library Selenium2Library
*** Variables ***
*** Test Cases ***
User must sign in to check out
[Documentation] This is some basic info about the test
[Tags] Smoke
Open Browser http://www.google.com.ua chrome
Close Browser
I customized robot framework with PyCharm as it was in videos but when I run this script in terminal of PyCharm, the desired site isn't opened and I get the next information:
C:\Users\user\PycharmProjects\amazon>
C:\Users\user\PycharmProjects\amazon>pybot -d results tests/Amazon.robot
Amazon :: This is some basic info about the whole suite
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
User must sign in to check out :: This is some basic info about th... | FAIL |
error: [Errno 10054]
------------------------------------------------------------------------------
Amazon :: This is some basic info about the whole suite | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\Users\user\PycharmProjects\amazon\results\output.xml
Log: C:\Users\user\PycharmProjects\amazon\results\log.html
Report: C:\Users\user\PycharmProjects\amazon\results\report.html
Tell me, please, why this script doesn't open the browser and actions that it should execute and why do I get this error. Thank you.

If the code you posted is literally your code, you're missing at least one space before chrome on the open browser line. There must be two or more spaces between the URL and the browser.
This may not be the only problem, but it's definitely a problem.

Related

Robot Framework Test Template Setup argument problems

I've got several working Robot Framework tests that I'm trying to consolidate into one test suite and run through a template. The tests are functionally the same, just being executed from a different URL. So that's the one parameter that's different. I'm trying to pass the URL into each test case, but I am getting an error: "Keyword 'Setup' expected 0 arguments, got 2."
*** Settings ***
Documentation Login tests
Library Zoomba.GUILibrary
Suite Setup Setup
Test Template Template 1
*** Variables ***
${browser} chrome
${url1} https://<test.url1>
${url2} https://<test.url2>
${url3} https://<test.url3>
*** Keywords ***
Setup
Open Browser ${url} browser=${browser} options=add_argument("<argument>")
Maximize Browser Window
Set Selenium Speed 0.2s
Log To Console Setup complete. Logging in...
Template 1
[Arguments] ${url} ${browser}=${browser}
Setup ${url} ${browser}
<Login tests>
*** Test Cases ***
Site 1 Login
${url1}
Site 2 Login
${url2}
Site 3 Login
${url3}
Anybody have any ideas? Please let me know, thanks!
You are calling Setup with two arguments, like the error says:
Template 1
[Arguments] ${url} ${browser}=${browser}
Setup ${url} ${browser}
<Login tests>

Save results from terminal in robot framework

I am having trouble output/saving the results from my terminal commands.
*** Settings ***
Library Process
Suite Teardown Terminate All Processes kill=True
*** Test Cases ***
Example
Run Process adb devices -l
Current Output
Expected Output
However, if i just run adb devices -l, it will provide me with a list of android devices id.
E.g. List of devices attached
0429329319 device usb: xxxx
My attempts
Based on the robot framework, it has this example that i tried to follow but gave me errors such as "No keyword with name ${result} = Run Process found"
Sample code from robot framework
${result} = Run Process program stdout=${TEMPDIR}/stdout.txt stderr=${TEMPDIR}/stderr.txt
Log Many stdout: ${result.stdout} stderr: ${result.stderr}
Another way that i have discovered is to use 'Get Process Result' keyword.
So my question is - how do i print/save the output of my terminal commands?
Would appreciate if anyone can take a look at it
Referenced to
http://robotframework.org/robotframework/latest/libraries/Process.html
https://github.com/robotframework/robotframework/blob/master/atest/testdata/standard_libraries/process/get_process_result.robot
I just found out one way would be using the OperatingSystem library - 'Run'.
Then log the results of the command entered into the terminal/command prompt using 'Log To Console'
*** Settings ***
Library OperatingSystem
*** Test Cases ***
Get list of devices
${result} = Run adb devices -l
Log To Console [${result}]
To save the printed stuff in the console, just do
robot xx.robot > console.txt
Referenced to - how to run commands in CMD prompt using robot framework

Unable to run shell script from test case

I'm trying to invoke a shell scrip from within a .robot test case.
The .sh file is in the same folder as the .robot file
*** Settings ***
Library Process
*** Test cases ***
Run the shell script
Start Process ./getIDfromDB.sh shell=yes
I'm getting the error:
Setting variable 'Start Process ./getIDfromDB.sh' failed: Invalid variable name 'Start Process ./getIDfromDB.sh'.
Running on Ubuntu
Researched documentation for Robot framework but could not find a solution. Maybe digging in the wrong spot.
I'm not sure how you are trying to set the path of the shell script in the robot file. The error message seems to convey that something is wrong with the way you're initialising the variable to hold the path.
The following code should work:
*** Settings ***
Library Process
*** Variables ***
${pathToScript} ./getIDfromDB.sh
*** Test cases ***
Run shell script
${output} Run process ${pathToScript} shell=yes
The return code and the output displayed in the terminal are stored in the ${output} variable. You can access the details as ${output.rc} and ${output.stdout} respectively.
You can find more details about the result object here.
According error details the keyword is not recognized, I think, you need add extra spaces after keyword name:
Start Process ./getIDfromDB.sh shell=yes

Robot test fails when run on Circle CI

when I run my Robot test locally all is fine. I have a very basic Scala Play project with a couple of html pages. This project uses bitbucket, is built using Circle Ci and uses a Docker image. My Dockerfile looks like this...
FROM circleci/python:2.7-stretch-browsers
USER root
RUN pip install --upgrade pip && \
pip install --upgrade robotframework robotframework-httplibrary robotframework-seleniumlibrary requests robotframework-requests python-jose robotframework-jsonlibrary naked
This is my .robot file...
*** Settings ***
Documentation This is some basic info about the whole suite
Library SeleniumLibrary
*** Variables ***
*** Test Cases ***
User must login to visit landing page
[Documentation] This is some basic information about the test
[Tags] Smoke
Open Browser http://localhost:9000 headlesschrome
#Open Browser http://localhost:9000 chrome
Wait Until Page Contains The Login and Authentication App!
Sleep 2s
Click Link Continue
Wait Until Page Contains User Login
Sleep 1s
Input Text username geoff
Sleep 1s
Input Text password 123
Sleep 2s
Click Button Login
Sleep 2s
Wait Until Page Contains Landing Page!
Sleep 2s
Click Link logout
Wait Until Page Contains You are logged out.
Sleep 2s
Close Browser
*** Keywords ***
There are 2 steps at the circle ci end. Build (includes 3 unit tests) and run robot test. The build is fine but the Robot tests are failing. This is the output from Circlci...
==============================================================================
User must login to visit landing page :: This is some basic inform... .User must login to visit landing page :: This is some basic inform... | FAIL |
Text 'The Login and Authentication App!' did not appear in 5 seconds.
------------------------------------------------------------------------------
Amazon :: This is some basic info about the whole suite | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: /root/project/output.xml
Log: /root/project/log.html
Report: /root/project/report.html
Exited with code 1
I suspect there is some issue with CircleCi and headlesschrome. I have tried using a different Docker image that installs a lot of Chrome stuff but to be fair that felt like a stab in the dark. Any ideas about how I can fix this would be appreciated.

File has no test case table in Robot FrameWork

I've encountered a problem relating to Robot Framework test cases. After executing it, the console (cmd screen) displays error:
"[ ERROR ] Parsing 'Login_admin_page.txt' failed: File has no test case table."
Please take a look my test suite as well as test case and help me figure out the issue:
A. Structure of Test cases:
TS_test(folder)
--Login_admin_page.txt (--> main test case)
--resource.txt (--> resource file)
B. Content of test cases file:
Login_admin_page.txt
***Settings***
Documentation A resource file with reusable keywords and variables.
... This test is functionally identical to the example in
... valid_login.txt file
Resource resource.txt
Test Teardown Close Browser
***Test Cases***
Open Login page
Open Browser To Login Page
resource.txt
*** Settings ***
Documentation A resource file with reusable keywords and variables.
...
... The system specific keywords created here form our own
... domain specific language. They utilize keywords provided
... by the imported Selenium2Library.
Library Selenium2Library
*** Variables ***
${SERVER} http://google.com
${BROWSER} Firefox
${DELAY} 0
${VALID USER} admin
${VALID PASSWORD} admin
${INVALID USER} xyz
${INVALID PASSWORD} invalid
*** Keywords ***
Open Browser To Login Page
Open Browser ${SERVER} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
Login Page Should Be Open
Login Page Should Be Open
Title Should Be Google
Use cmd and access to folder "TS_test", execute "pybot Login_admin_page.txt". The screen displays error.
Thanks.
The error File has no test case table can only occur in one circumstance: you do not have a testcase table. If you have a test case table but have no test cases, you'll get a different error.
A testcase table is denoted by a line that begins with one or more asterisks and then the phrase "Test Case" or "Test Cases". Case doesn't matter, and trailing asterisks are ignored. A fairly common pattern seems to be to use multiple asterisks on both ends of the line, eg: *** Test Cases ***
If you try to give a file without such a heading to robot, you will get the error you report. For example, trying to run robot on a completely empty file will give that exact error. Also, if you misspell "Test Case", you'll get the same error.
Given that, I'm wondering if your error is simply that you forgot to save the file before trying to run it.
Please set proper line endings.
In my case I've changed from Mac (CR) to UNIX (LF)
How about encoding of your test case files? I saved unicode encoded test file and I use to have the same error. Save your test case files in UTF-8 and It will fix your problem.
I have encountered similar file - parsing errors using Robot Framework in the past, mostly when trying to use Microsoft Word to author html files (not recommended!). I have always found that following the advice given in the Robot Framework user Guide about Debugging eventually helps me track the problem down.
In this case, I would recommend you try switching on Robot Framework's syslog output and looking through to see what it has managed to parse, if anything, from your test case file. I recently used this to figure out a nasty UTF-8 character encoding problem introduced into a html test case file by Microsoft Word (again, not recommended unless you really have to!).
(From the User Guide):
#!/bin/bash
export ROBOT_SYSLOG_FILE=/tmp/syslog.txt
export ROBOT_SYSLOG_LEVEL=DEBUG
pybot --name Syslog_example path/to/tests
I had the same problem happen to me, and in my case it was simply a missing new line after * Test Cases * and the start of the actual test table.
This happened when you copy past the content of the test case file. In my case I have copied test case content and paste in nano editor
It got pasted something like below without proper spacing
*** Settings *** Library Selenium2Library *** Variables *** ${BROWSER} firefox *** Testcases *** Hello Open Browser http://www.google.com browser=${BROWSER}
Then I have intend and aligned properly like below and its works
*** Settings ***
Library Selenium2Library
*** Variables ***
${BROWSER} firefox
*** Testcases ***
Hello
Open Browser http://www.google.com browser=${BROWSER}

Resources