Open universal links (deep links) with XCUITest - xcuitest

I would like to create several tests for native iOS application. To be more precise, I want to test deep links. But I am not sure how to trigger deep link with XCUITest and I don't really see how launch() and launcArguments (https://developer.apple.com/documentation/xctest/xcuiapplication) can help me. Did anybody have a chance to open deep link with XCUITest?

In iOS 14 using Spotlight seems to work well:
private func open(_ urlString: String) {
XCUIDevice.shared.press(.home)
XCUIApplication(bundleIdentifier: "com.apple.springboard").swipeDown()
let spotlight = XCUIApplication(bundleIdentifier: "com.apple.Spotlight")
spotlight.textFields["SpotlightSearchField"].typeText(urlString)
spotlight.buttons["Go"].tap()
}

Set safari as app like this
let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
Open your email in safari
Tap on the link
Normally assert some element on app

I never tried this, but this idea comes to my mind. Create a new dummy project/application that should only contain some links pointing to URLs that you expect your original app to open. From that new application, write some UI tests that tap a link, like this:
func testOpeningLinks() {
let app = XCUIApplication()
app.links["Some link text"].tap()
// This is the place where your original app should be opened...
// Find the XCUIApplication object:
let originalApp = XCUIApplication(bundleIdentifier: "original.app.bundle.identifier")
// You should be able to find some views from original app from here, eg. a button:
let button = originalApp.buttons.element
}
This would work only if you have previously installed your app on the device/simulator where you're running your UI tests.

Related

WKWebView Canvas issue. Links inside canvas aren't doing anything

I'm having an issue with WKWebview.
I'm loading a canvas from html into the Webview.
This is the link:
https://cdn-factory.marketjs.com/en/color-fill-playable-ad-demo/index.html
it runs perfectly the html game loads and everything seems to be okay, the touch events are working when you play the mini game tough there is a button "install now"
that should open the app store url and when i tap it nothing happens.
On browser it works and i have tried few of those games but nothings works.
Any advise? the webview preference allowjs and allow inline media are set to true.
Aside that i couldn't find any info on it.
Help is appreciated :D thanks !
iOS: 13.4.1
Swift: 5
iPhone xs max
Okay i figured it out.
In case someone will bash into it in the future.
So the webpage used:
window.open("http://asdfsadfsda")
javascript code to open the url in a new window.
WKWebview wont do anything unless you will implement the WKUIDelegate and the method
webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
for navigationAction: WKNavigationAction,
windowFeatures: WKWindowFeatures) -> WKWebView?;
another important thing in order to make this method to get called is to set in the webview preferences like this:
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
let configuration = WKWebViewConfiguration()
configuration.preferences = preferences
configuration.allowsInlineMediaPlayback = true;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = true
configuration.preferences.javaScriptEnabled = true
And then you can handle the new page opening in the delegate method.
If you still want a new window you should create a new webview and return it in the delegate method.
In my case it was to do nothing and just take the url etc..
so i returned nil.
Good luck :)

Adding API's to chromium build in Electron framework

I would like to write custom functions in Window API in chromium source code. So how do we do it?
In case of doubts about window API here's a link to what I mean click here. I would like to have custom property functions analogus to those shown in the link.
It's for a github electron project.
Well after a week of searching I finally found the solution. Thanks to a pull request by magicae#github.
You need to look create your custom function in
electron/atom/browser/api/lib/atom_api_web_contents.cc
as say
bool WebContents::GetOkOk() {
return true;
}
And define the same in it'h header file
electron/atom/browser/api/lib/atom_api_web_contents.h
as
bool GetOkOk();
Lastly you need to export the function through the webContents method located in
electron/atom/renderer/lib/web-view/web-view.js
as
/* Public-facing API methods. - modified by Akshay Thakare */
methods = ['getOk','getURL', ... ];
And you are good to go.
Finally after you compile your electron app,
in the main.js file add,
console.log(mainWindow.webContents.getOk());
and your done.
As JS is prototype oriented, you could simply extend the BrowserWindow API
var BrowserWindow = require('electron').BrowserWindow; // main process
var BrowserWindow = require('electron').remote.BrowserWindow; // renderer process
BrowserWindow.foo = function() {
console.log('foo');
}
Not sure if you're looking for someting more specific, but I'm not sure you can extend it with heavy impacts on the system, could you explain exactly what you are trying to do ?

How to override focus engine update sound in tvOS

I am trying to override the sound that plays when a focus change is made on tvOS, but I cannot seem to find anything indicating if this is possible. I have looked through the Apple documentation a bit, and looked at some of the sound API's but none seemed to fit. Does anybody know if this is even possible? If this is possible how can this be achieved?
This can be achieved with soundIdentifierForFocusUpdate, which was added to the SDK in tvOS 11
Using this method, you can customize or remove the default sound of tvOS played on focus updates.
To remove the sound you can return UIFocusSoundIdentifier.none
override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? {
return UIFocusSoundIdentifier.none
}
To use a different sound insted, you must include the new sound file in your target, and to load as shown here below:
let myPing = UIFocusSoundIdentifier.init(rawValue: "customPing")
let soundURL = Bundle.main.url(forResource: "ping", withExtension: "aif")!
UIFocusSystem.register(_: soundURL, forSoundIdentifier: myPing)
Then you have to return that sound new from soundIdentifierForFocusUpdate:
override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? {
return myPing
}
Everything is documented by Apple in the following link:
Using Custom Sounds for Focus Movement

When using React-native, why does my iPhone or emulator hang with a white screen unless Chrome Debugging is on?

When running an app using react-native 0.4.4, I see that the app will hang the iOS emulator or the phone unless Chrome Debugging is turned on. Does anyone have an idea what is going on?
I'm not getting any errors at all on Chrome when I open it. I have noticed that the "sample" React-native app doesn't have any problems when running without Chrome, so it seems like it's something within my own code, but I have no idea what!
I took the react-native example code and started adding code from my existing project to it one file at a time until I found the offending line.
Here it is:
render: function () {
let buttonStyle = styles.disabledLgButton;
let buttonTextStyle = styles.disabledLgButtonText;
if (this.state.submitEnabled) {
buttonStyle = styles.activeLgButton;
buttonTextStyle = styles.activeLgButtonText;
}
It took me a while to figure it out, even when I was staring at the code that was breaking things.
I have gotten into the bad(?) habit of using certain ecmascript 6 features such as let. Chrome will deal with let without any difficulty, but the JavaScript engine on the phone chokes. As soon as I changed those let lines to var, the phone was happy rendering on its own without Chrome's help.

Share Target and JumpListItemBackgroundConverter

I've added the Share Target declaration to my app for the data format WebLink and everything works as expected. However, when I add a JumpListItemBackgroundConverter or JumpListItemForegroundConverter anywhere in the app, the app hangs on the splash screen when you enter the app using the Share from IE. No exception, no crash, the debugger doesn't even stop. All I get is a cryptic error in the output window, "The program '...' has exited with code -1073741819 (0xc0000005) 'Access violation'." The documentation for those converters say they're fine with universal apps, just that they've been moved to a different namespace. Has anyone been able to get these two things to work in the same app? If so, where did I go wrong? Or is there something better than those two converters to get the LongListSelector look and feel?
Steps to reproduce:
Create a new universal app. I chose hub.
Add a share target of format WebLink to the appxmanifest declarations.
Add a new page to point the share contract to.
Add the OnShareTargetActivated code to app.xaml.cs to open the new page. See code below
Add a JumpListItemBackgroundConverter to the resources of the main page of the app. You don't need to apply it to anything, just declaring it is enough to break the sharing.
Go to IE and share a link. It should hang on the splash screen.
Code for app.xaml.cs:
protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
// Replace SharePage with the name of the share target page
var rootFrame = new Frame();
rootFrame.Navigate(typeof(SharePage), args.ShareOperation);
Window.Current.Content = rootFrame;
Window.Current.Activate();
}
It turns out this is a bug in the emulator. It works if you test on a physical device.
MSDN Forum - JumpListItemBackgroundConverter and Share Target in Windows Phone 8.1