Appium iOS Safari Open new tab, accept alerts and switch between two tabs - ios

So I'm testing a web app for which I have to open a new tab, switch to it, do some input, than switch back to the first tab and this more than once.
I try to open the new tab this way:
((JavascriptExecutor) AppiumTestBase.getDriver()).executeScript("window.open('http://google.com', '_blank')");
This causes the following alert to appear:
But I'm not able to accept it through automation with Appium. Things that I have tried:
Using the following capabilities: "safariAllowPopups" and "autoAcceptAlerts"
Changing the according settings for safari in the iOS sim
.switchTo().alert().accept(); I also waited for the Popup.
Switchting to native context before accepting the popup
Clicking the pop up by name .findElement(By.name("Allow")).click();
What I have not tried:
Taping on the screen according to the pop-up coordinates. I didn't try this since I'm not sure on how to get the position of the "Allow" button.
And my other question is how would I switch between two tabs? I haven't tried anything yet, but research would suggest that I try it with window contexts.
Some other information:
Currently testing with a iPhoneSE iOS 9.3 Simulator, the solution should work for several configurations
Appium is on the most recent version
The class "AppiumTestBase"s only purpose is to set capabilities and initialize the AppiumDriver

Please try this cap after i change to this no popup from safari anymore
desired_capabilities=automationName:XCUITest,browserName:safari,platformName:iOS,platformVersion:11.1,deviceName:iPhone 6,nativeWebTap:True,safariIngoreFraudWarning:True

I tried the solution suggested by Atthaboon Sanurt, but it didn't help.
There was no alert, but the new window/tab didn't open either.
Here where the problem is reported:
https://github.com/appium/appium/issues/6864
So far it looks like there is no solution and plans to fix it.

Related

How to dismiss the UIActivityViewController during a UI test with Xcode 11 & iOS 13

Apple has re-designed the share sheet that appears, which has now broken my UI tests.
I have attempted to record a new UI test through Xcode, but as soon as I tap on the dismiss button, the test terminates so I have not been able to capture the event.
Ultimately, I just want to know how I can access the gray 'X' shown with the arrow below:
I have just tested this with Xcode 13 and have found that the original answer no longer works. However, I am keeping it for posterity, or those using previous versions of Xcode.
Xcode 13
I have tested this with Xcode 13.0 and verified it works for iPhone and iPad:
let activityListView = app.otherElements.element(matching: .other,
identifier: "ActivityListView")
XCTAssertTrue(activityListView.waitForExistence(timeout: 2.0))
activityListView.buttons["Close"].tap()
Previous versions
After some trial and error, I was able to locate where my specific elements were with the following:
app.otherElements.element(boundBy: 1).buttons.element(boundBy: 0).tap()
Using app.otherElements.element(boundBy: 1) would identify the share sheet for me. I had attempted to locate it through accessibility identifiers, but I could not find one that worked, including previously valid ones used in iOS 12 and below.
Please note that based on the layout of your screen, the index value
may differ from what I am seeing.
Next, .buttons.element(boundBy: 0).tap() was used to locate the Close button. I again attempted to use identifiers, but could not find anything that represented the button.
When I attempted to discern additional information through the console while testing, I would always wind up crashing the test. This result was surprising, as I was able to query these elements with Xcode 10.
Ultimately, I would like to find working identifier values so that I can have something that works reliably across products, without the trial and error to find the share sheet's index value.
For iPad
The following will dismiss the popover for an iPad:
app.otherElements["PopoverDismissRegion"].tap()

How to debug Siri extension in 'Type to Siri' mode?

There is an option in iOS 11 global preferences: General/Accessibility/Type to Siri. If it is enabled, when you open Siri it shows you a text field into which you can type your request instead of saying it.
This option works fine when I run Siri with the device's home button. But when Siri is started through the Xcode's bebug session of my extension, the textfield is not shown and I need to speak to it.
Is there a way to force siri to be opened it the Type mode when started from the Xcode debugger?
I have found a workaround:
When you start Siri from the debugger, wait for it to show you the label 'What can I help you with?'. Then tap on this label and drag it to the bottom of the screen and release it there. The label will disappear and the textfield 'Type to Siri' will be shown.
For this trick to work you still have to enable General/Accessibility/Type to Siri option in iOS preferences.
Alternatively, if you want to debug your Siri extension with a specific fixed query, you can set it as a debug schema parameter. Click on your intent extension schema, click edit schema, Run debug > Info tab> Siri Intent Query

Appium: iOS, real device, driver.hidekeyboard() doesn't operate

I'm using Appium on Mac OS with iPhone 5S with operation system 9.2.
When i'm trying to hide the Keyboard with the method:
driver.hidekeyboard();
Nothing happens and the application crash.
Need help please
Thanks
Ohad
If in case your application is crashing on when you are trying to hide the keyboard, then that could be a possible bug you are looking at and to understand the cause of that and get it fixed would be the topmost recommendation. Your statement
driver.hidekeyboard();
is good enough for what you desire out of the execution assuming the driver used is AppiumDriver or its subclass.
Also if you are sure that the keyboard is displayed and you can even manually hide the keyboard, a forced way to do that is as #Gaurav has suggested in the comments using the following code :
driver.navigate().back();
In case of uncertainty of the visibility of keyboard, you can give this a try :
driver.getKeyboard();
driver.hideKeyboard();

Testing Action Extension with UI Tests

Is it possible to perform UI tests on Action Extension targets? I am unable to create a UI testing target with the Action Extension as the "Target to be Tested." I am trying to load the Action Extension from within Safari (or Photos, although Safari/both is prefered)
If I record my interactions I can get as far as:
app.icons["Safari"].tap()
I can then manually add:
XCUIDevice.sharedDevice().pressButton(.Home)
before the generated code, but it doesn't work as expected (the simulator is left on the home screen).
I have also tried:
UIApplication.sharedApplication().openURL(NSURL(string: "https://google.com")!)
but that also doesn't open Safari.
I'm not even sure if I'll be able to interact in an automated with with the Action Extension if it does get launched, but hopefully it'll be possible.
So, it's possible to switch apps with XCUITest, but it's undocumented. If you check out Facebook's WebDriverAgent, they did a header dump and made a helper for launching from the springboard. You can call:
XCUIApplication* safari = [[XCUIApplication alloc] initWithPrivatePath:nil bundleID:#"com.apple.safari"];
[safari launch];
And then interact with Safari just like you do your app. However, I've run into a similar problem where XCUITest won't actually launch the extension itself. Once open (i.e. you tap physically on the extension button while the test is running), the test runner works perfectly, and you can interact with your extension in the same context as your app. However, having the test runner tap to launch the extension does nothing. I've also got an Apple Dev Forum question going on this topic.
Update:
It turns out if you use the app to press the screen at the location of the button, the extension will load and you can interact with it! Note that the API for tapping a coordinate is very wonky. The x, y are multipliers of the frame of the thing that you created the coordinate from. Relevant sample code:
// app is your XCUIApplication
// In this case we are tapping in the horizontal middle and at the y coordinate 603 (this is for a 6+ screen size)
XCUICoordinate* coordinateOfRowThatLaunchesYourExtension = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 603.0 / 736.0)];
[coordinateOfRowThatLaunchesYourExtension tap];
This will press the button for your extension in the action sheet, after Apple's extension picker has been invoked. For whatever reason / bug in XCUITest simply pressing your app in the action sheet doesn't work:
[app.sheets.staticTexts[#"MyApp"] tap];

How to show user location on XCode 4.5 simulator - prompt won't appear?

I have an MKMapView in a View Controller for my app and I checked "Shows User Location" in the Attributes tab of the MKMapView. The first simulation took awhile to load, as I expected, and the prompt came up asking whether to show the user location (Don't Allow / Allow). I chose 'Don't Allow' just to test the option first, but now the prompt will not return and I cannot show user location at all. I searched for an answer but could not find one. Sorry, I'm still a beginning iOS developer!
Thanks!
Answered below by Nico: Reset the simulator, don't be a noobie. Silly me!
Reset your simulator permission : in the simulator -> Settings -> reset.

Resources