.feature file in cypress cucumber , stopped running tests because a plugin crashed - plugins

I am trying to run a .feature file in cypress cucumber. but when i run the file, getting this error.
TypeError: Cannot destructure property 'name' of '(intermediate value).parse(...).feature' as it is undefined.
following is my index.js
/// <reference types="cypress" />
/**
* #type {Cypress.PluginConfig}
*/
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
}
Can anyone please tell me what am i doing wrong?is

I had the same issue, the problem was there was a feature file without the word "feature" inside. I was not using that file because it was commented but cypress ask me for that word.

Change in your file .feature Scenario : for Scenario Outline: and run

Related

Automatically create i18n directory for VSCode extension

I am trying to understand the workflow presented in https://github.com/microsoft/vscode-extension-samples/tree/master/i18n-sample for localizing Visual Studio Code extensions.
I cannot figure out how the i18n directory gets created to begin with, as well as how the set of string keys in that directory get maintained over time.
There is one line in the README.md which says "You could have created this folder by hand, or you could have used the vscode-nls-dev tool to extract it."...how would one use vscode-nls-dev tool to extract it?
What I Understand
I understand that you can use vscode-nls, and wrap strings like this: localize("some.key", "My String") to pick up the localized version of that string at runtime.
I am pretty sure I understand that vscode-nls-dev is used at build time to substitute the content of files in the i18n directory into the transpiled JavaScript code, as well as creating files like out/extension.nls.ja.json
What is missing
Surely it is not expected that: for every file.ts file in your project you create an i18n/lang/out/file.i18n.json for every lang you support...and then keep the set of keys in that file up to date manually with every string change.
I am assuming that there is some process which automatically goes "are there any localize("key", "String") calls in file.ts for new keys not yet in file.i18n.json? If so, add those keys with some untranslated values". What is that process?
I have figured this out, referencing https://github.com/Microsoft/vscode-extension-samples/issues/74
This is built to work if you use Transifex for your translator. At the bare minimum you need to use .xlf files as your translation file format.
I think that this is best illustrated with an example, so lets say you wanted to get the sample project working after you had deleted the i18n folder
Step 1: Clone that project, and delete the i18n directory
Step 2: Modify the gulp file so that the compile function also generates nls metadata files in the out directory. Something like:
function compile(buildNls) {
var r = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject()).js
.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through())
.pipe(buildNls ? nls.createAdditionalLanguageFiles(languages, 'i18n', 'out') : es.through())
.pipe(buildNls ? nls.bundleMetaDataFiles('ms-vscode.node-debug2', 'out') : es.through())
.pipe(buildNls ? nls.bundleLanguageFiles() : es.through())
Step 3: Run the gulp build command. This will generate several necessary metadata files in the out/ directory
Step 4: Create and run a new gulp function to export the necessarry translations to the xlf file. Something like:
gulp.task('export-i18n', function() {
return gulp.src(['package.nls.json', 'out/nls.metadata.header.json', 'out/nls.metadata.json'])
.pipe(nls.createXlfFiles("vscode-extensions", "node-js-debug2"))
.pipe(gulp.dest(path.join('vscode-translations-export')));
}
Step 5: Get the resulting xlf file translated. Or, add some dummy values. I cant find if/where there is documentation for the file format needed, but this worked for me (for the extension):
<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="package" source-language="en" target-language="ja" datatype="plaintext"><body>
<trans-unit id="extension.sayHello.title">
<source xml:lang="en">Hello</source>
<target>JA_Hello</target>
</trans-unit>
<trans-unit id="extension.sayBye.title">
<source xml:lang="en">Bye</source>
<target>JA_Bye</target>
</trans-unit>
</body></file>
<file original="out/extension" source-language="en" target-language="ja" datatype="plaintext"><body>
<trans-unit id="sayHello.text">
<source xml:lang="en">Hello</source>
<target>JA_Hello</target>
</trans-unit>
</body></file>
<file original="out/command/sayBye" source-language="en" target-language="ja" datatype="plaintext"><body>
<trans-unit id="sayBye.text">
<source xml:lang="en">Bye</source>
<target>JA_Bye</target>
</trans-unit>>
</body></file>
</xliff>
Step 6: Stick that file in some known location, let's say /path/to/translation.xlf. Then add/run another new gulp task to import the translation. Something like:
gulp.task('i18n-import', () => {
return es.merge(languages.map(language => {
console.log(language.folderName)
return gulp.src(["/path/to/translation.xlf"])
.pipe(nls.prepareJsonFiles())
.pipe(gulp.dest(path.join('./i18n', language.folderName)));
}));
});
Step 7: Run the gulp build again.
The i18n/ directory should now be recreated correctly! Running the same build/export/translate/import/build steps will pick up any new changes to the localize() calls in your TypeScript code
Obviously this is not perfect, there are a lot of hardcoded paths and such, but hopefully it helps out anyone else who hits this issue.

' ReferenceError: browser is not defined ' while running cucumber-js in protractor-cucumber

I am using protractor 5.2.2. and cucumber 3.2.0.I am getting an error "browser is not defined" when i am run cucumber-js.
Feature: Login page test
Scenario: Verify whether the user is able to navigating to the login page
When I go to "https://in.linkedin.com/"
and my step code is
var {defineSupportCode} = require('cucumber');
defineSupportCode(function ({ setDefaultTimeout, Given, When, Then }) {
setDefaultTimeout(60 * 1000);
When(/^I go to "(.*)"$/, function (url, callback) {
browser.get(url).then(callback);
});
)};
It looks like cucumber is not catching the global browser variable.
To run protractor script, you need to use command like protractor conf.js no matter which test framework(jasmine, cucumber) you used.
When use cmd protractor to start running, it will load browser into Nodejs runtime's global variable.
After protractor complete load browser into global, the package protractor-cucumber-framework will generate and execute another command line which will use cucumber-js to run cucumber feature files, but now in the Nodejs runtime, global variable has browser this property and its value is not null/undefined.
That's why we have to need more two packages: cucumber and protractor-cucumber-framework

unable to specify path to javascript file in Karma

My JS file (which I need to test) is /JasmineTest/src/mySource.js. It has myObj object
myObj={
setA:function(value){
a=value;
},
getA:function(){
return a;
},
};
My Jasmine spec file is /JasmineTest/spec/mySpec.js. It tests myObj
describe("Jasmine sample suite",function(){
it("tracks that spy was called",function(){
expect(myObj.getA).toHaveBeenCalled();
});
In karma, I have specified the spec file location as
files: [
'spec/*.js'
],
when I start Karma in /JasmineTest, the test gives error
Chrome 60.0.3112 (Windows 10 0.0.0) Jasmine sample suite tracks that spy was called FAILED
ReferenceError: myObj is not defined
at UserContext.<anonymous> (spec/mySpec.js:4:9)
I tried exporting myObj module.exports = myObj; and importing it in spec file using require('../src/mySource.js') but I got error require is not defined
How do I make myObj visible in the specs file?
Karma doesn't know how to do module requiring unless you configure it specially to do bundling. In general I would expect to use the same sort of bundling in Karma as you do for your web app, so Webpack or Browserify or similar.
Another way is to list mySource.js in under the "files" field in karma.conf.js, which will just execute it and put myObj in as a global, but that doesn't scale very well.

Protractor e2e test for downloading and comparing file with browser.driver.wait is timing out

I followed the suggestions in this thread: Protractor e2e test case for downloading pdf file and the file is downloading properly, but the test is timing out before the compare/expect is reached.
var filename = 'somefilename';
var content = 'some content\r\nsome more content';
download.click();
browser.driver.wait(function() {
return fs.existsSync(filename);
}, 5000).then(function() {
expect(fs.readFileSync(filename, {encoding: 'utf8'})).toEqual(content);
});
It creates and downloads the file and then sits there for 5 seconds before continuing on. The message I get is:
Message:
Error: Wait timed out after 5000ms
Stacktrace:
Error: Wait timed out after 5000ms
at Array.forEach (native)
From: Task: <anonymous wait>
at /path/to/test/e2e/scenarios.js:337:28
at Array.forEach (native)
Where line 337 is the browser.driver.wait line.
I tried doing it without the browser.driver.wait since the download is actually very quick since the file is just two short line by doing the following:
expect(fs.existsSync(filename));
browser.sleep(5000);
expect(fs.readFileSync(filename, {encoding: 'utf8'})).toEqual(content);
but it says that the filename doesn't exist for readFileSync and I assume this is because the file is not downloaded yet and the browser.sleep(5000) doesn't do anything.
Is there another way to do promises in protractor? Or can anyone clue me in as to why this might not be working? I'm running Protractor 2.1.0. I was running 1.0.0 and updated everything before trying again, but alas, it still isn't working.
Best regards,
Julie
I figured out the problem. My filename didn't contain the path that I set in the 'default_directory' of my protractor-conf.js file. Once I put in the whole path, it worked. Boy do I feel silly!

How to run only one feature file when running protractor with cucumber?

I have multiple feature files and I would really love to run just one file or just one scenario or just one tag.
I know I could just provide one file in my specs in my cucumberConf.js, but I would like to run it once without fiddling with my cucumberConf.js.
Which arguments do I need to type in when running protractor?
in protractor's config:
cucumberOpts: {
...
tags: [
"#runThis",
"#runThat",
"~#ignoreThis"
];
...
},
in the feature file
#runThis
Scenario: Run this Scenario
Given user does some action
Then something should happen
#ignoreThis
Scenario: ignore this Scenario
Given user does some action
Then something should happen
The easiest way to do this would be to use the --specs option.
protractor --specs=specs/testA.js e2e-conf.js
use the specs array in protractor config file. E.g.
specs: [ 'test/features/xxx.feature' ],