TypeError: Cannot read property 'alertIsPresent' of undefined - protractor

If i use
var Alerts = protractor.ExpectedConditions;
browser.wait(protractor.ExpectedConditions.alertIsPresent(), 1000);
i am getting error like below
TypeError: Cannot read property 'alertIsPresent' of undefined
Please help me how to wait till alert is present without browser.sleep();

Const EC =require('protractor').ExpectedConditions;
browser.wait(EC.alertIsPresent(), 5000);
Protractor documentation

Related

discord.js find and edit messages in dm

i'm trying to find message in dm and edit it via discord.js but i'm unable to do
my code:
const User = client.users.cache.get(usrid);
if (!User.dmChannel) return console.log("No messages found.");
// Getting the message by ID
User.dmChannel.messages.fetch(lastmsgid).then(dmMessage => {
// Editing the message.
dmMessage.edit(`${dmMessage.content}\n${messageToSend}`);
Error:
readline.js:1147
throw err;
^
TypeError: Cannot read property 'dmChannel' of undefined
at C:\Users\Shankar\Desktop\bot\Disgd-hax\index.js:29:35
at Interface._onLine (readline.js:327:5)
at Interface._line (readline.js:658:8)
at Interface._ttyWrite (readline.js:1003:14)
at ReadStream.onkeypress (readline.js:205:10)
at ReadStream.emit (events.js:315:20)
at emitKeys (internal/readline/utils.js:335:14)
at emitKeys.next (<anonymous>)
at ReadStream.onData (readline.js:1137:36)
at ReadStream.emit (events.js:315:20)
if usrid is used correctly and is a user id, it mean that you are currently fetching the userid and getting user result not a dm channel or a dm message, to be able to do such that.
I suggest using the messages.fetch method mentioned here

resolveLocalFileSystemURL TypeError: Cannot read property 'then' of undefined TypeError

I am working on ionic 4 ( capacitor ). I am trying to resolve a local file system URL so I used this function resolveLocalFilesystemUrl but unfortunately, I am getting this error
TypeError: Cannot read property 'then' of undefined TypeError: Cannot read property 'then' of undefined
This is my code:
constructor(private _file: NativeFile) {}
...
..
this._file.resolveLocalFilesystemUrl(nativeFilePath).then((entry: Entry) => {
console.log(entry);
});
Note that this function returns a promise
Be sure that you are using the right plugin. This is the one you need: https://ionicframework.com/docs/native/file
import { File } from '#ionic-native/file/ngx';
...
constructor(private _file: File) { }
this._file.resolveLocalFilesystemUrl(nativeFilePath).then((entry: Entry) => {
console.log(entry);
});
Edit
Are you sure the method returns a promise? According to some documentation, the method accepts a callbakc function. So your code will be something like:
this._file.resolveLocalFilesystemUrl(
nativeFilePath,
(entry: Entry) => console.log(entry),
err => console.log(err)
);
EDIT 2
I am working on a cordova based project (Ionic 4) an I am using the officially suggested plugin: https://ionicframework.com/docs/native/file . It is also supported in capacitor projects.
Form the official documentation:
You also need a FileEntry object to read an existing file. Use the
file property of FileEntry to get the file reference, and then create
a new FileReader object. You can use methods like readAsText to start
the read operation. When the read operation is complete, this.result
stores the result of the read operation.
function readFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
console.log("Successful file read: " + this.result);
displayFileData(fileEntry.fullPath + ": " + this.result);
};
reader.readAsText(file);
}, onErrorReadFile);
}
Official Ionic Documentation
Official plugin documentation
I had the same problem but I found the solution!
Have you installed the ionic native file plugin?
I dont know capacitor but with cordova :
ionic cordova plugin add cordova-plugin-file
If you get this error message:
TypeError: Cannot read property 'then' of undefined TypeError: Cannot read property 'then' of undefined
The plugin probably does not have permission to access the storage, resulting in all functions and properties returning undefined.
Have you added the needed permission to config.xml?
<preference name="AndroidPersistentFileLocation" value="Compatibility" />

Failed: Cannot read property 'bind' of undefined with Expected Conditions

My script failed at the expected conditions at this line:
let condition = EC.presenceOf (title_css);
The error message:
Failed: Cannot read property 'bind' of undefined
I tried an equivalent script in selenium Java and it works. But I am wonder why this fails in Protractor. I am new to Protractor and wonder if ExpectedConditions do not work for non angular.
var title_css = "h1[ng-bind='::$ctrl.primaryText']"
describe ("Protractor test demo", function(){
it ("testing site", function (){
browser.get('https://www.eat24.com/')
let EC = ExpectedConditions;
var title_css = by.css (title_css);
let condition = EC.presenceOf (title_css);
browser.wait(condition, 30000)
})
})
ExpectedConditions in Protractor should accept css like in Selenium / Java?
change the EC to EC = protractor.ExpectedConditions;
then the presenceOf part browser.wait(EC.presenceOf(element));
Also this condition will return a promise that needs resolving
I suggest you to read protractor API documentation first. you'll see protractor has different syntax
A few problems I noticed in your code
let title_css = "h1[ng-bind='::$ctrl.primaryText']" // I assume you verified it works
describe("Protractor test demo", function() {
it("testing site", function () {
browser.get('https://www.eat24.com/')
let EC = protractor.ExpectedConditions; // ExpectedConditions may be available as a global variable, may not, so to be safe do it this way...
let title_element = element(by.css(title_css)); // syntax is element(by.strategy(locator))
let condition = EC.presenceOf(title_element);
browser.wait(condition, 30000)
})
})
If you solve your problem, your next problem will be Promises, I can guarantee you that. So read how to handle them

Cannot read property 'sPath' of undefined error while performing .read() method

I am confused with the error I get while trying to do .read() method of the odata model.
Here is my model definition:
var oModel = new sap.ui.model.odata.ODataModel("/destination/sap/opu/odata/sap/ODataServer");
this.getView().setModel(oModel, "odata");
Here is the relevant method:
_read: function(aFilters) {
var oModel = this.getView().getModel("odata");
console.log("oModel",oModel);
oModel.read("/myEntitySet", {
filters: aFilters,
success: function(oData) {
console.log("oData",oData);
},
error: function(oError) {
console.log("oError",oError);
}
});
}
The model is defined and is displayed in console.
In the line where the .read() method is, I get the following error:
Uncaught TypeError: Cannot read property 'sPath' of undefined
I have never seen such behavior before. What do I do wrong?
I had an error in my aFilters array. Well,the problem was that aFilters wasn't array at all. After fixing this issue, the .read() method worked fine.

Why when I click on the update button error TypeError: r is undefined happen?

The error in firefox browser as follows: TypeError: r is undefined
This is the chrome browser:
Uncaught TypeError: Cannot read property 'data' of undefined
I also did a video for a better understanding.
The error occurs when I changed the values ​​in a field
jsfiddle code
youtube video
button code update
save: function (e) {
var that = this;
$.ajax({
url: '/api/apdevice',
type: e.model.id == null ? 'POST' : 'PUT',
contentType: 'application/json',
data: JSON.stringify(e.model),
success: function (data) {
alert('yes');
that.refresh();
},
error: function (data) {
alert('no');
that.cancelRow();
}
});
}
The reason for this is because your datasource's update method is being called. It has not been set which gives you the TypeError.
You can do one of two things.
Set the update method of your datasource to contain the logic contained in your save function. You'll need to set update as a function in order to be able to control the method dynamically (POST/PUT). You should remove the ajax code from the save event at this point.
Set the update method to a dummy function and handle it as part of the save event instead.
Here's an example of approach #2.
var dataSource = new kendo.data.DataSource({
..
update: function(e) { return true; }
..
});
Keep the save event function as is.
Note that I'm getting an Uncaught SyntaxError: Unexpected number error. I believe this is originating from the LastClientsCount property.
Fiddle: http://jsfiddle.net/mSRUe/23/