RSpec: How to get example metadata before running suite - testing

I'd like to get the metadata for the examples in my suite before running it. I want to parallelize my test suite based off of tags. Anyone know how to get this data during something like RSpec.configure?

I don't see a way to do this while running the suite. You could conceivably create a custom formatter and run the suite with rspec --dry-run --format=MyFormatter, capture the output, extract the metadata and then do what you want with it. Unfortunately it appears the built-in JSON formatter does not output example metadata.
More info on formatters in the RSpec docs.

You can do this by inspecting,
RSpec.current_example.metadata
so for example, to detect if javascript is enabled:
def js_true?
RSpec.current_example.metadata[:js]
end

Related

In TestCafe, there is a way to get a list of all test cases of a project filtering by metadata

I need the information of an specific set of tests before running them. Can be all available tests, of some tests with a certain parameter in metadata.
Something like:
[Test xxx] - Perform actions......
[Test xxx] - Something ....
Environment details:
testcafe version: 1.8.1
node.js version: 10.16.1
What I've done is output data from the filter method, which provides pretty much any information about the test (before running) that you can get.
At that point, you can use that information to only run specific tests, or return true to not filter anything and only use the filter method for printing information.

Integration between Rally and Robot framework?

Does anybody know of an integration between Rally ALM and robotframework?
I'm looking for something that would log test results in robotframework back to Rally test cases.
With the pyral rally module for Python, seems like it could be fairly straightforward.
As far as I can tell there is nothing out there to do this-- but its pretty easy to do, only needing about 50 lines of python code for a simple integration that logs robot framework to Rally test case results.
In my case, I have it log results for any test who's name starts with a Rally test case id: (e.g. "TCXXXX My Test Name").
The trick is to user the RobotFramework listener API (See: Elapsed time and result of a test in variables) and pyral, the Rally python API. Key for my needs was to define an "end_test" listener:
def end_test(self, name, attrs):
match = re.search('^(TC\d+)\s*(.*)', name)
tcId = match.group(1)
testName = match.group(2)
if tcId:
tcr = self.__logTestCaseResultToRally(tcId, testName, attrs)
self.__cleanTestCaseState()
In robotframework, I include this listener file, which also has some additional methods to add attachments and other information like notes to a test result (these can be directly called as libraries in your robotframework file):
def addAttachment(self, attachment):
if os.path.isfile(attachment) and os.access(attachment, os.R_OK):
self.attachments.append(attachment)
This method simply saves the attachment path in the listener object so that when end_test() is called, it has access to the file names to attach to the rally test case. __cleanTestCaseState() zeros these out so they are cleared before the next test cast starts.
Actually, I've never used Rally!
But in my opinion, With robot framework, I like using Testlink for testcase management system & jenkin for CI control system :)
You can search in the internet for installation.
Hope it useful :)

I want to start at the same time more than one cucumber test with the help of watir-webdriver using tags. How can I get(start) it? Is it possible?

How can I get start it? Is it possible? Can you give me some simple example?
For example i use following command to launch defined tagged tests:
parallel_cucumber features/ -p [#critical]
And all tests are launched after that, including untagged.
The solution was found :
parallel_cucumber features --test-options '--tags #critical' .
Only features with tags #critical will be launched in this case.

Selenium Test Suite: differing paths to test cases

I have a test suite that does the following
log in
do tests
log out
since I want to reuse log in and log out with other test suites I moved them into a separate folder and referenced those test cases in the href field e.g.
a href="..\lib\fLogIn.html"
Selenium however raises an exception that it can't find the file in question.
I tried all sorts of URLs, e.g.
file:///E:\absolute\path\lib\fLogIn.html
file:///E:/absolute/path/lib/fLogIn.html
../lib/fLogIn.html
..//lib//fLogIn.html
..\lib\fLogIn.html
etc.
I even tried to access them through a webserver.. no success.
Does anyone have an idea as to how this can be solved?
I really want to reuse test cases.
Thanks a lot
Juergen
PS: forgot to add: I am using Windows OS
Try to move all the reusable functions to an upper level class and using them accordingly.

Using environment vars in non-rails cucumber test

I created a simple smoketest for a portal running java/tomcat/jahia (cms) fronted by cache servers and big ip. Cucumber + Webrat + Mechanize is a good fit for a simple smoketest of this setup. (and it has been very easy to get started).
Right now I have hardcoded into /features/support/paths.rb the following lines:
module NavigationHelpers
#PATH="http://production-environment"
#PATH="http://staging-environment"
#PATH="http://test-environment"
PATH="http://localhost:8080"
#
def path_to(page_name)
case page_name
when /the homepage/
"#{PATH}/"
when [...]
...
end
end
end
World(NavigationHelpers)
Right now I manually switch the comments when I want to test different environments. The issue here is I'd love to get rid of the constant PATH and put a default value inside one of the support files. And i also want to be able to feed cucumber with this environment variable from the command line like so:
cucumber ENV=staging
How do you cope with this issue? Any suggestions? Links to code that deals with this? Snippets?
You can pass environment variables to Cucumber like you have done with ENV. Each environment vriable will then be available in Ruby's ENV constant. More details in the Wiki
(I just added this page - the feature has been around since 0.3.90 but was only ever mentioned in the History.txt file).