Search code examples
c#androidtestingui-automationappium

Questions regarding Appium


Please bear with me as I am relatively new to Appium. I am writing C# tests in Appium for my Android app. I am stuck finding answers to questions below.

1) How to check if a particular element exists? Is there any boolean property or function returning true or false? The methods driver.GetElementById, driver.GetElementByName etc. throw exceptions if element doesn't exists.

2) Suppose I want to write a test for login. The user enters username and password and hits login button. The requests goes to server and it checks whether username-password pair exists in database. Meanwhile the loading indicator (progress dialog in Android) is shown on screen. How shall make a test suspend it's execution until response comes from server assuming I don't want to use something like Thread.Sleep function?

3) Can I check whether textfield validation is failed on screen? A control with black background and white text is shown below textfield upon validation failure if we set validation for that textfield through setError function. Is there any way to check that validation has failed?

Anticipating answers. Thanks.


Solution

  • For the first 2 questions (This is what I do in java, definitely can be implemented in c#) -

    1) Use the polling technique - In a loop check for the element return of the following

    @param - By by , int time
    driver.findElement(By by);
    

    This must not be null or empty. If within the threshhold time the element is not present then fail the test. In appium mode - isVisible() will be same as the above, as an element not visible will not be present.

    2) Check for the next activity to be awaited. Use the same polling technique to keep on comparing the current activity with the awaited activity, If the awaited activity does not start within the threshold time then fail the test.

    @param int time, String awaitedActivity
    

    1) Get the current activity. 2) Compare with the awaited activity. 3) If same then break the loop. 4) Else sleep for a second and then continue till the time is exhausted.