appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 755 forks source link

@WithTimeout error reports default timeout value #236

Closed justintilson closed 9 years ago

justintilson commented 9 years ago

I just started using the @WithTimeout annotation to customize the timeout for a few page object properties. It works great. However, if the property times out, the error message that is displayed is the default value.

For example

@WithTimeout(time = 30, unit = TimeUnit.SECONDS)
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.wholefoods.wholefoodsmarket:id/recipesSearchResultsGrid\")")
private MobileElement searchResults;

The property fails to load in 30 seconds and the TimeException displays the following error:

org.openqa.selenium.TimeoutException: Timed out after 12 seconds waiting for visibility of ...

This made me think that the @WithTimeout annotation wasn't working but it is.

TikhomirovSergey commented 9 years ago

Hi @justintilson It is very interesting! This string looks weird

org.openqa.selenium.TimeoutException: Timed out after 12 seconds waiting for visibility of

I've looked at code for places that check visibility of elements or use specific ExpectedCondition's that wait for element visible. There is code that waits for the proxied element: https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java#L31 Here function is performed: https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java#L149

So it shouldn't throw any exception. The only place where exception is thrown: https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java#L169

NoSuchElementException is more expected than TimeOutException.

Could you provide detailed code samples that throw exception like you mentioned and server outputs? Please give us links to gists.

TikhomirovSergey commented 9 years ago

@justintilson Also please add to this ticket detailed exception stack trace. It should be very useful for the problem investigation.

justintilson commented 9 years ago

Code sample here: https://gist.github.com/justintilson/04c8d009f6ce1bd87292 Server logs here: https://gist.github.com/justintilson/abbc4e3a82c6de6d4b21

org.openqa.selenium.TimeoutException: Timed out after 12 seconds waiting for visibility of [[AndroidDriver: Android on LINUX (07c0ee29-48b1-4a43-995b-f6ce6a8eed2f)] -> -android uiautomator: new UiSelector().resourceId("com.wholefoods.wholefoodsmarket:id/recipesSearchResultsGrid")]
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: 'CEN106471', ip: '192.168.1.4', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.4', java.version: '1.8.0_40'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.wholefoods.wholefoodsmarket, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=192.168.57.101:5555, platform=LINUX, appActivity=com.wholefoods.wholefoodsmarket.application.activities.WFMSplashActivity, desired={appPackage=com.wholefoods.wholefoodsmarket, appActivity=com.wholefoods.wholefoodsmarket.application.activities.WFMSplashActivity, platformVersion=4.4, automationName=Appium, name=Android - Version 4.4 - Phone, platformName=Android, deviceName=Android Emulator}, platformVersion=4.4.4, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, name=Android - Version 4.4 - Phone, browserName=Android, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: 07c0ee29-48b1-4a43-995b-f6ce6a8eed2f
    at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:229)
    at com.wfm.qa.mobile.pages.common.BasePage.waitUntilVisible(BasePage.java:164)
    at com.wfm.qa.mobile.pages.android.phone.recipes.SearchPhonePage.waitForResultsToLoad(SearchPhonePage.java:114)
    at com.wfm.qa.mobile.tests.android.phone.recipes.SearchAndVerifyResultsTest.testSearchByRecipeNameAndByRandomIngredients(SearchAndVerifyResultsTest.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:696)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:882)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1189)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
    at org.testng.SuiteRunner.run(SuiteRunner.java:254)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
Caused by: org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: Locator map: 
- native content: "By.AndroidUIAutomator: new UiSelector().resourceId("com.wholefoods.wholefoodsmarket:id/recipesSearchResultsGrid")" 
TikhomirovSergey commented 9 years ago

@justintilson I've commented your client code. https://gist.github.com/justintilson/04c8d009f6ce1bd87292 Please answer that question :)