page object - promise handling - error "Cannot read property 'submit' of undefined" - jasmine

I am trying to click on the submit button in a login screen, only if the button text shows "Next". In the last line below, I am getting the error - "Cannot read property 'submit' of undefined". I think I am not resolving promise properly in the page object. I'd appreciate it if someone could help suggest a solution..
//Login Page object
var LoginPage = function () {
this.email = element(by.model('loginCtrl.username'));
this.password = element(by.model('loginCtrl.password'));
this.submit = element(by.css('[ng-click="loginCtrl.login()"]'));
this.get = function(){
browser.get('/#/login');
};
this.login = function () {
this.email.clear();
this.email.sendKeys(browser.params.login.user);
this.submit.getText().then(function (text) {
if (text == "Next") {
//***ERROR below.
//***Cannot read property 'submit' of undefined
this.submit.click();
}
});

In this case, when inside the then() function, the this is not pointing to your page object anymore. A common approach is to create a reference to the page object in the outer scope:
this.login = function () {
this.email.clear();
this.email.sendKeys(browser.params.login.user);
var self = this;
this.submit.getText().then(function (text) {
if (text == "Next") {
self.submit.click();
}
});
}

Related

parameter is not well received in blade file from controller

I am trying to show up book in laravel. When book 1st loads it shows 1st page of book.. but when I click bookmark button it reloads page but don't show book again. I am using pdf.js .
My Javascript function:
function pdf( count , scale)
{ console.log(count);
pdfjsLib.getDocument('../uploads/{{$book->file_path}}').then (doc => {
doc.getPage(count).then(page => {
var myCanvas=document.getElementById('my-canvas');
var context= myCanvas.getContext('2d');
const viewport = page.getViewport(scale);
myCanvas.height = viewport.height;
myCanvas.width = viewport.width;
page.render({
canvasContext: context,
viewport: viewport
});
});
});
}
function bookmark()
{
var url= '{{route('save_bookmark', ['b_id' => ':b_id', 'p_no' => ':p_no'])}}';
url = url.replace(':b_id', book);
url = url.replace(':p_no', count);
document.location.href = url;
}
My route:
Route::get("save_bookmark/{b_id}/{p_no}",'BookmarkController#create')->name('save_bookmark');
My controller:
public function create($b_id, $p_no)
{
$b=new bookmark;
$b->u_id=Auth::user()->id;
$b->book_id=$b_id;
$b->p_no=$p_no;
$b->save();
$b=Book::find($b_id);
return view('pages/readbook')->with('book', $b)->with('count',$p_no);
}
Everything is working fine when book 1st opens but after bookmark click it is not finding up book.. I have tested that book and count variables are well recieved.
Error:
GET http://localhost/BookLibrary/public/save_bookmark/uploads/51312.pdf 500 (Internal Server Error)
Any suggestions??

How to get webHookUrl from Microsoft Teams connector

I’m building a connector for Teams and I can get my custom configuration page to load by calling the necessary functions. I have a few <span> tags in my page just to debug and I'm populating the tags with properties from my call to "getSettings()".
<script>
microsoftTeams.initialize();
var teamsSettings = microsoftTeams.settings.getSettings(); //should this not return at least something?
if (teamsSettings == null) {
$(document).ready(function () {
document.getElementById('status').textContent = "Get settings
returned null!"; //i always get null
});
} else {
document.getElementById('entityId').textContent = teamsSettings.entityId;
document.getElementById('configName').textContent = teamsSettings.configName;
document.getElementById('contentUrl').textContent = teamsSettings.contentUrl;
document.getElementById('webhookUrl').textContent = teamsSettings.webhookUrl;
document.getElementById('appType').textContent = teamsSettings.appType;
document.getElementById('userObjectId').textContent = teamsSettings.userObjectId;
}
microsoftTeams.settings.registerOnSaveHandler(function (saveEvent) {
saveEvent.notifySuccess();
});
function onClick() {
microsoftTeams.settings.setValidityState(true);
}
</script>
So I’m wondering if the getSettings() method is even running as my label element is blank. How can I troubleshoot the JavaScript interactions while configuring my connector in Teams? Is there a better way to view settings obtained from the method?
Here is the code snippet to get the webhookUrl using getSettings().
microsoftTeams.initialize();
microsoftTeams.settings.getSettings(function (settings) {
document.getElementById('webhookUrl').textContent = settings.webhookUrl;
});

Clicking if element is clickable in protractor

on website I have sometimes additional button with restoring autosaved data filled in the form, which pops in random moments (sometimes someone tests something and close form, which causing the popup button). I tried with Continue if element is not visible in protractor with following code:
let DoNotRefillBtn=element.all(by.className('modal-button-no'));
var isApproachable = function(element) {
return element.isPresent().then(function (present) {
return present
? element.isDisplayed()
: false;
});
};
describe(...)
it('Open the form:', function () {
browser.driver.get('foo');
browser.sleep(1000);
isApproachable(DoNotRefillBtn).then(function(approachable) {
if (approachable) {
DoNotRefillBtn.click();
browser.sleep(500);
}
else {
browser.sleep(300);
}
});
It clicks correctly, but after clicking, it throws error Failed: element not visible on line DoNotRefillBtn.click();.
Why does the program clicks and throws an error that thing is not clickable (after it was clicked)?
I used a workaround, the button comes with the status message "Do you want to refill the form?". So when I check for the status message and click the button, seems to be working:
let StatusMessage=element.all(by.className('status-message'));
let DoNotRefillBtn=element.all(by.className('modal-button-no'));
var isApproachable = function(element) {
return element.isPresent().then(function (present) {
return present
? element.isDisplayed()
: false;
});
};
describe(...)
it('Open the form:', function () {
browser.driver.get('foo');
browser.sleep(1000);
isApproachable(StatusMessage.get(8)).then(function(approachable) {
if (approachable) {
DoNotRefillBtn.get(0).click();
browser.sleep(500);
}
});
});
});
StatusMessage.get(8) is 8 because there are some more messages with the same class, but not displayed. I counted which status-message is that one and it seems to be working - closes popup if displayed, but skipping when it's not.
Propably checking the button and clicking it gives some problems

Knockout.Validation not showing error messages for property that is loaded after initial rendering

I have a Knockout.Validation scenario which I think would be fairly common but haven't found a solution from searching around the web and various answers on this site.
The property that I am validating does not get added to the knockout observable until after an ajax call. When validation gets triggered the validation fails and is an error in my validation group but the error message does not get shown on the page. I have made sure all the validation is hooked up by adding validation to a property that does exist when initial render happens and the message shows for that.
I know I could set a default for the property but I wouldn't expect you would have to do that. When i manually add the validation message with the validationMessage databind property it throws a js error because the property doesn't exist when knockout does its first pass through.....Uncaught TypeError: Unable to process binding "validationMessage: function (){return BlogPost().Title }"
Message: Cannot read property 'extend' of undefined.
See this plunk for an example...http://plnkr.co/edit/OhUw8wP2uNypulbcOIbz?p=preview .
self.Errors = ko.validation.group(this, { deep: true });
self.Count(self.Errors().length);
if (self.Errors().length === 0) {
alert("no errors");
}
else {
self.Errors.showAllMessages();
}
It is using require js but that is not causing any issues as for a standard scenario the validation message shows.
What am I missing here to get this working?
This is pretty clean... move your observables up to the main viewmodel, and leave the updateBlogPost to be just a method (no properties... as it should be).
This allows you to call self.Errors.showAllMessages() after you've loaded the blog post. Not sure you need the update method after this change?
function EditBlogPostViewModel(params) {
var self = this;
self.BlogPost = ko.observable({});
self.ErrorsCount = ko.observable(0);
self.Test = ko.observable("").extend({ required: true });
self.Count = ko.observable(0);
self.Errors = ko.validation.group(this, { deep: true });
self.Count(self.Errors().length);
blogApiService.getCategories().then(function (categories) {
return blogApiService.getBlogPost(params.id).then(function (post) {
self.BlogPost(new BlogPost(post, categories));
self.Errors.showAllMessages();
});
});
}
EditBlogPostViewModel.prototype.updateBlogPost = function () {
var self = this;
if (self.Errors().length === 0) {
alert("no errors");
}
else {
self.Errors.showAllMessages();
}
};
set deep: true in self.errors property,
self.errors = ko.validation.group(self, { deep: true });
and set this to display error messages,
ViewModel.errors.showAllMessages(true);
Hope it works!

Jquery validator is not un-highlighting "chosen" select box

I am using Chosen with jquery valodation.
you can see this example: http://jsfiddle.net/hfdBF/9/
if you click submit, you see that the validation is working for combo and input.
if you put one letter in the input box you will get an alert that the letter un-highlighted, as it suppose to be.
BUT, if you choose in the select box a value, it wont be alert as un-highlighted.
do you have any idea how to get that to work?
$(function() {
var $form = $("#form1");
$(".chzn-select").chosen({no_results_text: "No results matched"});
$form.validate({
errorLabelContainer: $("#form1 div.error"),
wrapper: 'div',
});
var settings = $.data($form[0], 'validator').settings;
settings.ignore += ':not(.chzn-done)';
settings.unhighlight= function(el){
alert(el.name + " hit unhighlight")
}
});​​
Thanks
You don't need to do the validation manually. You can bind a function to the change event handler that will check if the specific select is valid. This will also clear the error if the select is valid.
$('.chzn-select').change(function () {
$(this).valid();
});
You need to reset the jQuery validation manually:
$(".chzn-select").chosen().change(function () {
var value = $('#UserCompanyIds').val(); // the select element
if (value != "") {
$('.field-validation-error').each(function () {
if ($(this).attr('data-valmsg-for') == 'UserCompanyIds') {
$(this).html("");
$(this).removeClass("field-validation-error").addClass("field-validation-valid");
}
});
}
});
I hope this helps!

Resources