cy.get(...).selectFile is not a function Cypress - cypress

const IMAGE_INPUT = 'test-image-input';
const IMAGE_PATH = '/images/test.jpeg';
cy.get(`[data-element-id="${IMAGE_INPUT}"]`).selectFile(IMAGE_PATH, { force: true });
Returns: TypeError: cy.get(...).selectFile is not a function
I use Cypress 9.5.0, from what I know the selectFile functionality is supported since 9.3.0
I also use cypress-fail-fast 3.1.0

Related

File saver is deprecated. How to resolve this issue from SonarQube

Working on filesaver, while running SONAR QUBE it shows " 'fileSaver' is deprecated. use { autoBom: false } as the third argument "
this.http.get(`getTemplate/${doc.id}`, { responseType: 'blob' }).subscribe(
(data: any) => {
fileSaver.saveAs(new Blob([data], { type: this.fileType }), doc.docName)
error :- 'fileSaver' is deprecated. use { autoBom: false } as the third argument
Even if I use autobom:false it still shows the same
Here is the code for autobom
this.http.get(`getDocument/${doc.docId}`, { responseType: 'blob' }).subscribe(
(data: any) => {
var blob = new Blob([data], { type: this.fileType });
fileSaver.saveAs(blob, doc.docName,false);
'saveAs' is deprecated. use { autoBom: false } as the third argumentWhy is this an issue?
'fileSaver' is deprecated. use { autoBom: false } as the third argument Why is this an issue?
It should be the setting of autoBom, not just false:
fileSaver.saveAs(blob, doc.docName, { autoBom: false });
I had the same issue. I fixed by importing only the function.
For ts
import { saveAs } from 'file-saver';
saveAs(blob, doc.docName);
For js
const { saveAs } = require('file-saver');
I think that this sonar issue is because the browsers do not natively support interface.

JS: topmost() is deprecated. Use Frame.topmost() instead

I switched to Nativescript 6.3 and after that I have begun to get
JS: topmost() is deprecated. Use Frame.topmost() instead. warning. And HMR does not to seem to make the instant changes as well. For navigation among pages I use the following
code:
function onTap_StartPage() {
var navigationEntry = {
moduleName: "views/Sep-page/Sep-page",
context:{trans:language,trans2:wordGroup},
transition: {
name: "fade",
duration: 200,
}
};
frames.topmost().navigate(navigationEntry);
}
exports.onTap_StartPage= onTap_StartPage;
What changes am I supposed to make? Just adding Frame before topmost() is not working as well.
frames.Frame.topmost().navigate(navigationEntry);// is not working.
Then I tried navigation without topmost() and used the following:
const getFrameById = require("tns-core modules/ui/frame").Frame.getFrameById;
const frame=getFrameById("myFrame" );
function onTap_StartPage() {
var navigationEntry = {
moduleName: "views/Sep-page/Sep-page",
context:{trans:language,
trans2:wordGroup,},
transition: {
name: "fade",
duration: 200,
}
};
frame.navigate(navigationEntry);
}
exports.onTap_StartPage= onTap_StartPage;
Although navigation works I still get JS: topmost() is deprecated. Use Frame.topmost() instead. warning. and HMR is not working as well.

Array destructuring returned from promises not working as expected

I am using Mocha and Chai for writing tests for a smart contract deployed on the development blockchain with truffle.
I have a contract named Election which contains two candidates.
The test code is as follows:
it("Checking the properties for candidates", () => {
return Election.deployed().then((app) => {
return [app.candidates(1), app];
}).then(params => {
const [candidate1, app] = params;
assert.equal(candidate1.id, 0);
return [app.candidates(1), app];
}).then(params => {
const [candidate2, app] = params;
assert.equal(candidate2.id, 1);
});
});
The test cases pass when I am not using the array destructuring to return app.candidates() and an instance of the app. In that case I had to declare a global variable, assign it to app and use it in every scope. But I want to avoid defining a global variable. I came across this post on SO which suggests using ES6 destructuring.
But here I am getting candidate1.id and candidate2.id both as undefined.
What am I doing wrong here?
Why are you returning from an it? It's not needed, they should only throw.
I strongly recommend avoiding this .then syntax and npm i chai-as-promised --save-dev then install it like this:
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
// Must install Chai as Promised last - https://github.com/domenic/chai-as-promised/#node
chai.use(chaiAsPromised);
// Disable object truncating - https://stackoverflow.com/a/23378037/1828637
chai.config.truncateThreshold = 0;
global.expect = chai.expect;
Then you would do:
it("Checking the properties for candidates", async () => {
expect(Election.deployed()).to.eventually.satisfy(app => app.candidates(1).id === 0)
and.satisfy(app => app.candidates(2).id === 1);
});
If app.candidates returns a promise, maybe can even do this, I'm not sure about async function to argument of satisfy though.
it("Checking the properties for candidates", async () => {
expect(Election.deployed()).to.eventually.satisfy(async app => {
await expect(app.candidates(1)).to.eventually.be.an('object').that.has.property('id', 0);
await expect(app.candidates(2)).to.eventually.be.an('object').has.property('id', 1);
});
});

Testing Filter with Jasmine + Angular + Error: [$injector:unpr] Unknown provider

Here is my app.js module part
angular
.module('flickrNgSpaApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ngMock'
])
filter that I am using (flickrNgSpaApp)
'use strict';
angular.module('flickrNgSpaApp')
.filter('flickrURL', function () {
return function (input, dimension) {
var url = 'http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg';
return url.replace('{farm-id}', input.farm)
.replace('{server-id}', input.server)
.replace('{id}', input.id)
.replace('{secret}', input.secret)
.replace('[mstzb]', dimension);
};
});
And filter unit test that fails for some reason :)
'use strict';
describe('Filter: flickrURLFilter', function () {
var $filter;
beforeEach(function(){module('flickrNgSpaApp')});
beforeEach(inject(function (_$filter_) {
$filter=_$filter_;
}));
it('returns null',function(){
var input={
farm:"1",
server:"2",
id:"3",
secret:"4",
dimension:"q"
};
expect($filter('flickrURLFilter')(input, 'q')).not.toEqual(0);
})
});
and error:
Chrome 43.0.2357 (Windows 8.1 0.0.0) Filter: flickrURLFilter returns null FAILED
Error: [$injector:unpr] Unknown provider: flickrURLFilterFilterProvider
<- flickrURLFilterFilter
Could anyone take a look and give me any hints... I would be grateful! :)
Use the name of the filter, and replace $filter('flickrURLFilter') with $filter('flickrURL').

jasmine-reporters is not generating any file

i'm using jasmine-reporters to generate a report after protractor finish the tests,
this is my configuration file:
onPrepare: function(){
var jasmineReporters = require('jasmine-reporters');
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps){
var browserName = caps.caps_.browserName.toUpperCase();
var browserVersion = caps.caps_.version;
var prePendStr = browserName + "-" + browserVersion + "-";
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter("protractor_output", true, true,prePendStr));
});
},
i don't get any error, the reporters installed, but i don't see any file in protractor_output folder.
Any idea what am i doing wrong?
The problem is with the jamsine version:
If you are trying to use jasmine-reporters with Protractor, keep in mind that Protractor is built around Jasmine 1.x. As such, you need to use a 1.x version of jasmine-reporters.
npm install jasmine-reporters#~1.0.0
then the configuration should be:
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters#1.0
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true, true)
);
}
If you are on a newer version of the Jasmine Reporter, then the require statement no longer puts the JUnitXmlReporter on the jasmine object, but does put it on the module export. Your setup would then look like this:
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters#1.0
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter('xmloutput', true, true)
);
}
also you need to verify that xmloutput directory exist!
To complete the answer, if the output is still not generating,
Try adding these configuration line to your protractor exports.config object :
framework: "jasmine2",
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
.......
}

Resources