JScript setText() in email and password not being read - modal-dialog

Hello StackOverflow -
My issue is a strange one and hopefully someone has seen something like it before.
I'm using TestComplete to do front-end functional testing with a REST API.
We have a Login button that drops a modal to enter email and password.
My script:
function modalCheck()
{
var emailBox, mainPage, unexpWnd;
//Browsers.Item(btFirefox).Run("http://[redacted]");
var mainPage = Sys.Browser("firefox").Page("http://[redacted]/");
var loginModalButton = Sys.Browser("firefox").Page("http://[redacted]/").Panel(0).Header(0).Panel(0).Nav(0).Panel(0).Panel(1).Button("login");
//click login button to drop modal
if(loginModalButton.Exists)
{
loginModalButton.Click();
Log.Message("This button exists and I clicked it.");
}
//modal now visible = assign text and click login submit button
var emailBox = Sys.Browser("firefox").Page("http://[redacted]/").Panel(4).Panel(0).Panel(0).Panel(1).Form(0).Panel(0).Panel(0).Panel(0).Panel(0).Textbox("email");
var passwordBox = Sys.Browser("firefox").Page("http://[redacted]/").Panel(4).Panel(0).Panel(0).Panel(1).Form(0).Panel(0).Panel(0).Panel(0).Panel(0).PasswordBox("password");
var loginSubmitButton = Sys.Browser("firefox").Page("http://[redacted]/").Panel(4).Panel(0).Panel(0).Panel(1).Form(0).Panel(1).Panel(0).Panel(0).SubmitButton("login_submit");
emailBox.setText("[redacted]");
passwordBox.setText("[redacted]");
Delay(5000);
loginSubmitButton.Click();
//need to logout - now the button will show "Logout" instead of "Sign Up"
var logoutButton = Sys.Browser("firefox").Page("http://[redacted]/").Panel(0).Header(0).Panel(0).Nav(0).Panel(0).Panel(1).Button("logout");
if(logoutButton.Exists)
{
logoutButton.Click();
Log.Message("This button exists and I clicked it.");
}
}
I can drop the modal, enter my email and password, and click the login button successfully with this script. The problem is - my credentials aren't recognized and/or are flagged as incorrect if they're entered via my script or if the browser autofills them. They work if entered manually (so I know they're correct and I'm not locked out).
As a tester, this is pretty black-box for me. I can pass along some HTML but I'm not involved in the creation. I can also ask the front-end guys more specific questions if it would help solve my issue.
What does it look like my problem is?!

Use the Keys method instead of SetText. The later puts the text directly to the control and this does not fire the required events.
emailBox.Keys("[redacted]");
passwordBox.Keys("[redacted]");

Related

Yes/no user prompt to continue or stop the script

I have this nice google apps script that works fine but it results in the deletion of a sheet in my google spreadsheet thus I would like the script to start with a Yes/No prompt asking "Are you sure you want to close the job". If he says yes, great, go on, if not, exit the script.
Any ideas? Thanks in advance !
Found this
// Display a dialog box with a message and "Yes" and "No" buttons. The user
can also close the
// dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Are you sure you want to continue?',
ui.ButtonSet.YES_NO);
// Process the user's response.
if (response == ui.Button.YES) {
Logger.log('The user clicked "Yes."');
} else {
Logger.log('The user clicked "No" or the close button in the dialog\'s
title bar.');
}

webDialog "CURRENT GOALS" header but no button to authorize or cancel

I am new to Facebook SDK. I am adding the Facebook login in my Android app using Facebook SDK 3.0.1. A Facebook webDialog pop-up for login. Today I found a strange behaviour that is different from that yesterday.
After entering an account name and password and press Login button in the webDialog, it finally shows "CURRENT GOALS" in the header requesting add friends, enter locations, etc. The body shows "(YOUR_APP) would like to access your public profile and friend list". But there is no more button to authorize or cancel. From the Eclipse LogCat, the current session state from Session.StatusCallback() is OPENING. As a result, user cannot complete the login process.
So how do I pass the dialog to complete the login process successfully? If I press the upper-left corner close button or back button, the dialog closes. The session state would become CLOSED_LOGIN_FAILED.
Yesterday, when the same account login, the webDalog finally show "You have already authorized (YOURAPP)" and a Cancel and OK buttons exist. If user press OK, the dialog closes, and Session.StatusCallback() calls out session state becomes OPENED. Thus user complete the login process successfully.
I just found and posted a workaround at: current goals hides facebook ok button during Facebook authorization in a web view
In the FaceBookSDK I modified com/facebook/widget/WebDialog.java, so that once the web dialog was loaded it would look for the block that contains "Current Goals" and hide it (if it exists). Once you do that, the buttons are visible again (at least they were for me).
In com/facebook/widget/WebDialog.java:
private class DialogWebViewClient extends WebViewClient {
// ... other methods ...
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (!isDetached) {
spinner.dismiss();
}
/*
* Once web view is fully loaded, set the contentFrameLayout background to be transparent
* and make visible the 'x' image.
*/
contentFrameLayout.setBackgroundColor(Color.TRANSPARENT);
webView.setVisibility(View.VISIBLE);
crossImageView.setVisibility(View.VISIBLE);
// I don't know how to highlight in the code block
// So I just add this extra long comment to make it obvious
// Add a javascript call to hide that element, if it exists
webView.loadUrl("javascript:try{ document.getElementById('nux-missions-bar').style.display='none'; } catch (e) {}");
// End changes
}

How to prevent a button added by a userscript [GreaseMonkey/TamperMonkey] from submitting a form

Let me start off by saying that the code in question is part of a UserScript and, as such, normal DOM rules and Javascript methods do not work.
Here is the situation:
I have written a UserScript that interacts with an online chat site. I have a number of button that are generated within the user script. Some of these buttons are located inside of a form, while many of them are not.
Elements added through GreaseMonkey live in two worlds -- they live on the page DOM and they live in the slightly elevated world of UserScripts, which mean that these lines:
event.preventDefault = true;
event.stopPropagation = true;
prevent the rest of the UserScript actions from running, but it does not stop the button from causing a form submit.
As a work around, I am building span elements instead of a button. This works, but it really breaks the visual layout of the chat room.
Does anyone know a way to prevent elements added by UserScripts to prevent form submissions? Failing that, I'll dream that someone knows how to make a span look like a native button.
Edit: I have a solution which seems to be working -- but I haven't fully tested it under every UserScript environment:
// Yes, yes, poorly named but it was a SPAN
// userWindow is an alias for unsafeWindow.
// (Used to run under a userScript environment for IE and I had to emulate a lot)
var span = document.createElement("input");
span.value = text;
span.type = "button";
span.className = "cpbutton";
// Add it to the body just long enough to set up a page-level, DOM0 event handler
var body = userWindow.document.getElementsByTagName("body")[0];
var tname = "IAmTheVeryModelOfAModernMajorGeneral";
span.id = tname;
body.appendChild(span);
userWindow.document.getElementById(tname).onclick = function() {return false;};
body.removeChild(span);
span.id = "";
See the W3C spec for <button>.
By default, a <button> element acts as a submit button inside a form. This means that event.preventDefault() (the correct usage, BTW), on the click handler, may not be enough to stop the form submit.
In that case you could intercept the form's submit event too BUT, the smart thing to do is to use the type attribute to tell the browser not to treat the button as a submit button.
EG:
<button type="button">Your button markup</button>
when you say
to prevent elements added by UserScripts to prevent form submissions
i'm not sure if you want to allow or prevent submiting the form...
anyway, here is a link and a div disguised as a button: http://jsfiddle.net/RASG/PvhUb/
and if you post some of your code, i can help you with your script.

UI Automation in iPhone App

Hi people I have a serious problem at hand, I have made a sample iphone app with "username" and "password" field and a "login" button and I have set the accessibility labels for all the components to be username, password and login and written a java script to test these components which goes as follows -:
UIALogger.logStart("Starting Test");
var view = UIATarget.localTarget().frontMostApp().mainWindow();
var textfields = view.textFields()["username"];
var passwordFields = view.secureTextFields();
var convertButton = view.buttons()["login"];
textfields.setValue("ABC");
passwordFields[0].setValue("SDE");
convertButton.tap();
what I observe is that when I fire up instruments to test the app through the above java script, the js successfully enters value into the username field but is unable to enter the value in the password field which I have made secure also the button is tapped successfully and the control moves to the next page in the app and on the next page there is a logout button set with the accessibility label "logout" which also I am not able to tap on. Can you please suggest a workaround for this situation if any.
var passwordFields = view.secureTextFields();
How many secure text fields are there - what happens if you output the length of that array?
Why not
var passwordfield = view.secureTextFields()["password"];
passwordField.setValue("SDE");
in the same way you did for the text field?

How FB refreshes the page without reloading it (xmlHttpRequest) but Back button still works?

How FB refreshes the page without reloading it (xmlHttpRequest) but Back/Forward Buttons still work as usual?
It's not about using history.pushState() methods. PushState() only changes URL-string but does nothing to get previous looking page after you click Back Button. So it's smth different.
Here's my code and example.
I have such site (look at the pic below). Header-div and Content-div. At the begining when you first time open it, the URL is mysite.com/page1.php. I want to change content in Content-div without reloading page. Just new info should appear in Content-div. And the URL should change to mysite.com/page2.php.
Here's HTML-code.
<div id="content"></div>
Reload Content
Here's JS-code to it.
document.getElementById("relaodLink").onclick = function() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "page2.php", true);
xmlHttp.send();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
document.getElementById("content").innerHTML = xmlHttp.responseText;
}
}
return false;
}
So Header should not reload after pressing relaodLink, just content in Content-div changes. And most important: URL should change like page was really reloaded. Back Button allows to go to mysite.com/page1.php and then Forward Button allows to go back to mysite.com/page2.php again. With history.pushState() methods it doesn't work. But in FB Back and Forward Buttons work fine. How to make it?
(source: ljplus.ru)
This is an excellent question. If you observe, you can notice that the back buttons and forward buttons will work in gmail also though it is completely built on Ajax.
The browser back and forward buttons work on storing what is there in the address bar. So in Ajax, if you never change what is there in the address bar, it doesn't go into the history and hence back and forward buttons don't work.
For this to work, you need to append something to the address bar constantly.
For example : In gmail,
When Inbox is clicked - https://mail.google.com/mail/?tab=mm#inbox
When Starred is clicked - https://mail.google.com/mail/?tab=mm#starred
When Sent is clicked - https://mail.google.com/mail/?tab=mm#sent
So in this way, gmail keeps appending to address bar. Hence history is preserved. The same goes with facebook also. Though the page is not refreshed, the location in address bar changed - that's the key here !!
I hope it helps you !