How to handle A/B experiment on Android App automation

Hi All

We are running A/B experiment on Android app where for 50% of users we are showing type A listing and for rest 50% we are showing another listing, the challenge i am facing in automating this thing is the element ID’s. both the experiment are having element ID’s, say an element id is “Button” in experiment A and “Button_ext” in the second experiment. i do not want to use multiple if-else to handle this.

Can any one help me with a better approach.

Thanks in advance.

I haven’t tried this yet, but you could try an xpath ID matching strategy.

Here’s an example that should match any place in the view hierarchy containing Button onscreen. (Again I haven’t tried this yet)
find_element(:xpath, “//[matches(@id,'Button.’)]”)

Full resource here:

Instead of locating by id have you tried locating by CSS classes? Do these button share the same classes?

Use @findAll or @findBys depending on your needs.

Examples are here: Android_Page_Object_Example

PS never or min use of XPATH cause it is working times slower.

1 Like

You can try and use the common part of id as long as they surely identify only those buttons:

String query = "new UiSelector().resourceIdMatches(\".*" + id + "\")";
return fluentWait30.until(webDriver -> ((AndroidDriver) driver).findElementByAndroidUIAutomator(query));

We had the same problem in our company and here’s how we solved it:

  • we have completely disabled VTs for test builds
  • we have added UI to change VTs in automated tests
  • we explicitly activate VTs in our automated scenarios