Xcode 8: UI Testing, Neither element not any descendant has keyboard focus - swift

I've recently started to use UI testing within Xcode. I was able to record the test and play it back and it worked perfectly fine. I recently changed the accessibility labels for textFields to make the test look cleaner by giving it a better name.
However, now when I record the UI test and play it back again to test it, I get an error "Neither element not any descendant has keyboard focus.". I've attempted to uncheck hardware keyboard as mentioned in other posts, but that doesn't work for me.
//test login with username and empty password
let app = XCUIApplication()
let elementsQuery = app.scrollViews.otherElements
let emailtextfieldElement = elementsQuery.otherElements["emailTextField"]
let passwordtextfieldElement = elementsQuery.otherElements["passwordTextField"]
emailtextfieldElement.tap()
passwordtextfieldElement.tap()
emailtextfieldElement.tap()
app.typeText("wayne#test.com")
passwordtextfieldElement.tap()
app.buttons["Login - signInButton"].tap()
Anybody know the fix for this?

Use typeText on emailtextfieldElement instead of app.
let emailtextfieldElement = elementsQuery.otherElements["emailTextField"]
emailtextfieldElement.tap()
emailtextfieldElement.typeText("wayne#test.com")

Related

Xcode Swift 5 MacOs app empty window when archived but works when running it from Xcode

I am building an app for Mac which logs into a website based on login and password collected from textfield and secure text field, then app opens an url which is created in my app based on date range selection with use of two date picker cell calendars. Next app displays html data in webWiev (using WKWebView), converts html to string using extension NSAttributedString and then saves retrieved data as txt file. Everything works as expected as long as app is run from Xcode "play" button. Problem is if I archive this app and launch it, it will bring up an empty window without any button, calendar or textfield. There are no errors, no crash logs on organizer, nothing.
I decided to perform a little test. I build another view controller with only one button which upon clicking will show my app main view controller. After archiving this modified app and running it outside of Xcode a window shows view controller with one button which is correct. But after clicking it nothing happens. App works great if running "inside" Xcode, a pushbutton shows main ViewController correctly. Do You have any clue what can be wrong? thank You!
Edit 1. So I found a discussion on apple which mention this problem. It is associated with IB WKWebView and problem is already known since some time. Now I have to get around the problem. Apple forum link: https://forums.developer.apple.com/thread/116047
Did you embed WebKit.framework to your app?
After comment that I wrote, I founded a solution and solved with this method.
Please check it out.

Locating element in Xcode UI Test without accessiblity id

Recently I started learning XCode UI Test to write functional automation tests using UI testing feature of Xcode.
I need to read a text value of native app element. I can get the element with the help of text of element but the problem is I can not use the text as it is dynamic it will be changed after some time or next launch of app.
I am familiar with using WebDriver and Appium where I can tackle this with writing parent - child xpath.
Can anyone suggest a solution to this problem? Please post a sample code snippet as well with your solution as I am new to apple technology / swift.
Appreciate your help.
In your app's code, add an accessibility identifier to the element you want to inspect, then use that identifier to find the element in your UI test code.
// app code
let myLabel = UILabel()
myLabel.accessibilityIdentifier = "myDescriptionLabel"
// add other label configuration...
// UI test code
let app = XCUIApplication()
let descriptionLabel = app.staticTexts["myDescriptionLabel"]
let description = descriptionLabel.value as String

How to always show alert of my Cocoa application pop up all other applications?

I create the app simple. the app just remind work. I have problem how to my Alert always show pop up all other app. I tried code but my alert will hide when use other app I want my alert look like this alert in image
I tried code
let myPopup: NSAlert = NSAlert()
myPopup.messageText = "Notification"
myPopup.informativeText = "Hello world"
myPopup.alertStyle = NSAlertStyle.WarningAlertStyle
myPopup.addButtonWithTitle("OK")
myPopup.addButtonWithTitle("Cancel")
myPopup.runModal()
But when I use other app it hide.
I want always show alert.
You can tutorial code example help me ?
I just beginner. I want writer app remind simple. I spent a whole day to do it but i can't. please help me.
You can modify the windowLevel property of your alerts window object. NSModalPanelWindowLevel should give the desired effect.

My App crashes when iCloud status changes

I know there is a similar question but the OP seems to think his problem was only on the simulator and so not such an issue... But I think mine is in both.
I was having a problem adapting an app for iCloud storage (when trying to observe for NSUbiquityIdentityDidChangeNotification). I could not see what the problem was with my code and so...
...after hours of banging my head against a wall I have set up a new project in Xcode (v6.1 6A1046a) to try and narrow it down. It seems it must be a very basic problem indeed...
The only things I have done in this new projects are:
Enable iCloud capabilities for 'Key-value storage' and for 'iCloud
Documents'(using the default container) - no error messages, appears to be set up fine.
Add a label and a button to the provided view controller in IB.
Add an IBOutlet for both and hook up an IBAction to change the label text when pressed.
For clarity, the only code I added to an empty 'Single View Application' template is:
#IBOutlet weak var label: UILabel!
#IBOutlet weak var button: UIButton!
#IBAction func buttonPressed(sender: AnyObject) {
self.label.text = "You pressed the button"
}
So if I run the project from Xcode in the simulator or on the device, or if I run the project directly on the device, it launches fine and the button works properly - as you would expect...
The problem is:
If I am running on the device from Xcode & I go to the Settings->iCloud->iCloud Drive on the device and toggle the switch for my app (from/to either state) the app crashes. I'm getting no feedback except this:
If I am running the app directly on the device and try and toggle iCloud Drive setting, when I go back into the app it appears to restart (the view is being reset, along with the label.text - neither of which happen if I just visit settings without touching the switch).
It also has the habit of freezing my device completely, which is mildly irritating.
I'm new to iCloud development so I guess I may be missing something really basic...
As I say it's an empty project with only a couple of lines of additional code so it's probably not something I HAVE done. Which limits it to something I HAVEN'T done. I am trying to follow as many tutorials as I can find and as much apple documentation as well. I just can't see any obvious steps I may have overlooked.
Unless it's the expected behaviour, or an Apple issue I guess.
Thanks for any help - it's driving me nuts!
iOs kill your app when you change iCloudDrive state. This is standard iOs behavior you can check this with build in applications(Safari for example).

Not able to enter a string in the TextField of UI-(iphone)

I brought a new MAC-MINI before this i was using MAC BOOk Pro..
i am facing some problem with xcode, the problem is when i run the Application where ever there is a TextField in the UI when i click to enter its not taking input,it takes hardly 1 or 2 strings and throws thread....
when i try to enter its throwing Thread in main() function telling EXC_BAD_ACCESS...
NOTE:The apps which were working before in Mac book Pro's xcode i mean apps which contains TEXTFIELD in the UI is also not taking input in the present xcode of MAC MINI.
if i tried without writing any code just placing a TextField in the UI and running it ,even then i am not able to enter anything in the UI its just throw Thread in main() function EXC_BAD_ACCESS..
I am not able to solve this issue may i know why its happening like this?
ITS NOT TAKING ANY INPUT IN TEXTFIELD OF PREVIOUS WORKING APPS AS WELL..
Is the problem with Xcode?
Plz Suggest me to solve this issue..
Thank u
Are you setting an object as the textField's delegate?
When you type in the text field, it tries to call its delegate (if it's not nil) to notify about a change in the text. If for whatever reason the delegate is dealloc'ed, you get this type of error, as the textField is trying to reference a deallocated object.