YOU-i-Labs / appium-youiengine-driver

Appium You.i Engine Driver
Other
25 stars 22 forks source link

[Mobile]Accepting iOS 14.4 location alerts doesn't work. #172

Open kamil-nowocin opened 3 years ago

kamil-nowocin commented 3 years ago

The problem

Can't accept permission to use location on iOS 14.4

Environment

Details

I'm not able to accept location prompt on iOS. IMG_0057 Appium caps:

{
  "autoAcceptAlerts": true,
  "automationName": "YouiEngine",
  "deviceName": "iPhone",
  "deviceType": "phone",
  "platformName": "iOS",
  "platformVersion": "14.4",
  "udid": "00008020-XXXXXXXXX",
  "xcodeOrgId": "XXXXXXXXXX",
  "xcodeSigningId": "iPhone Developer",
  "youiEngineAppAddress": "192.168.1.48"
}

I've also tried to use driver.switchTo().alert().accept(); but seems that this command isn't implemented yet.

MJSONWP (316ae836)] Calling AppiumDriver.getAlertText() with args: ["316ae836-0636-4ece-be1b-5fa678451e66"]
[YouiEngineDriver] Executing YouiEngine WebDriver command 'getAlertText'
[MJSONWP (316ae836)] Encountered internal error running command: NotYetImplementedError: Method has not yet been implemented
[MJSONWP (316ae836)]     at YouiEngineDriver.executeCommand (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:327:13)

This might be appium issue, but I'd be grateful if you could check if youiengine-driver is working as expected in regard to accepting iOS alerts. Thanks! ps. I can provide more details if required.

Link to Appium logs

https://gist.github.com/kamil-nowocin/aece03e9b16dca34814d50b6c3581a49

dlenroc commented 3 years ago

@kamil-nowocin have you tried Appium v1.21.0 which includes appium-youiengine-drive 1.2.8 ?

In the latest version of appium, both solutions you tried most probable will works

  1. Capability: autoAcceptAlerts - #145

  2. Context Switching - #143

    // switch to xcuitest driver
    driver.context("NATIVE_APP");
    
    // all xcuitest driver commands now can be used
    driver.switchTo().alert().accept();
    
    // switch back to you.i driver
    driver.context("YOUI_APP"); 
kamil-nowocin commented 3 years ago

Hey @dlenroc I've tried today, but with appium 1.21.0 I'm not able to interact with app at all! I'm able to launch app, but then I'm facing timeouts - elements can't be found.

[MJSONWP (1d6df98d)] Calling AppiumDriver.findElement() with args: ["name","startScreenLander","1d6df98d-4cd2-497a-bac8-21b5ba0c6ea1"]
[YouiEngineDriver] Executing YouiEngine WebDriver command 'findElement'
[BaseDriver] Valid locator strategies for this request: id, name, class name, accessibility id
[BaseDriver] Waiting up to 0 ms for condition
[YouiEngineDriver] COMMAND: {"args":["startScreenLander",""],"name":"getElementByName"}
[MJSONWP (1d6df98d)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[MJSONWP (1d6df98d)]     at YouiEngineDriver.commands.findElOrEls (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-youiengine-driver/lib/commands/find.js:67:13)
[HTTP] <-- POST /wd/hub/session/1d6df98d-4cd2-497a-bac8-21b5ba0c6ea1/element 500 28 ms - 164

So, 1.21.0 It's even worse than with 1.20.2

kamil-nowocin commented 3 years ago

However with appium 1.21.0 I was able to switch context and accept alert, but I wasn't able to click on any element...

kamil-nowocin commented 3 years ago

OK I found the issue. If we are using android/ios bindings

@AndroidFindBy(id = "Select-City-Modal_Confirm-Button")
@iOSXCUITFindBy(id = "Select-City-Modal_Confirm-Button")
protected MobileElement confirmCityButton;

and we will call method by confirmCityButton.click(); It doesn't work at all.

BUT... If we'll use direct search like driver.findElementById("Select-City-Modal_Confirm-Button").click(); it works.

So, where should I report that 'bug'?

dlenroc commented 3 years ago

did you tried to wait for elements before interacting with them either via explicit waits or via initElements /AppiumFieldDecorator or @WithTimeout ?

if this doesn't help, then the most likely problem is in the appium / appium client, given that driver.findElementById works in your case, but you can wait a bit to see if someone from you.i can help

kamil-nowocin commented 3 years ago

Yes, I have fully customized automation framework with bunch of various explicit waits. Before every action on element; element must be visible/clickable etc. This is simple example of our wait condition:

 private void waitUntilCondition(ExpectedCondition<?> condition, String timeoutMessage, int timeout) {
        WebDriverWait wait = new WebDriverWait(driver, timeout);
        wait.withMessage(timeoutMessage);
        wait.until(condition);
    }
    public void isElementClickable(MobileElement mobileElement) {
        ExpectedCondition<WebElement> condition = ExpectedConditions.elementToBeClickable(mobileElement);
        String timeoutMessage = String.format("Element \"%s\" wasn't clickable after %d seconds!",
                mobileElement, LONG_TIMEOUT);
        waitUntilCondition(condition, timeoutMessage, LONG_TIMEOUT);
    }
    public void click(MobileElement mobileElement) {
        waitHandler.isElementClickable(mobileElement);
        Reporter.log(String.format("Clicking on \"%s\" button.", mobileElement.getAttribute(String.valueOf(ElementAttributes.NAME))), true);
        mobileElement.click();
    }

So yeah, I'm pretty sure this is working as expected since on Appium 1.20.2 I don't have any problems with element interaction.

lukeyoui commented 3 years ago

Hey @kamil-nowocin, just catching up on this thread.

Does this issue happen still when using a native driver (automationName: 'XCUITest')? I'm wondering if we are able to deduce where the root cause of the issue is: Appium driver, XCUITest Driver, or Youi Driver.

lukeyoui commented 3 years ago

Hi @kamil-nowocin, I tried autoAcceptAlerts": true with the same location prompt and it accepted the prompt correctly. This was using Appium v1.22 and youi driver v1.2.8

Please let me know if this is still an issue you are facing.

kamil-nowocin commented 3 years ago

Oh sorry @lukeyoui I didn't receive any notifications about any new comments in this thread... I'm on Appium 1.21 with youi driver 1.2.8 - I don't see any new Appium 1.22 release.

About alert I was able to make it work with workaround, Appium capability autoAcceptAlerts": true wasn't working for me.

This is how I managed to accept iOS permission alert (POC code)

driver.context(Context.NATIVE_APP);
driver.findElementByAccessibilityId("Allow While Using App").click();

This might be related to app structure or something. I don't really know, but I can confirm that autoAcceptAlerts": true wasn't working for me in that case.

About selectors I didn't try to use 'XCUITest' as automation engine, but I switched from

@AndroidFindBy(id="element_id")
@iOSXCUITFindBy(id="element_id")

to

 @FindBy(id = "element_id")

and it started working again - I hope this may be helpful information.

kamil-nowocin commented 3 years ago

Quick update if anyone will search information about this issue. On iPhone 8 "autoAcceptAlerts": true, work like a charm, problem is reproducible on iPhoneXR

lukeyoui commented 3 years ago

Thanks for the info! That leads me to believe that it might be to do with the XCUITest driver.