casperjs + modal popup - popup

i'm wondering why cannot get casperjs to recognize the modal popup:
var casper = require('casper').create();
casper.start('http://www.zulutrade.com/trader/140682?Lang=en');
casper.waitForSelector("form[name=aspnetForm] button#main_BtnFollow",
function success() {
this.test.assertExists("form[name=aspnetForm] button#main_BtnFollow");
this.click("form[name=aspnetForm] button#main_BtnFollow");
},
function fail() {
this.test.assertExists("form[name=aspnetForm] button#main_BtnFollow");
});
casper.waitForPopup(/popup\.html$/, function() {
this.test.assertEquals(this.popups.length, 1);
});
casper.run(function() {this.test.renderResults(true);});
running the above gives me timeout in the waitForPopup part..
How to make this work and how to use casper.withPopup properly with the popup?

ah, are you using Resurrectio? in my experience, you need to tweak whatever script they generate. i mostly only use it for element names.
i'm only seeing asserts in your script. i think you need to tell casper to click on something before you see your modal. something like this maybe?
casper.then(function() {
this.clickLabel('.Follow', 'a');
});
casper.waitForSelector("#modal_popup", function() {
this.echo('see the modal!');
this.capture('screenshotofmodal.png', { top: 0, left:0, width:1000, height: 4000});
});
PS
using capture() is super helpful in troubleshooting your scripts. i have them as sort of like, breakpoints where i can easily see what's going on if a test that i know should be passing is failing.

I've found myself implementing crude timeouts to get casper to play nicely with modal interactions:
casper.start(uri).then(function() {
var slideshow = 'a.photo_gallery_icon_modal_launch';
casper.wait(2000, function(){
casper.thenEvaluate(function(sel) {
$elem = jQuery(sel).first();
$elem.click();
}, slideshow)
}).wait(1000, function(){
// wait a sec for modal to show up before taking pic
casper.capture('foo.png', {
top: 0,
left: 0,
width: 1280,
height: 1024
})
})
});
There is also waitForSelector but I have not had as much success with it, because the contents of my modal are also asynchronous making the usage of wait or even waitForUrl more appropriate.
http://docs.casperjs.org/en/latest/modules/casper.html#waitforselector

Related

Bigcommerce Infinite scroll not working after faceted search is made

Infinite scroll to our Custom PLP page is only working for page load alone. After selecting the faceted search, the infinite scroll feature is not working after the faceted response is appended. Please someone help us to have the Infinite scroll feature working after the faceted search result is appended.
Thanks in Advance
BigCommerce does not offer an Infinite Scroll feature by default, so I'm going to assume you followed this guide: https://medium.com/bigcommerce-developer-blog/how-to-add-infinite-scroll-to-category-pages-6c991750a8d5
The thing to keep in mind is that the category page gets reloaded via AJAX when a filter is applied. The fix for this should be as simple as duplicating the infiniteScroll function inside the this.facetedSearch function.
Look for the following code in your category.js file:
this.facetedSearch = new FacetedSearch(requestOptions, (content) => {
$productListingContainer.html(content.productListing);
$facetedSearchContainer.html(content.sidebar);
$('html, body').animate({
scrollTop: 0,
}, 100);
});
And add the infinite scroll function here as well:
this.facetedSearch = new FacetedSearch(requestOptions, (content) => {
$productListingContainer.html(content.productListing);
$facetedSearchContainer.html(content.sidebar);
function infiniteScroll() {
const elem = document.querySelector('.productGrid');
const infScroll = new InfiniteScroll(elem, {
// options
path: '.pagination-item--next .pagination-link',
append: '.product',
history: false,
});
return infScroll;
}
infiniteScroll();
$('html, body').animate({
scrollTop: 0,
}, 100);
});

Protractor locator issues

My goal is to pull the css width of a particular element.
The actual jQuery command I use in Chrome console works well :
$('div-grid-directive[grid-name="SAT"] .qMinus1_resize_expand').first().css('width');
"0px"
However, running Protractor in a Win 7 cmd prompt, I'm getting the following error:
Message:
Failed: element(...).first is not a function
The error points to my objects page topNav.icons.page.js, in this.getQMinus1Column :
module.exports = function(){
this.clickExpandRowsIcon = function(){
$('.resize-btns > .glyphicon.glyphicon-resize-horizontal').click();
browser.driver.sleep(2000);
};
this.getQMinus1Column = function(){
return element(by.css('div-grid-directive[grid-name="SAT"] .qMinus1_resize_expand')).first();
};
};
and my SAT.spec.js file :
var IndexPage = require('./pageObjects/index.page.js');
var TopNavBar = require('./pageObjects/topNav.icons.page.js');
describe('Testing the Sales & Trading Top Nav grid icons', function(){
var indexPage = new IndexPage();
var topNavBar = new TopNavBar();
beforeEach(function () {
indexPage.get(); // Launches app !!
});
describe('Clicking on the Expand Rows icon', function () {
it('Should horizontally expand previous quarters qMinus1 thru qMinus6', function () {
topNavBar.clickExpandRowsIcon();
var elem = topNavBar.getQMinus1Column();
expect(elem).getCssValue().indexOf('width: 5px;').not.toBe('-1');
});
});
});
So before I even try to get the css width attribute, I'm struggling to return first(), using this format:
return element(by.css('MY-CSS')).first();
Do I have too much going on in this line, or perhaps the wrong syntax for Protractor ?
return element(by.css('div-grid-directive[grid-name="SAT"] .qMinus1_resize_expand')).first();
Again, the same syntax works using jQuery in console tools, so the CSS select is correct.
Advice is greatly appreciated here...
regards,
Bob
As per this , element does not return a collection of objects to call first method in it.
Probably you might want to use element.all(locator)

Ionic Decrease Scroll Speed

i got problem when trying to slowing scroll from this code :
$ionicScrollDelegate.$getByHandle('credit').scrollBottom(true).
How can i slowing down the scroll? Because now it scrolling too fast for me. I need to slowing down the scroll, just like credit scene on the Star Wars movie.
Anyhelp would be much appreciated, thanks!
$scope.viewCreditsV2 = function () {
$ionicModal.fromTemplateUrl('views/popupcredit.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
$scope.modal.show();
if ($scope.modal.isShown()){
setTimeout(function() {
// Do something after 2 seconds
$ionicScrollDelegate.$getByHandle('credit').scrollBottom(true);
}, 2000);
}
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
// $scope.modal.hide();
$scope.modal.remove();
};
};
This question is old but somebody might use it.
Even though there are no parameters to pass options, you can still access the ScrollView object using the $ionScrollDelegate.
Following #Jeremy Wilken's answer (which helped me derive this one), you could do:
$timeout(function() {
$ionicScrollDelegate.getScrollView().options.animationDuration = 400;
console.log($ionicScrollDelegate.getScrollView().options);
});
//.....
$ionicScrollDelegate.scrollBy(0,20, true) // Animation will be slower now
I wrapped the call on a $timeout to avoid racing conditions from $ionicScrollDelegate not being created.
Ionic doesn't have a means to change the animation speed for the $ionicScrollDelegate. There is no public API to make this change.
https://github.com/driftyco/ionic/blob/master/js/views/scrollView.js#L327
You can use $anchorScroll as shown in the Angular documentation https://docs.angularjs.org/api/ng/service/$anchorScroll

GreenSock JS adding dom element within Tween onComplete()

I'm trying to get past a GreenSock JS issue that you might be able to help me with.
After a tween of container div width, I'm trying to append an inline div into the newly created container space using the onComplete() event.
The new div does not immediately get added to the space. On the next add action (that creates additional container width), the previously created div appears.
I'm trying to solve within the GreenSock context, but all ideas are welcomed.
Thanks!
TweenLite.to($('.list-item-container'), 1, {
width: $('.list-item-container').width() + 253,
delay: 0.25,
onComplete: function () {
var _item = document.createElement('div');
$(_item).addClass('list-item');
$('.list-item-container').append(_item);
}
});
It looks like the tween is complete before jQuery is ready.
$(function() {
TweenLite.to($('.list-item-container'), 1, {
width: $('.list-item-container').width() + 253,
delay: 0.25,
onComplete: function () {
var _item = $("<div/>");
$(_item).addClass('list-item');
$('.list-item-container').append(_item);
}
});
});
http://jsbin.com/lesire/1/
This also works for when I put it inside of a triggered event.
$("#button").on('click', function(){
TweenLite.to($('.list-item-container'), 1, {
width: $('.list-item-container').width() + 253,
delay: 0.25,
onComplete: function () {
var _item = $("<div/>");
$(_item).addClass('list-item');
$('.list-item-container').append(_item);
}
});
});
I created a JSBin that demonstrates it.
http://jsbin.com/zuyinu/5/
You might want to consider using an id to identify your list-item-container because
$('.list-item-container').append(_item);
will append _item to every element with the list-item-container class.
Good luck!

IE does not pick up form processing data in inputs in a jQuery Dialog

I have an HTML5 page with several data inputs inside a jQuery Dialog box. I sweep this data into form processing with the input attribute form=dataInput. It works fine in Firefox and Chrome, but not in IE because IE does not support the input form attribute. Something about the Dialog widget makes input box elements 'invisible' to form processing. The form attribute fixes this for browsers that support HTML5, but no released IE has this support. I tried $('.ui-dialog').appendTo('form'); in the Dialog open: option, but it does not fix the problem. Is there a way to get IE to sweep input data out of a Dialog widget and into $_POST ?
Here is a sample of an input box inside the Dialog
<label><input type="radio" id="unitedStates" name="country" form="dataInput" value="US">United States</label>
I use the jQuery Form plug-in to perform the submit. It has some options, like beforeSubmit and beforeSerialize, but I don't understand the documentation or the submit process well enough to know if they can be used to solve this problem. Please be specific with code or tutorials. I'm new enough to this that I don't follow general instructions well. ;-) (BTW, IE has the other feature support I need, just not this one.)
Here's my code with Andrew Hagner's suggestion and my modification. Dialog works, but IE does not set a value for the country. What needs to change?
var countrySelected = $("input[type=radio][name=country]").val(); //set earlier by W3C geocoding
var countryChooser = $('#countryChoices').dialog( {
autoOpen: false,
bgiframe: true,
height: 300,
width: 850,
resizable: false,
draggable: true,
title: "Click to select another country",
open: function () {
$('#regions').tabs(
{
event: "mouseover",
})
},
buttons: {
'Close / continue location input': function ()
{
countrySelected = $('input[name=country]:checked').val();
$(this).dialog('close');
}
}
});
//then later on
getCityFromGeonames3Step(countrySelected);
Updated:
// Before you enter dialog, assign the element you will
// be grabbing the info from to a variable.
var countrySelectionElement = $("input[type=radio][name=country]").val();
var countrySelected = "";
var countryChooser = $('#countryChoices').dialog( {
autoOpen: false,
bgiframe: true,
height: 300,
width: 850,
resizable: false,
draggable: true,
title: "Click to select another country",
open: function () {
$('#regions').tabs(
{
event: "mouseover",
})
},
buttons: {
'Close / continue location input': function ()
{
// Since jQuery won't work in here, use the variable
// we assigned above to access value.
countrySelected = countrySelectionElement.val();
$(this).dialog('close');
}
}
});
//then later on
getCityFromGeonames3Step(countrySelected);
Original:
Before you open the dialog assign the input to a variable:
function OpenDialog()
{
var input = $("yourinput");
// Open dialog, use input to work with that element.
// If you want you can then place the entered data in a hidden field
// using jQuery, in the same way we are using input here. Then you will
// be able to post that data back however you like.
}
I had this problem the other day, I found this solution on jQuery's Dialog site.
http://jqueryui.com/demos/dialog/#modal-form