To open notification panel I use:
GesturesHelper.gestSwipeVertical(driver, 0.01, 0.9, 0.5, 1000);
witch is the function:
public static void gestSwipeVertical(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * startPercentage);
int endPoint = (int) (size.height * finalPercentage);
if (driver instanceof AndroidDriver) {
new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(anchor, endPoint).release().perform();
} else if (driver instanceof IOSDriver) {
new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(0,endPoint-startPoint).release().perform();
}
}
Then I make sure I'm on notification view (on iOS10 there are two views now). Finally I get the content from first XCUIElementTypeCell visible, because thats were the SMS I just received
You can watch this video : https://youtu.be/DW5VJzdICF8106
Hello @Telmo_Cardoso ,
Thank you very much for fast response. But we still failed to catch the message
Here is part of our code
private boolean catchCode(){
gestSwipeVertical(driver, 0.05, 0.9, 0.5, 1000);
logger.debug("Page Source:\n" + driver.getPageSource() + "\n\n");
try{
WebElement elem =driver.findElement(By.xpath("//*[contains(text(),'Your code')]"));
if ( elem == null){
logger.info("Code SMS caught, trying to extract text");
code = elem.getAttribute("name");
logger.info("Code SMS " + code);
//TODO - swipe up to close the panel - gestSwipeVertical(driver, 0.05, 0.9, 0.5, 1000);
return true;
} else {
logger.error("Code SMS not caught ");
return false;
}
} catch (Exception e){
logger.error("Code SMS not caught ");
return false;
}
}
private void gestSwipeVertical(AppiumDriver<WebElement> driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * startPercentage);
int endPoint = (int) (size.height * finalPercentage);
new TouchAction(driver).press(anchor, startPoint).waitAction(duration).moveTo(0,endPoint-startPoint).release().perform();
}
I receive "Code SMS not caught" because of NoSuchElementException after line
WebElement elem =driver.findElement(By.xpath("//*[contains(text(),'Your code')]"));
On iPhone screen I can see the OTP window reached by the program, so I believe swipe works as expected, but the field with the code still not caught
Page Source printed in debug doesn't show the OTP (it still shows only source code of my application under test) so I cannot use more specific xPath
Could you, please, suggest a solution?
Thank you, @chrisjywu, for suggestion.
Unfortunately, we need the code from received SMS since SMS is part of registration via application process and should be received after entering number on previous step
Hi,
you should have waits before finding element or it may be trying to find it before it being available (use FluentWait or WebDriverWait)
What I recommend is in debug mode, place a breakpoint on that line and use an inspector (p.e. https://github.com/mykola-mokhnach/Appium-iOS-Inspector38) and see if you can see the SMS. If you can, then its all about implementation.
Hi,
We tried to use the suggested inspector.
OTP not seen by appium even when only SMS on the screen
The same source code I receive when printing in log from my program (source doesn't contain OTP)
We have no such problem in Android application testing. Sure there should be some way to solve it for IOS application as well
Hope to find the solution with your help
Thanks for quick answer.
I have some questions, pls:
- Is that happens on all type of devices ?
- Do you think that this solution can help: https://appium.readthedocs.io/en/stable/en/advanced-concepts/wda-custom-server/51 ?
- Maybe there is any capabilities that can help ?
Thank you very much
Hi,
I hoped after upgrade to Appium 1.7.0 problem will be solved, but still no success
I tried to find solution in the article you provided, but the problem is that on my real device I can catch everything related to application under test. OTP is not caught since it’s a separate application. Did you mean some particular step?