Cucumber after each test I need to run a specific scenario, same as Background. Background is for before each, do we have similar for after each - automation

Groups page functionality
Background:
Given When the user logs in
Then add the test group
#smoke
Scenario: Verify the groups list page
When the user opens the groups page
Then the group's page title should be visible

Cucumber does not have an after hook like background, but there is a workaround: if you want to run a after hook for a specific feature file then add a tag to the feature file, and then use that tag to write an after hook in the env file.
The given example is for capyabra with ruby
Test.feature
#test_tag
Feature: test feature file
env.rb file
After('#test_tag') do
# code for after hook
end
If you want to run an after hook for a specific scenario, use the same method. Add a tag for the scenario and pass it in after hook.
After('scenario1') do
# code
end
If you want a general after hook to run after every scenario, then we can directly write the After hook without tag
Example:
After do
# code
end
Note: The scenario parameter passed gives information for the scenario e.g scenario.failed? to check if the scenario ran successfully if you want to run logic not associated with scenario details in the After hook you can omit the parameter
Example:
After do|scenario|
if scenario.failed?
page.save_screenshot("path_#{scenario.name.parameterize}.png")
end
end

Related

Blocking some GTM tags when running TestCafe tests - use the dataLayer?

Wondering the best way to prevent a GTM tag from firing. I found https://rbardini.com/automating-gtm-data-layer-tests/ which tags about fetching the dataLayer variable and comparing it in an assertion, but this looks like a clumsy approach when you want to write to the dataLayer on every page.
For example, it suggests:
const getDataLayer = ClientFunction(() => window.dataLayer)
We use Google Tag Manager to automatically load tags on our website. Unfortunately one of them is CloudIQ (from PayPal) which pops up an iframe overlay offering a newsletter signup or ability to save your shopping basket. The Trigger in our GTM setup for that tag is simply 'All Pages'. When it pops up it generally blocks our test because Selectors cannot be clicked.
Our page flow is over several pages of an online shop, e.g.:
visit home page, click a product - navigates to a product page
click some options on the product page, then add to cart
go through checkout flow
So there might be many pages visited due to click actions.
There is an ability in GTM to define Variables and then use them in Exceptions for a tag, so I could prevent the CloudIQ tag firing either via a/ a global variable or b/ a dataLayer variable. However, I can't see how to elegantly get these set for each page visited during my test, such that they would exist when the GTM examines variables in order to block a Tag from being loaded. Fixture.beforeEach isn't right because it would only run once per fixture, and any data it set on the page's scope would be lost as soon as a page navigation occurs.
Anyone got experience of this sort of thing?
(The alternative of course is to detect the overlay, use switchToIframe to switch into the CloudIQ iframe and close it manually, but it pops up quite erratically and I'd prefer to simply disable the Tag altogether during tests as it's not core functionality of our website that we need to test.)
One way would be to set a custom user agent string to your test suite, create a custom javascript variable that returns the value for navigator.useragent, and make an exception trigger that blocks the tag.
Or any variation on that theme - set a cookie, use a url parameter, or if you test suite allow inject a global js variable, and check for the value in an exception trigger.
There is no need to avoid firing of events on the client side. Just mock the service routes for Google Tag Manager and CloudIQ and imitate correct responses for them.

Is the Selenium IDE test case property "Title" accessible to my script?

For example, if I create a new test case in the IDE, and it appears in the left hand side window pane, then right click that test case and chose "Properties", there are two properties available ... one of them is "Title".
The IDE allows one to create separate titles for each test case, even if you have included the same test case twice.
For example, I might have a script where I want to login twice (just an example only to serve the purpose of this question).
I could provide a title for the first instance of the login.html test case as "1st login", then add some test case, logout, and login again ... then title the second instance of the login.html test case as "2nd Login".
This is very handy. However, I want to be able to access the title value in the test itself. In that way, I might know that I am on the first or second instance of the same test case file.
I know some of you may have other opinions about how to accomplish the goal, but keep in mind, I am only using this as an example ...
I want to find out if the "Title" is available to me programmatically during a test run.
I'm not sure I understand your question, but maybe this can help.
"storeLocation" command is useful to store current selected window's URL in selenium IDE. The web application's URL will be stored into variable "varTitle1" and you will be able to use that variable value anywhere in your script.
*Command - Target*
open - https://www.google.com
storeLocation - varTitle
echo - ${varTitle}
"storeTitle" command is storing title of current opened software web application's title. It will store current selected windows title in to variable "varTitle2".
Command - Target
open - https://www.google.com
storeTitle - varTitle2
echo - ${varTitle2}

Is there a way to get a QTP to fail a test if a particular element appears on a web page

I am trying to test a JSP based web application with QTP. On some of the pages the JSP is coded to return a particular div element, which will have an ID attribute, to the browser, only of the underlying model has a certain boolean flag set. I'd like to be able to develop a QTP test that fails if the div is present in the returned web page. However, the QTP documentation doesn't seem to have any details on how to do this.
The point is to detect if the condition applies and then explicitly fail the test.
If Browser("b").Page("p").WebElement("html tag:=div", "html id:=theId").Exist Then
''# Report failure
Reporter.ReportEvent micFail, "Element Exists", "It shouldn't"
''# if you also want to stop the test
ExitTest
End If
The default behavior for QTP is to write in 'Report' when a check point fails. i.e. if an element is not found on the page , automatically the QTP will write in the log report. In order to disable that , and to customize your report depending on your test scenarios, you can disable the report logging from the
beginning and write only in case you found an abnormal behavior.
Reporter.Filter = rfDisableAll
'check point validations
Reporter.Filter = rfEnableAll

How can I display Joomla modules within a component?

I have a component with several categories of games and I want to display a different banner depending on the category. I need the banner (and link) to be customizable so it's not simply a case of showing categoryX.jpg or whatever.
I saw this Joomla help page on another question, but it only seems to display a module type, not one specific module. I'd like to use various mod_custom modules and display the one appropriate to the category (I can store each module's ID if necessary).
Any ideas?
This can be done in a 2 step process:
Use the "Load module into article" plugin to allow yourself to access the module using a plugin call like:
{module [*mod_id*]} // where *mod_id* is the module id
Now that you can call a plugin to put your module anywhere, you now need to go to the view code of your/a component you wish to add the module to and add this code:
echo JHTML::_('content.prepare', '{module [*mod_id*]}');
Please see this link - http://www.alltogetherasawhole.org/group/developers/forum/topics/running-joomla-content-plugins - regarding point number 2. I was trying to do the same thing and I found it didn't work, and the reason for this was a comment you can find on the page link above:
"I noticed that some plugin actually expect option=com_content for them to process onPrepareContent properly, so you might actually want to "fool" them by callin JRequet::setVar and restoring the correct values after the trigger."
If you would like to show module within PHP code then use this code, it's worked for me :
<?php echo JHTML::_('content.prepare', '{loadposition position-2}'); ?>
If you want to show module inside html content then just put this code where you want to show module.
{loadposition position-2}
It loads all modules which are assigned to position-2.
You can also use the Joomla Module Renderer
$doc = JFactory::getDocument();
$renderer = $doc->loadRenderer('modules');
$position = 'custom_position_name';
$options = array('style' => 'raw');
echo $renderer->render($position, $options, null);
Just a heads up, Along with being assigned the module position, that module also has to be set to "Display on All pages".
Joomla has this functionality built in. You can use the {loadposition XX} command within your content items. You can specify custom module positions that do not appear in your template to insure that you have the correct module in the correct article.
http://docs.joomla.org/How_do_you_put_a_module_inside_an_article%3F
You could create a new module?
If each category appears in the querystring (catid=X) then you could take a similar approach to https://support.pillwax.com/open-source/doku.php?id=joomla:header_image.
Alternatively, that link might actually do it for you.

Fitnesse test suite with variables

Is it possible to set up a variable within the test suite so that it can be passed down to the setup fit page as a parameter value?
Sure. Use a !define xxx {yyy} on the suite page and a ${xxx} on the SetUp page. Make sure the SetUp page and all the test pages are children of the Suite page.
Have a look at the FlowFixture, this contains the keyword name.
More info at: http://www.syterra.com/FitnesseDotNet/NameKeyword.html