How to get scenario name using CodeceptJs and Cucumber - cucumberjs

I am using CodeceptJs with cucumber helper. For reporting options need to get Scenario name in Before section.
Trying to use this documentation: https://codecept.io/bdd/#before
So in
Before(() => {
console.log(Scenario.name)
});
Have nothing in console log.

Related

Cannot do drag and drop test in cypress

How to automate the drag and drop feature in an application using cypress?
I am not able to pick a file using cypress. I have tried using cypress-file-upload
there are some solutions:
First option: I recommend using cypress-drag-drop plugin you can know more about this option in the following link https://github.com/4teamwork/cypress-drag-drop
Second option: You can use cypress-file-upload plugin you can know more about this option in the following link https://www.npmjs.com/package/cypress-file-upload in this case you will need to something similar to:
cy.get('your-element').attachFile('myfixture.json', { subjectType: 'drag-n-drop' });
or
cy.get('your-element').attachFile('image.jpg',
{
subjectType: 'drag-n-drop', events: ['dragenter', 'drop']
})
Third option: You can check this article in the following link where the author have created a new command from scratch: https://jayashanigunarathne.medium.com/uploading-drag-drop-images-in-cypress-943c9db9957e

Cypress: capture and log all XHR requests to a file

Using Cypress to test a web app, I have tests failing because of an unexpected XHR response from our test backend.
The screenshots and screencasts doesn't help understanding why we get this error message from the webapp. It would be very useful to get the actual XHR requests logs as an artifact.
It seems to be possible to capture some routes using cy.route, but it seems to be more suitable to stub requests.
What is the correct way to capture and write the XHR logs alongside the screenshots and videos ? It would be even better if it would delete the file if everything passes.
To record the network traffic in the same manner like the network tab in devtools, you can utilize the HAR file format (http://www.softwareishard.com/blog/har-12-spec/). To generate a HAR file during the execution of your Cypress tests you can use the cypress-har-generator plugin.
describe('my tests', () => {
before(() => {
// start recording
cy.recordHar();
});
after(() => {
// save the HAR file
cy.saveHar({ waitForIdle: true });
});
it('does something', () => {
cy.visit('https://example.com');
// ...
});
});
It will save a HAR that can be used to inspect the network activity, identify the performance issues or troubleshooting bugs. The file can be skimmed using any kind of viewer (e.g. https://developer.chrome.com/blog/new-in-devtools-76/#HAR).

custom matchers how to load in jasmine-node?

I am using jasmine-node and want to reuse some custom matchers I have been using with karma. I cannot find how to load my custom matchers...
Using karma and jasmine 2.4 I can load them this way:
beforeEach(function () {
jasmine.addMatchers(customMatchers);
});
But using jasmine-node it is not working.
I must be missing something because jasmine itself is actually undefined..Can some please guide me in the right direction? Thank-you

Failed to run custom step with the selenium cucumber ruby

I am writing a test for desktop web automation using the
selenium cucumber ruby.
My test includes both predefined and custom steps.
However, my test fails to run due to an error caused by a custom step.
The feature file that I run:
Feature: Login a customer
Scenario: Go in a call
Given I navigate to <url>
...
When I submit the form with id "custSearchSimple"
....
And I wait for 5 sec
Then element having id "accNumber" should be present
The When I submit the form with id "custSearchSimple" is a custom step.
This step is defined in the custom_step.rb. I have used the submit command of the Selenium Cucumber Ruby API. The custom_step.rb is the following file:
require 'selenium-cucumber'
# Do Not Remove This File
# Add your custom steps here
# $driver is instance of webdriver use this instance to write your custom code
#firefox browser instantiation
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "https://localhost/telebet"
When(/^I submit the form with id "(.*?)"$/) do |arg1|
element= driver.submit(:id,"#{arg1}")
end
When I run the feature file by running cucumber features/name_of_the_file.feature, I get the NoMethodError error:
When I submit the form with id "custSearchSimple" # features/step_definitions/custom_steps.rb:12
private method `submit' called for #<Selenium::WebDriver::Driver:0x94c4bde4bdff4d6 browser=:firefox> (NoMethodError)
I could not find any example using the Selenium Cucumber Ruby API for writing custom steps. I suspect that I might have omitted some commands for the selenium web driver ruby. Something is missing that I could not find. Does anyone know why I get this error?
Maybe I am confused here but:
When(/^I submit the form with id "(.*?)"$/) do |arg1|
submit_form arg1
end
def submit_form(form_id)
submit("id", form_id)
end
Would do what you want? submit_form isn't a cucumber step, it's a ruby method - probably why you're getting Cucumber::UndefinedDynamicStep.

Unable to get jasmine-jquery fixtures to load in Visual Studio with Chutzpah, or even in browser

I'm prototyping a MVC.NET 4.0 application and am defining our Javascript test configuration. I managed to get Jasmine working in VS2012 with the Chutzpah extensions, and I am able to run pure Javascript tests successfully.
However, I am unable to load test fixture (DOM) code and access it from my tests.
Here is the code I'm attempting to run:
test.js
/// various reference paths...
jasmine.getFixtures().fixturesPath = "./";
describe("jasmine tests:", function () {
it("Copies data correctly", function () {
loadFixtures('testfixture.html');
//setFixtures('<div id="wrapper"><div></div></div>');
var widget = $("#wrapper");
expect(widget).toExist();
});
});
The fixture is in the same folder as the test file. The setFixtures operation works, but when I attempt to load the HTML from a file, it doesn't. Initially, I tried to use the most recent version of jasmine-jquery from the repository, but then fell back to the over 1 year old download version 1.3.1 because it looked like there was a bug in the newer one. Here is the message I get with 1.3.1:
Test 'jasmine tests::Copies data correctly' failed
Error: Fixture could not be loaded: ./testfixture.html (status: error, message: undefined) in file:///C:/Users/db66162/SvnProjects/MvcPrototype/MvcPrototype.Tests/Scripts/jasmine/jasmine-jquery-1.3.1.js (line 103)
When I examine the source, it is doing an AJAX call, yet I'm not running in a browser. Instead, I'm using Chutzpah, which runs a headless browser (PhantomJS). When I run this in the browser with a test harness, it does work.
Is there someone out there who has a solution to this problem? I need to be able to run these tests automatically both in Visual Studio and TeamCity (which is why I am using Chutzpah). I am open to solutions that include using another test runner in place of Chutzpah. I am also going to evaluate the qUnit testing framework in this effort, so if you know that qUnit doesn't have this problem in my configuration, I will find that useful.
I fixed the issue by adding the following setting to chutzpah.json:
"TestHarnessLocationMode": "SettingsFileAdjacent",
where chutzpah.json is in my test app root
I eventually got my problem resolved. Thank you Ian for replying. I am able to use PhantomJS in TeamCity to run the tests through the test runner. I contacted the author of Chutzpah and he deployed an update to his product that solved my problem in Visual Studio. I can now run the Jasmine test using Chutzpah conventions to reference libraries and include fixtures while in VS, and use the PhantomJS runner in TeamCity to use the test runner (html).
My solution on TeamCity was to run a batch file that launches tests. So, the batch:
#echo off
REM -- Uses the PhantomJS headless browser packaged with Chutzpah to run
REM -- Jasmine tests. Does not use Chutzpah.
setlocal
set path=..\packages\Chutzpah.2.2.1\tools;%path%;
echo ##teamcity[message text='Starting Jasmine Tests']
phantomjs.exe phantom.run.js %1
echo ##teamcity[message text='Finished Jasmine Tests']
And the Javascript (phantom.run.js):
// This code lifted from https://gist.github.com/3497509.
// It takes the test harness HTML file URL as the parameter. It launches PhantomJS,
// and waits a specific amount of time before exit. Tests must complete before that
// timer ends.
(function () {
"use strict";
var system = require("system");
var url = system.args[1];
phantom.viewportSize = {width: 800, height: 600};
console.log("Opening " + url);
var page = new WebPage();
// This is required because PhantomJS sandboxes the website and it does not
// show up the console messages form that page by default
page.onConsoleMessage = function (msg) {
console.log(msg);
// Exit as soon as the last test finishes.
if (msg && msg.indexOf("Dixi.") !== -1) {
phantom.exit();
}
};
page.open(url, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(-1);
} else {
// Timeout - kill PhantomJS if still not done after 2 minutes.
window.setTimeout(function () {
phantom.exit();
}, 10 * 1000); // NB: use accurately, tune up referring to your needs
}
});
}());
I've got exactly the same problem. AFAIK it's to do with jasmine-jquery trying to load the fixtures via Ajax when the tests are run via the file:// URI scheme.
Apparently Chrome doesn't allow this (see https://stackoverflow.com/a/5469527/1904 and http://code.google.com/p/chromium/issues/detail?id=40787) and support amongst other browsers may vary.
Edit
You might have some joy by trying to set some PhantomJS command-line options such as --web-security=false. YMMV though: I haven't tried this myself yet, but thought I'd mention it in case it's helpful (or in case anyone else know more about this option and whether it will help).
Update
I did manage to get some joy loading HTML fixtures by adding a /// <reference path="relative/path/to/fixtures" /> comment at the top of my Jasmine spec. But I still have trouble loading JSON fixtures.
Further Update
Loading HTML fixtures by adding a /// <reference path="relative/path/to/fixtures" /> comment merely loads in your HTML fixtures to the Jasmine test runner, which may or may not be suitable for your needs. It doesn't load the fixtures into the jasmine-fixtures element, and consequently your fixtures don't get cleaned up after each test.

Resources