How to achieve clean state before Google + login scenario?


I’d like to automate login with Google + scenario on Android.

I develop the tests on my business phone where I use a few Google accounts, so when I click “Login with G+” button in mobile app I see a list of accounts to pick from. I can remove those accounts if needed, but then after test scenario account will be there in again.

If I’ll run the tests on some simulator or clean device the screen will be different - login and password at first time.

So the question is: can I automatically remove all G+ accounts from Android device settings before/after test using Appium?
Or I should take some other approach? Any advices are welcome!


You can clear the app data by using below adb command through java code:

adb shell pm clear packageName

where packageName is G+ App package.

Thanks for reply! Unfortunately the Google accounts are something general to the device (Settings/Accounts), it’s not stored only in the cash of single app. Is there any command that removes all accounts from settings?

EDIT: I’ve found following for rooted devices:
adb shell rm -r /data/system/accounts.db

Not tested it yet.

I don’t have the exact answer but you can try this work around

List<WebElement> acc_picker= driver.findElements(By.xpath("//android.widget.ListView[contains(@resource-id,'list')]/android.widget.LinearLayout")).subList(0, 2);
for(WebElement cc:acc_picker)
            String email=cc.findElement(By.xpath("//android.widget.LinearLayout")).findElement(By.xpath("//android.widget.TextView[@index ='1']")).getText();

Get all the account name and choose yours. Hope it helps!