UI Automation in iPhone App - iphone

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?

Related

How to pass information from one app and show it in another app using startupFcn(app) method in matlab?

I have two apps that I designed using app designer 2016b, the the first interface is a login screen that takes the username and the password and has a login button, when the login button is pressed the second app appears which should have the username that the user typed in the login interface.
The problem that I am having is that I am not able to show the username in the second app using startupFcn(app) method, it only shows if I put the code in button callback which I don't want.
Here is that code that I used in the login in to send the data:
function LOGINButtonPushed(app, event)
v = app.EditField_2.Value;
y = v;
g = MainInterface;
g.Data = y;
close(gcbf);
And here is the code of the second app which is suppose to retrieve the username and put it in a label:
function startupFcn(app)
results = app.Data;
set(app.UsernameLabel,'text',results);

JScript setText() in email and password not being read

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]");

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.

Saving page preference in site navigation using SiteMapPath control

I have created site navigation in my ASP.net application using SiteMapPath control and its working fine. Now my requirement is that, there is open page in my application which has Radio buttons and based on their selection datagrid is populated from database. I want to save the radio button selection in navigation url so that when I click on that page through navigation url then page will display the data from my selected options.
Any help would be highly appriciated.
Thanks,
Yogesh
I'm not sure that I understand. I propose some other solution (using Session). Add event to radioButton onSelectionChange. When selection change, remember this in Session
Session["name_param"] = some_params;
And in form with dataGrid get event PageLoad with code:
if ( Session["name_param"] != null ) {
var param = Session["name_param"];
// using param to load data to grid
} else {
// something else, maybe default chance for data to grid
}

How to enter the text in search bar using UIAutomation?

Could you please help me out in entering the text in search bar using UIAutomation scripts for IPhone Application.
Thanks in advance,
Madhu.
UIASearchBar inherits from UIATextField:
http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIASearchBarClassReference/UIASearchBar/UIASearchBar.html#//apple_ref/doc/uid/TP40009913
Try the "setValue" method:
searchBar.setValue("search for this");
Since through tap input method you communicate with the device, you can try user-like type of action: tapping.
To bring up the keyboard you just tap on the text input field:
someTextInputField.tap();
But be aware of the fact that there is no keyboard object instance available for actions if you do not activate the keyboard itself by tapping on any text input field.
Once the keyboard is activated:
var App = UIATarget.localTarget().frontMostApp();
var Keyboard = App.keyboard();
var Keys = Keyboard.keys();
var AltKeys = Keyboard.buttons();
Where AltKeys represent service buttons like Shift, Done, etc.
And Keys represent all other buttons.
P.S. Keep in mind that you have to switch between keyboard tabs to get access to either characters, numbers, special characters.