I am trying to use the Dialog for "Invite Friends" via Javascript SDK:
function sendRequestToManyRecipients() {
FB.ui({method: 'apprequests',
message: 'My Great Request',
}, requestCallback);
}
from https://developers.facebook.com/docs/reference/dialogs/requests
This works fine for me in case the user selects his friends and submits. My question is how can I also add "Skip" button through this function and if I can also catch the event of clicking "Skip"...any suggestions are highly appreciated! Thanks!
There is an ajax request fired when apprequests is called. In the callback you will find a response.to array in case if the user selects a friend. If the user does not select it is blank. A blank array in response.to is only when the user skips the dialog box.
Related
Below is a submit button on the page I am trying to test.
When you click this button, a pop-up window is displayed. The URL of this pop-up is https://login.microsoftonline.com/........etc.
This sign in uses SSO, but we are having difficulty bypassing the sign-in process using requests.
So we are instead trying to capture the URL of the pop-up during the test.
I have seen examples where people retrieve the href attribute of a button. However, as you can see above, there is no href on this button.
I've searched the HTML for a form element too, but can't find that.
I'm just wondering, is there a way I can get the URL of the pop-up window that clicking the above button generates?
To catch the URL, try adding an intercept before the click
cy.intercept('POST', '*').as('submit')
cy.get('button').click()
cy.wait('#submit').then(interception => {
console.log(interception.request.url)
})
Note this is debugging code only to help find the URL. Don't use it in a long-term test.
Additional notes:
I'm assuming 'POST' as it's most common for submit, but may need 'GET' instead.
using '*' will catch anything, so you may catch so stray requests from the page load with the first cy.wait('#submit'). If so, just add more cy.wait('#submit') or a long cy.wait() before the click.
The new tab is likely to be trigger via javascript. If it is using [window.open][1] the you can stub it to open in the same ta
cy.window().then(win => {
cy.stub(win, 'open').callsFake((url, target) => {
expect(target).to.be.undefined
// call the original `win.open` method
// but pass the `_self` argument
return win.open.wrappedMethod.call(win, url, '_self')
}).as('open')
})
cy.get('a').click()
cy.get('#open').should('have.been.calledOnceWithExactly', 'url')
})
[1]: https://glebbahmutov.com/blog/cypress-tips-and-tricks/#deal-with-windowopen
I am trying to build a test scenario for acceptance testing. In my scenario, I want to click on an non-editable input field to trigger a JqueryUI calendar, and then click a date from the calendar.
The problem is that I can't seem to find any actions in CodeCeption that allows you to click on something else than a an anchor or a button.
The doc clearly states : Perform a click on a link or a button, given by a locator.
public function click($link, $context = null)
There are also similar functions that do something similar, but not with the left mouse button
public function clickWithRightButton($cssOrXPath)
public function doubleClick($cssOrXPath)
This seems so trivial that I can't find anything about it. Why isn't there a clickWithLeftButton? Am I missing something here? I'm just starting with acceptance tests with CodeCeption.
I may not fully understand the question, but have you tried
$I->waitForText('Text User would click on Here', 30);
$I->click('Text User would click on Here');
My client is using Magento, and after clicking the submit button, the form submits to the controller and then the same page reloads. What he asked me is once he clicks on the submit button he wants a popup displayed. So I used a div with a disabled background as a popup in a dynamic way (JavaScript), but since the button is "submitting", the page refreshes and I lose the popup, so is it possible to keep that div displayed even after submitting?
Jquery example:
$(document).ready(function(){
$('#form_selector').submit(function(){
showDialog();
//stop submit
return false;
});
$('#dialog_button_selector').click(function(){
//submit form
$('#form_selector').submit();
});
});
I'm not familiar with Magneto, but generally speaking, couldn't you look for a form submit in the controller when the page reloads and call for the popup, if true?
Why don't you use slide panel instead of pop-up panel?
For instance, check isLoggedin function of Magento :
<?php
if ($this->helper('customer')->isLoggedIn() ) {
echo "Welcome!";
} else {
echo "Please log in.";
}
?>
if customer is logged, show necessary information of customer inside the slide panel.
If you want just one time show this panel, try to event observer methods of magento :
app/code/core/Mage/Customer/Model/Session.php
Event names :
customer_login
customer_session_init
For jQuery Sliding Panel, you can use jqEasy which is supporting showOnLoad property.
jqEasy
Given that you don't want to hold submission of the page, you basically need to echo the popup after the page is submitted. So, using some generic event (catalog_product_add_to_cart_after), add a session variable like this:
public function observer($event) {
Mage::getSingleton("customer/session")->setNeedsCartPopup(true);
}
Then, in your template, you can check for the existence of this variable to show your popup:
$session = Mage::getSingleton("customer/session");
if($session->getNeedsCartPopup()) {
$session->->setNeedsCartPopup(false);
// echo HTML to display popup as the page loads
}
This is not tested code, but it should give you the gist of how to capture the event and respond to it in the template. Hope that helps!
Thanks,
Joe
I've been working on Chrome Extension for a website for the past couple of days. It's coming along really nicely but I've encountered a problem that you might be able to help with.
Here's an outline of what the extension does (this functionality is complete):
A user can enter their username and password into the extensions popup - and verify their user account for the particular website
When a user browses http://twitter.com a content script is dynamically included that manipulates the DOM to include an extra button next to each tweet displayed.
When a user clicks this button they are presented with a dialog box
I've made a lot of progress but here is my problem:
When a user visits Twitter the content script is activated and all tweets on the page get my new button - but if the user then clicks 'More...' and dynamically loads the next 20 tweets... these new additions to the page DOM do not get affected by the content script (because it is already loaded).
I could add an event listener to the 'More...' button so it then triggers the original content script again (and adds the new button) but i would have to predict the length of twitter's ajax request response.
I can't tap into their Ajax request that pulls in more tweets and call my addCurateButton() function once the request is complete.
What do you think is the best solution? (if there is one)
What you want to do is to re-execute your content-script every time the DOM is changed. Luckily there is an event for that. Have a look at the mutation event called DOMNodeInserted.
Rewrite your content script so that it attaches an event listener to the body of the DOM for the DOMNodeInserted event. See the example below:
var isActive = false;
/* Your function that injects your buttons */
var inject = function() {
if (isActive) {
console.log('INFO: Injection already active');
return;
}
try {
isActive = true;
//inject your buttons here
//for the sake of the example I just put an alert here.
alert("Hello. The DOM just changed.");
} catch(e) {
console.error("ERROR: " + e.toString());
} finally {
isActive = false;
}
};
document.body.addEventListener("DOMNodeInserted", inject, false);
The last line will add the event listener. When a page loads the event is triggered quite often so you should define a boolean (e.g. var isActive), that you initialize to false. Whenever the inject function is run check whether isActive == true and then abort the injection to not execute it too often at the same time.
Interacting with Ajax is probably the hardest thing to coax a content script to do, but I think you’re on the right track. There are a couple different approaches I’ve taken to solving this problem. In your case, though, I think a combination of the two approaches (which I’ll explain last) would be best.
Attach event listeners to the DOM to detect relevant changes. This solution is what you’ve suggested and introduces the race condition.
Continuously inspect the DOM for changes from inside a loop (preferably one executed with setInterval). This solution would be effective, but relatively inefficient.
The best-of-both-worlds approach would be to initiate the inspection loop only after the more button is pressed. This solution would both avoid the timing issue and be efficient.
You can attach an event-handler on the button, or link that is used for fetching more results. Then attach a function to it such that whenever the button is clicked, your extension removes all the buttons from DOM and starts over inserting them, or check weather your button exists in that particular class of DOM element or not and attach a button if it doesn't.
I have a web form which is split up into several HTML pages.
I am using the validation plug-in to check fields on submit and this is working great.
The spec says that users should be able to navigate through the form, both linearly (just using the submit buttons to go from page to page) and also to skip to any particular page.
I have a unordered list with the links at the top of each page. I'm looking to fire the validation both on submit and when one of these links is clicked but don't know if this is possible.
For info, I'm currently firing the validation this way:
$("form#courseDetails").validate({
rules: {
studiedBefore: "required" //Have you studied with us before
},
messages: {
studiedBefore: "Please indicate whether you have studied with us before."
}
});
Each form has an ID and validation for all the forms is in one JS file.
Not that it really matters, but the navigation is in <ul id="tabNav">
Any help much appreciated.
Thanks,
Phil
Check the .valid() method it provides. If you call that in click handlers attached to your links, you should be ok.