I have following scenario:
User tries to login with wrong password
on failure I ask him if he wants to reset password
if user click 'OK' (pure confirm dialog) , I'll open new tab with some URL.
My problem is: I always get popup blocker because I generate window only after error callback. Here is relevant code login method:
$scope.login = function () {
$auth.login({
email: $scope.fields.email,
password: $scope.fields.password
})
.then(function () {
// ... login success
})
.catch(function () {
// login failed (my case)
if (confirm('ERROR: Invalid password, forgot Password? Click \'OK\' if you want to reset it')){
var url_ = 'http://meeter.me/#/forgot-pass/snaggs#gmail.com';
var myPopup = window.open ('', '_blank');
myPopup.location = url_;
if (myPopup && myPopup.focus) {
myPopup.focus();
}
}// if
});
};
If I move var myPopup = window.open ('', '_blank'); to next line under $scope.login = function () it will work but it will open new empty tab.
I want to open new tab only when get error on login
I use satellizer
Please help,
Plunker Demo
In demo i use single $timeout to simulate async call
I don't think it is going to be possible to open a new window using window.open if it is invoked asynchronously. Without user invocation, the call stack is always going to identify that window.open is triggered asynchly and going to block it. Maybe an option to show a new button if login is failed and let that button open up a new window?
http://plnkr.co/edit/QGfnxH484OdTvaaOvMaE?p=preview
<button ng-click="init();">press me</button><br />
<span ng-show="resetPwd" >
Login Failed!! <button ng-click="reset()">Reset Password</button>
</span>
$scope.init = function() {
$timeout(function() {
$scope.resetPwd = true;
}, 2000);
}
Related
I am doing end-to-end testing with protractor. In a certain test, I need to test like print button is creating pdf or not. So When Test clicks the button, It opens the print window dialog like below.
And now this test is not able to be finished. because of this print window. My question is how to close this print dialog in protractor? Because of it, rest of test become pending. Please help. Thanks in advance.
EDIT
I have tried like this..
var printButton=element(by.css('[class="print"]'));
/* This print button should be present first*/
expect(printButton.isPresent()).toBe(true);
browser.actions().mouseMove(printButton).perform();
printButton.click().then(function () {
// fill in the form here
browser.sleep(2000);
// For Pressing Escape key
browser.actions().sendKeys(protractor.Key.ESC).perform();
});
I thought If i got successful to press escape key, then It will resolve the issue.But No Success.
NEXT EDIT--
I have tried new Windows change like below
printButton.click().then(function () {
// fill in the form here
browser.sleep(4000);
browser.getAllWindowHandles().then(function(handles){
browser.switchTo().window(handles[1]).then(function(){
//do your stuff on the pop up window
browser.driver.close();
browser.switchTo().window(handles[0]);
});
});
});
but it shows an error in console and actually It does not open any windows. and hungs up on print dialog as previous.
Failed: unknown error: failed to close window in 20 seconds
EDIT 3
I am having this problem in angular js not in java.
EDIT 4 My Last Attempt
printButton.click().then(function () {
// fill in the form here
return browser.getAllWindowHandles().then(function (handles) {
var newWindowHandle = handles[1]; // this is your new window
return browser.switchTo().window(newWindowHandle).then(function () {
return browser.sleep(5000).then(function () {
return browser.actions().sendKeys(protractor.Key.ESCAPE).perform().then(function () {
return browser.switchTo().window(handles[0])
});
});
});
});
But It does not open a new tab for print Dialog..open print Dialog in same tab.
You need to send the escape to the right window. Also wait for the window to be open before you send it. You probably also need to switch back to handles[0].
return browser.getAllWindowHandles().then(function (handles) {
var newWindowHandle = handles[1]; // this is your new window
return browser.switchTo().window(newWindowHandle).then(function () {
return browser.sleep(5000).then(function () {
return browser.actions().sendKeys(protractor.Key.ESCAPE).perform().then(function () {
return browser.switchTo().window(handles[0])
});
});
});
});
Set the capabilities as below; this will disable the print preview pop up from chrome browser
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ['--disable-print-preview','start-maximized']
}
},
Following OctoberCMS guidelines I need to redirect users when they attempt to reach a certain path (ex: www.foo.com/bar) to the home page with php variables (ex: www.foo.com/?bar=1) and have a modal open if the variable is found.
I've created bar.htm which redirects with the proper variable:
title = "bar"
url = "/bar"
layout = "default"
meta_title = ""
meta_description = ""
is_hidden = 0
==
<?php
function onStart() {
header('Location:/?bar=1');
}
?>
==
and then in my JS (with #submitBtn being the button on the modal to send the form)
$(document).ready(function(){
if(window.location.href.indexOf('1') > -1) {
$('#myModal').modal('show');
$('#submitBtn').click(function() {
window.location.href='/';
})
}
});
So this is not working, it is just showing the modal in a constant loop and never moving to the success modal or changing the href. This form is working properly in all other situations, so I do not believe the issue lies there.
Shortened example modal code:
$('#myModal').on('show.bs.modal', function (event) {
var newForm = $('#newFakeForm');
var config = {
submitBtn: $('#submitBtn'),
contactModal: $('#myModal'),
successModal: $('#successModal'),
};
initContactForm(newFakeForm, config);
});
and my HTML button to dismiss the modal:
Thank you
What if you do the redirect on JS?
Just listen for the hidden.bs.modal event and do the redirect there.
I've got a button in my Meteor application that does the following:
user clicks button > event calls method > method calls external api using http > external api returns single sign on link > method returns link > event opens new window (tab) with link as url
My problem is that the new tab is being blocked by a popup blocker even though it is based on user action
Here's the event code:
Template.welcome.events({
'click #accessLms': function(e) {
e.preventDefault();
var submitButton = $('#accessLms').button('loading');
Meteor.call('getLmsLink', function(error, portalLink) {
if(error) {
sAlert.error(error.message);
submitButton.button('reset');
} else if(portalLink) {
window.open(
portalLink,
'_blank'
);
submitButton.button('reset');
}
});
}
});
Here is the method:
Meteor.methods({
'getLmsLink': function () {
[set vars...]
try {
var response = HTTP.call( verb, wceaApiAddress + endPoint, {
headers: {
"Request-Time": timeStamp,
"Api-Key": key,
"Signature": hash
}
});
} catch(error) {
throw new Meteor.Error(501, 'There was a problem getting a link to the E-Learning Portal');
}
var result = JSON.parse(response.content);
var portalLink = result.records.accessLink;
return portalLink;
}
});
Basic approach:
On the click event in your app open a new window with a specific url to your own app
Include a route parameter that can be used in the new window, for example /redirect/token/
In the Template.onCreated event of the template used in that route, perform the method call and get the url and auth token to the 3rd party site.
Finally just set location = newSiteHref in that same code (in the new window) and redirect the user
I am trying to check the pop up for facebook login opening on click of button .
Error : Object [object Object] has no method 'getWindowHandle'.
Code Snippet generating error :
describe('Tests', function() {
var ptor;
var handlePromise;
var util = require('util');
beforeEach(function() {
ptor = protractor.getInstance();
handlePromise = ptor.getAllWindowHandles();
var handlesDone = false;
ptor.get('/SiteB_Upgrade_Device/app/index.html#/Recommendations#page');
ptor.findElement(by.id('fb')).click();
ptor.ignoreSynchronization = true;
});
describe('login', function() {
return it('should switch to popUp\'s handle', function() {
handlePromise.then(function(handles) {
var popUpHandle = handles[0];
var handle = browser.driver.switchTo().window(popUpHandle).getWindowHandle();
expect(handle).toEqual(popUpHandle);
});
},30000);
});
});
Here is what I currently use to navigate through popups/tabs :
// do stuff that will trigger the popup
// ...
browser.getAllWindowHandles().then(function (handles) {
// switch to the popup
browser.switchTo().window(handles[1]);
// make sure the popup is now focused
expect(browser.getCurrentUrl()).toEqual('popup/url');
// do stuff with the popup
// ...
// go back to the main window
browser.switchTo().window(handles[0]);
// make sure we are back to the main window
expect(browser.getCurrentUrl()).toEqual('original/url');
});
You just need to make sure that your popup is really a new window and not juste some kind of popover ( in which case you can just target it with css selectors ).
Another thing to keep in mind when you change tabs/popups it that the target page might not have angularjs loaded in it, which will render protractor useles. If you face this case you can simply use browser.driver as a replacement for browser to navigate a non angular page.
Hope this helps.
i'm trying to login into the site with the following javascript. But, i'm loading only the complete page. I'm developing windows 8 app
(function () {
"use strict";
WinJS.UI.Pages.define("/pages/home/home.html", {
// This function is called whenever a user navigates to this page. It
// populates the page elements with the app's data.
ready: function (element, options) {
// TODO: Initialize the page here.
document.getElementById("bt_login").addEventListener("click", login, false);
}
});
})();
function login() {
var xhrDiv = document.getElementById("xhrReport");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = dataLoaded;
xhr.open("POST", "http://www.160by2.com", true, <username>, <password>);
xhr.send();
function dataLoaded() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// OK
xhrDiv.innerHTML = window.toStaticHTML("response:" + xhr.responseText);
} else {
// not OK
xhrDiv.innerText = "failure";
}
}
};}
I want to dsiplay in xhrdiv.innerHTML as "LOGIN SUCCESS" or "LOGIN ERROR"
EDIT:
I tried the following code:
iframe = document.getElementById("ifra_op");
iframe.setAttribute("src", "http://www.160by2.com/index");
document.getElementById("op").appendChild(iframe);
iframe.contentWindow.document.getElementById("MobileNoLogin") = "<mobno>";
iframe.contentWindow.document.getElementById("LoginPassword") = "<pass>;
iframe.contentWindow.document.getElementsByName("LoginForm").click();
But, there is an error. It says "Javascript run time error:math is undefined"
"math" comes from the website. I don't know how to handle this. Also, the permission is denied. Why is that so?
You need to make sure you have a service (something like a web service) in the remote server to process the request.
In here what you can do is.
Create an iframe and set the src to 160by2;
Access the webpage using iframe.contentwindow, inject your code to fill up the forms and trigger the submit button.
Parse the received html to verify your login.
Use jquery , makes life easier.
var iframe = $("#ifra_op");
$(iframe).attr("src", "http://www.160by2.com/index");
$(iframe).attr("onload","submitForm();");
function submitForm(){
$(iframe.contentWindow.document).find("#MobileNoLogin").val("9999");
$(iframe.contentWindow.document).find("#LoginPassword").val("pass");
$('#button').click();
}