I have a button whose text changes based on certain criteria. I want to test this functionality with XCUITest but I can't seem to be able to access the text on the button.
I have tried
button.staticTexts
button.value
button.title
elementsQuery.buttons["My Button"] //This uses the accessibility label
How can I access the text?
I know this is old but try this:
let app = XCUIApplication();
let buttonText = app.otherElements["My Button"].staticTexts;
If this doesn't work let me know. Currently working on iOS XCUITests myself
Related
I wanted to make a kind of a notes app where users can add images inline with text, similar to how iOS' native Notes app does. Any advice on approaches I could take for this?
I'm new to iOS development and have been trying to teach myself a bunch of necessary skills and was curious as to how someone would go about doing this.
Thanks!
You can use UITextField to add images and text in one field, It can be done by using storyboard also and to do it programmatically is also convenient. Find the below code to add image programmatically in a text field :
var imageView = UIImageView()
var image = UIImage(named: "email.png")
imageView.image = image
emailField.leftView = imageView
emailField.leftViewMode = UITextFieldViewMode.always
emailField.leftViewMode = .always
UITextView is your best bet. It is not the most friendly UI component to work with if you are just starting out, but it is what Apple almost certainly uses for their Notes App, and supports inlining of text, images, hyperlinks, styles etc.
I'm attempting to put a subtitle under a title in the action bar on iOS. While there is this solution for Android it doesn't work on iOS at all. Is there any way to do this on iOS?
<ActionBar [title]="This works" [subTitle]="I want a subtitle here"></ActionBar>
iOS doesn't have a subtitle option. But you could use a custom title view and wrap two labels one below another.
iOS has some sort of subtitle, but it is named as prompt (for more detail, you can see the doc for UINavigationBar).
Unfortunately, you can't set its value from XML, so you need to use some handler - I create simple playground to demonstrate prompt property.
I am currently trying to display quick type suggestions for the user's email address when the user is editing the email text field as well as the email confirmation text field. To do that, I set two things:
the text field's textContentType as well as its autocorrectionType to get the quick type bar to appear.
However, it seems that setting the textContentType has no effect on the contents of the quick type bar; it simply displays "words" as they would appear when editing any other text field. This is obviously not the result I want my users to see.
Here is the current code:
SEL selector = NSSelectorFromString(#"textContentType");
// Make sure that the text field is actually able to process the event,
// the iOS version is greater than 10.3
if([self.emailTextField respondsToSelector: selector]){
self.emailTextField.textContentType = UITextContentTypeEmailAddress;
self.emailConfirmationTextField.textContentType = UITextContentTypeEmailAddress;
self.emailTextField.autocorrectionType = UITextAutocorrectionTypeDefault;
self.emailConfirmationTextField.autocorrectionType = UITextAutocorrectionTypeDefault;
}
From what I've read, this works for 3rd party apps only starting from ios 11
I've exported and compiled an iOS version of an app from the Ionic framework. I'm using Automate UI Testing in iOS's tool instruments. Everything is working fine except for when I use setValue() to fill the login textfield and password textfield. The Boxes are filling with text and when I use the inspect element the values are picked up by the inspector. The problem is when I press login the login and password validations trigger as if there is no text at all in the text boxes. I tried looking all over the net and couldn't find anything relating to my issue. Any help would be much appreciated. I've posted a pic and the code I'm using below.
var target = UIATarget.localTarget();
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);
var app = target.frontMostApp();
var window = app.mainWindow();
var scrollView = window.scrollViews()[1];
var webView = scrollView.webViews()[0];
var textField = webView.textFields();
//target.tap({x:28.00, y:28.50});
target.delay(2);
webView.buttons()["LOGIN"].tap();
target.delay(1);
webView.textFields()[0].tap();
target.delay(1);
webView.logElementTree();
webView.textFields()[0].setValue("username");
target.delay(5);
webView.secureTextFields()[0].tap();
target.delay(5);
webView.secureTextFields()[0].setValue("password");
target.delay(5);
webView.buttons()["LOGIN"].tap();
login screen
I'm struggling to type text in a UIWebView that is embedded in a native UIViewController. I loaded google in the web view, and I'm simply trying to enter "Hello". Recording suggests using app.typeText("Hello") but I keep getting the error
UI Testing Failure - Neither element nor any descendant has keyboard focus.
Any suggestions?
Project showing the issue, please test your possible answer by checking out this source by running from Terminal:
git clone git#bitbucket.org:Smaljaars/uitestingexample.git
UPDATE I found a workaround for typing text in a text field inside a web view:
func testWorkAroundForProblem() {
let app = XCUIApplication()
app.otherElements["Zoek"].tap() //this is language dependent! (no accessibility identifiers within webview)
// UGLY WORKAROUND FOR THE PROBLEM
let textToType = "XCTest slow search Google"
for character in textToType.characters {
if character == " " {
app.descendants(matching: .any)["space"].tap()
continue
}
app.descendants(matching: .any)[character.description.lowercased()].tap()
}
app.webViews.buttons["Google zoeken"].tap() //this is language dependent! (no accessibility identifiers within webview)
}
First make sure the search box has focused. The Accessibility Inspector shows that you should be able to access it via "Search". Oddly, Google marks the field as a combo box.
let app = XCUIApplication()
app.comboBoxes["Search"].tap()
app.typeText("Hello")
On the iOS Simulator menu, go to the Hardware dropdown and toggle the 'Connect Hardware Keyboard' setting.
This sometimes prevents UI tests from typing in text boxes.