Running a sample script using Robot Framework - frameworks

I am fairly new to Robot Framework. I am trying to run the following code using Ride IDE but facing issues. Could someone kindly help me on how to get this done.
Code:
*** Settings ***
*** Variables ***
*** Test Cases ***
Setting Variables
#| Example of running a python script
${result}= run process | python | C:\Users\name\Desktop\hello.py
#| | Should be equal as integers | ${result.rc} | 0
#| | Should be equal as strings | ${result.stdout} | Hello World
*** Keywords ***

I still think you should include more details in your question, namely:
the content of hello.py
the error message you get
Nevertheless, I think your problem will be somewhere around these:
1/ Your Settings section is empty, but you need Process library in order to execute Run Process keyword.
2/ Your hello.py is wrong, doesn't return and print what you think it does.
3/ You absolute path is wrong, the python file resides somewhere else.
4/ You're missing some modules you need in order to execute RF scripts. Please search on this site, similar question about missing modules has been asked many times.
All in all, the whole runnable example (provided you have all the prerequisites installed) would be:
*** Settings ***
Library Process
*** Test Cases ***
Setting Variables
${result}= Run Process python hello.py
Should be equal as integers ${result.rc} 0
Should be equal as strings ${result.stdout} Hello World
It's a good practice not to use absolute paths, so I refer to hello.py differently. The content of the file is:
hello.py
print('Hello World')

Related

pytest coverage output is cut

Running pytest with coverage in a larger project, the output is strangely cut (note the datam at the end, many files are still missed here).
I'm not aware of further configuration—no pytest.ini, no pyproject.toml, no related environment variable.
How can I overcome this, given I want the simple terminal output, not an extra report?
Only if needed: How could I print the results written to .coverage sqlite database to terminal?
> pytest tests/ --cov
...
---------- coverage: platform win32, python 3.10.4-final-0 -----------
Name Stmts Miss Cover
--------------------------------------------------------------------------------
...
datamodel\model\gis\topology\edge.py 26 3 88%
datamodel\model\gis\version.py 0 0 100%
datam
============================== 45 passed in 6.44s ==============================
This looks like a bug of the coverage package, maybe from too many files (>400 in my case), maybe interference with pytest-xdist.
In such a case ignore the pytest output and print the results written to the .coverage sqlite database to terminal, like
> pytest tests --cov -n 12
...
> coverage report
...

Robot Framework: conditional import of resource

Is it possible to do a conditional import of a resource file in robot framework? Depending on the test environment, I want to import a resource file with different variables. The variable could be read from the robot CLI (e.g. robot --variable VAR:production myTestSuite)
Illustrating Example:
*** Settings***
Resource variables_url_environment_a.robot
Resource variables_url_environment_b.robot
Run keyword if '${VAR}'=='production' Import resource variables_url_environment_b.robot
You could use Arguments file that will have different Environmental variables, You could use something like
QA.args
--variable Enviroment:http://sample.url/QA:1111
--variable USER:John
--variable PASSWORD:John
Then in your Robot.test
*** Test Cases ***
Run Argument File
Go To ${Enviroment}
Login With User ${USER} ${PASSWORD}
NOTE: This is just an example of the argument file use Login with User is not an actual keyword
And then execute command
robot --argumentfile "QA.args" tests
You can also overwrite the variables on the command line.
robot --argumentfile "QA.args" --variable Enviroment:http://sample.url/Staging:1111 tests
You could use a variable in the name of import file.
Set the value of the variable from pom.xml file in case you are using maven.
Something like below, where ${PLATFORM} is a variable :
*Settings*
Resource ../platforms/settings_${PLATFORM}.tsv
Resource ../platforms/settings_default.tsv
*Variables*
${PLATFORM} ${ENV_PLATFORM}
Below is snippet from POM.xml
....
<env.platform>Platform1.</env.platform>
....
<configuration>
<variables>
<param>ENV_PLATFORM:${env.platform}</param>
</variables>
</configuration>
....
Also, this way you can pass the value of platform from jenkins (if used)
using -Denv.platform=Platform_5
I dont think conditional imort is possible in Robot Framework in the way you liked.
However,what you can do is instead of importing envorimnent file as resoucres , you can pass them to your test as --variablefile
How i will do it?
variables_url_environment_a.py
msg='env a'
variables_url_environment_b.py
msg='env b'
Test.robot
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
Now just run your test suite as per the enviroment you need by creating a simple python script.
Python_run_script
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
For more information about how to use --variablefile , you can also refer below url
https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/
Run Keyword If '${VAR}' == 'iOS' Import Library a.py

Spring Restdocs source gradle build fails during test

I have downloaded a copy of the 1.1.0-RELEASE tagged source code for Spring RESTdocs, but "gradlew build" is failing during the test phase. 273 of 502 tests are failing with variations on this error:
org.springframework.restdocs.request.RequestPartsSnippetTests > requestPartsWithOptionalColumn[Markdown] FAILED
java.lang.AssertionError:
Expected: is adoc snippetPart | Optional | Description
---- | -------- | -----------
a | true | one
b | false | two
but: was:Part | Optional | Description
---- | -------- | -----------
a | true | one
b | false | two
The problem looks to be that the string "adoc snippet" is prefixed to the start
of the expected output. I don't think that's right, although I can see in the AbstractContentSnippetMatcher.describeTo() why it's happening and it doesn't look very conditional so maybe it's the test's actual result that's wrong?
I have made no changes to the source code* but I don't see other people reporting this problem, so I'm mystified. I'm entirely new to gradle. Is there some kind of config I need to set up to make the tests pass? Should I be using a different target?
(OK... 1 teensy change: I removed the new-line-at-end-of-file check from the checkStyle - I'm downloading from Github onto a Windows PC.)
The problem is that the files in the zip have Unix-style line endings but, when run on Windows, Checkstyle and the tests expect Windows-style line endings.
Typically a Windows Git client will take care of this for you by converting the line endings when you check out the code. For example, the default configuration of Git for Windows is to check code out with Windows-style line endings but commit changes with Windows-style line endings.
You may be able to find a Windows utility that will batch-convert the line endings from LF to CRLF. Failing that, it's probably easiest to install a Git client (such as Git for Windows that I linked to above), ensure it's configure to perform line ending conversion, and then:
> git clone https://github.com/spring-projects/spring-restdocs
> cd spring-restdocs
> gradlew build

Using CleanroomLogger in a Swift script fails to resolve DefaultLogConfiguration

I'm just starting to play with Swift 2.0 for scripting and running into an issue with symbols being resolved.
Using Carthage I bootstrap from a Cartfile containing
github "emaloney/CleanroomLogger"
I am able to get CleanroomLogger working inside of Playground by:
Create a Workspace inside of XCode 7.1.1
Add the CleanroomLogger.xcodeproj file from ./Carthage/Checkouts/CleanroomLogger
Create a new Playground in the project
Inside of the playground I enter the code
import CleanroomLogger
var logConfig = DefaultLogConfiguration.init(minimumSeverity: LogSeverity.Debug, synchronousMode: true)
Log.enable(logConfig)
Log.debug?.message("Sample message sent to debug")
Log.debug?.value("Sample value sent to debug")
This plays without error. I only see () as the output in the playground next to each Log.debug? call which is expected. If I open up the Console app I see two entries:
11/20/15 10:33:51.455 PM Cleanroom Logger[70056]: DEBUG | <EXPR>:5 — Sample message sent to debug
11/20/15 10:33:51.455 PM Cleanroom Logger[70056]: DEBUG | <EXPR>:6 — <String: "Sample value sent to debug">
So clearly I have CleanroomLogger checked out and properly built at this point.
I proceed to try and use Cleanroom Logger from a script logger-demo.swift located in the same directory as my Cartfile. This script is identical to the playground code with the addition of the shebang at the start
#!/usr/bin/env swift -F Carthage/Build/Mac
import CleanroomLogger
var logConfig = DefaultLogConfiguration.init(minimumSeverity: LogSeverity.Debug, synchronousMode: true)
Log.enable(logConfig)
Log.debug?.message("Hello from inside my Mac")
Log.debug?.value("This is a test of value")
Running the script results in the following output:
$ ./logger-demo.swift
LLVM ERROR: Program used external function '__TMdV15CleanroomLogger23DefaultLogConfiguration' which could not be resolved!
Why would this resolve in a playground but not from a swift script?
Wow, that sounds complicated ...
Maybe try SwiftyBeaver logger for Swift 2 instead. It is simple(!), supports colors, is fast & is much more feature-complete.
P.S.: I am the creator :)

Why can't I debug my puppet code?

I'm learning Puppet and the biggest frustration I have with the entire paradigm is the try/run/fix development process I'm using to build functional Puppet code. My background is in Java and I'm naturally use to debugging my code to find errors instead of just running the program to see where it bombs making development much faster but I can't seem to find a way to do this using Puppet and Eclipse. I know writing a debugger for Puppet would require some creativity given its nature but I think this is something the community could really benefit from.
I've written debuggers and know the Eclipse SDK but unfortunately it does not map cleanly to the Puppet architecture which is a bit awkward in the sense its runtime stack and execution flow does not happen in natural order as well as the fact the runtime requires a target machine to apply changes on.
I'm curious if the community has done any development work on trying to create some kind of debugger where code can be stepped. To write this I think it would make sense to extend Eclipse with a new Puppet debug configuration type where you specify a target sandbox host to test your code as well as a puppet project in your workspace you want to debug (leveraging existing Gepetto tooling). Then when you start a new Puppet debugging session Eclipse could connect to the remote host, execute puppet apply with some additional debug arguments and somehow provide feedback from the runtime about what line of code is currently being executed.
This still might be awkward but would allow puppet developers to quickly see things like oh duh.. I can't create this directory because the parent path does not exist, wait... why is this if statement not going here like I planned, oh I see here that Puppet is not very clear on single or double quotes or now I see why this fails because this class was not executed first etc. etc.
Instead all we get is a big ugly output on the agent console that yes can give us insight on errors but does not cleanly map exceptions to our code that in my view shows an underlying pain and weakness of Puppet, can you at least give me a stack trace and line number so I know where to look? Nope sorry.
Don't get me wrong, I love how Puppet can make me look very productive throughout the work week when all I'm doing is running Puppet apply on new machines which my manager has not yet figured out but I think for Puppet to really be useful this lack of debugging support is something that needs to be addressed.
Does anyone else feel this pain? - Duncan Krebs
It would be impossible to "step through" puppet code, unless you want to debug against the ruby codebase itself. It's not just that the order of "execution" is unclear, its that the manifest themselves are never executed at a single time. They are actually evaluated in multiple phases throughout execution.
There are ways to simplify finding problems though. The biggest one is writing unit tests using rspec-puppet. It lets you essentially test the compilation phase of puppet, helping you catch errors like circular dependencies, incorrect conditional logic, etc.
There is a new tool called the puppet-debugger which allows you to set breakpoints in your puppet code in order to step through it. So this is no longer "impossible" as it has been available for about 8 months.
You will first need to install the puppet-debugger gem
https://github.com/nwops/puppet-debugger
Then install the debug module, include it in your fixtures or just ensure it is in your module path.
https://forge.puppet.com/nwops/debug
Then just set a breakpoint in your code using debug::break() function.
Ruby Version: 2.0.0
Puppet Version: 4.9.4
Puppet Debugger Version: 0.6.0
Created by: NWOps
Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "classes",
"play", "classification", "types", "datatypes", "reset", or "help" for more information.
>> $vars = ['one', 'two', 'three']
=> [
[0] "one",
[1] "two",
[2] "three"
]
>> $vars.each | String $var | {
debug::break()
notify{$var:}
}
From file: puppet_debugger_input20170417-97123-qjwbaj.pp
1: $vars.each | String $var | {
=> 2: debug::break()
3: notify{$var:}
4: }
1:>> $var
=> "one"
2:>> exit
From file: puppet_debugger_input20170417-97123-qjwbaj.pp
1: $vars.each | String $var | {
=> 2: debug::break()
3: notify{$var:}
4: }
1:>> $var
=> "two"
2:>> exit
From file: puppet_debugger_input20170417-97123-qjwbaj.pp
1: $vars.each | String $var | {
=> 2: debug::break()
3: notify{$var:}
4: }
1:>> $var
=> "three"