is it possible to test web app using Xcui? - xcode

I am looking into Xcode and Xcui for web app and cannot get it work. to start up recording, build or whatsoever it needs a valid executable which I don't have since i am not building an app. is there any way to launch Safari as the app and then record it and run tests?
i know there's Appium and other tools but wondering if it's possible and if so I would be keen to implement some in swift.

NOTE: This is a super hacky way to get it done:
I think you would have to create a quick application that holds a web view in the app, that launches to your respective web page.
You can write automated tests for this app which will simply land you on your web page
You will not have access to elements, like table views, cells, or anything in the XCUIelement tree
You will have to do everything based on frames and coordinates
You can determine where all your elements are and set them up as variables and call them like this:
`let myButton = XCUIApplication().windows.element(boundBy: 0).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.30))`
myButton.tap()
Not ideal but if you want to use swift to learn and move things around its possible

As far as XCUI testing is concerned, it was basically made to test the integration flow of an iOS app. As a result it can ONLY test native view controllers. As far as the web view is concerned, it should be tested at the web level and not at the application level.

Related

UI Automation for AppleTV system using XCode

Is UI automation available for the main menu of the Apple TV and not a specific application? I already setup the whole UI testing thing using XCode and tried using the remote control but it is only available for the application that was defined using XCUIApplication.
So is it possible to control the whole system rather than a specific application? I was thinking of something similar to pyatv but using XCode since I might be able to get more information concerning the current focused apps and so on.
There is an API XCUIApplication(bundleIdentifier: ) to interact with not-AUT apps. You need to substitute the right identifier for this Springboard-like interface. Maybe it is a Headboard, but I'm not sure.
Bundle identifiers of tvOS apps https://github.com/rzakhar/XCTApps/blob/master/Sources/XCTApps/tvOS.swift

Pros and cons of splitting Cocoa utility app into helper binary + main app binary?

I'm modernizing and sandboxing an old Cocoa utility and considering approaches. The app lives in the menu bar and works in the background, but shows a Dock icon and a configuration window when the icon is clicked.
There are two approaches:
A. A single binary with LSUIElement=YES, using TransformProcessType to show and hide the dock icon as necessary.
B. A helper tool performs the actual app functionality, manages the menu icon and always runs in LSUIElement mode in background. The main app presents the configuration UI and is only launched when necessary.
The app currently does A. I've noticed that many long-running utility apps have separate helper binaries and basically do B. Examples on my Mac include Paste Helper, TimingHelper, Discord Helper, CCC Helper (for Carbon Copy Cloner), 1Password Extension Helper.
I understand that having a separate helper app is conceptually more pure and potentially allows for better separation of sandbox privileges, but it's also harder to implement, so I doubt that's the sole reason why all these apps opted to have a separate helper binary.
So:
What are the pros and cons of A and B, i.e. why do some choose B over A? Is it required to get some functionality these days?
Is it even possible to have a helper tool outlive the main app in a sandboxed Mac App Store app?
What API does one use to make such a helper? The old-style authorisation APIs seem deprecated, and XPC does not seem like it allows a helper app to launch at startup (and even outliving the main app may be hacky)?
I suspect the reason so many developers choose option B is because this arrangement is now baked into macOS via the "Login Items" facility.
In a nutshell, your main application embeds a second (helper) app and that app is configured as a "Login Item". macOS detects this and automatically adds your helper app to the user's login items. You can control this, programmatically, using SMLoginItemSetEnabled(...).
You end up with a regular app users are familiar with, and a helper app that automatically starts at login and can run in the background. I'm also pretty sure this includes a free XPC connection you can take advantage of.
Read all about it in the Adding Login Items section of the infamous Daemons and Services Programming Guide.
I've never done this myself (I currently install background apps as user agents, which I can do because I don't have a sandboxed app), but I did research it for another project and I know a lot of apps do this.
One disadvantage of option A (based on user feedback from my own apps) is that the main app won't act like a regular app. Using the A approach, your users either can't quit the app (because it will need to automatically restart) or you need a way to hide it in the dock, and then there's no (obvious) way to launch it again. It just gets confusing. If you do let your users quit the app, then the background functionality goes away, and that creates other problems.

How can Xamarin be used to wrap a web app as if it were a native app for Android?

Say I build a super mobile friendly web application that I want in the Play Store for Android users to be able to download.
Could I use Xamarin to:
Wrap the entire mobile app as a single WebView
Register for mobile push notifications
Essentially shortlining an MVP of an android app by using an existing web app? If so, is there any well-known process or documentation that demonstrates this?
Probably the best approach for you would be using Xamarin Forms with one or more pages containing only web views.
I don't love Xamarin Forms because usually for me Xamarin Android+iOS gives a better result in similar time, but your app would be so simple that doesn't make sense to do it with Xamarin Android.
Make sure that your web app will show only what makes sense to be shown in your app, otherwise you risk to see double header/footer, useless buttons... but if the website is yours adding a few parameters to change a bit the UI won't be a problem I guess.
Have a look at this example:
https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithWebview
Another approach is the use of Razor to build your pages in html directly inside your app, but if I understood well it's not what you need:
https://developer.xamarin.com/guides/cross-platform/advanced/razor_html_templates/
Although it is technically possible to do this as the previous answer has suggested. I would recommended firstly reviewing, the relevant stores guidelines on submissions. Apple for example will not allow a submission to their store of any application that simply mirrors the functionality of a website. I suspect Google's would likely be the same.
However that said, to answer your question, Xamarin.Forms would be appropriate for a simple application like the one you are suggesting. Or if you prefer to build to a specific OS, then in iOS with Xamarin you would use the Safari View Controller that was added in it's xcode 8.1 release. Android uses something similar as does windows.
EDIT:
You can use the Web View control in Xamarins Andorid native PCL project to encapsulate your mobile friendly website within an application here is the documentation:
Xamarin Android Developer link to Android Web View
As for push notifications, yes this is perfectly possible using Xamarin.Android. and varies on implementation depending on what you want to use as the back end to handle them, I.E. Azure's notification hub etc.

Can I manipulate Web pages from Xcode UI Testing?

I have my test cases written in Swift3 UI Testing in Xcode, my test cases run in an iOS application in simulator. One of our functionalities is bring assets into our app from dropbox, whenever we tap on dropbox icon (from our app) the dropbox web site opens to allow the user to LogIn. my question is, is there any way to use swift code that can automate the logIn on the web site? I would like to automate all that process.
No, there is no way to use XCTest UI tests to test anything other than an application you created.
The tests are only able to interact with a single application, and the bundle ID must match the bundle ID in the Info.plist for the UI tests.

In a codrova/phonegap based Xcode project, how do i turn my single view app into a multiple view app?

I have set up Cordova/phonegap to work in Xcode and written a simple app in HTML and CSS and tested it on the Simulator and it works. It's just a single view app. I am trying to figure out how to turn that into a multiple view app, so that there are several views/screens that link to each other.
Do I need to write several HTML documents and link them together in XCode, or is it written in one HTML document using JavaScript?
With PhoneGap, think of it as operating a tiny web server on your device. So, you build it out like you would any other web site - with links to other pages that sit in that folder/directory or even on other servers - and it will allow that navigation. So, once you get it set up and deployed via Xcode, all you need to do is modify the html/css/js.

Resources