Running same test across different devices has issues with smaller devices


I am running a test across 11 different iOS devices, but for a smaller device (iPhone SE 2022) I need to add a scroll to my test for it to pass where as with the other 10 devices do not require a scroll.

Is there a way I can run the same test across all devices but for a specific device add a scroll only? Otherwise my tests have a scroll for most devices when its not required.

Any advice / guidance would be muchly appreciated

Thank :slight_smile:

It sounds like you aren’t using page object model, but correct me if I’m wrong. I’m suggesting it because in a case like this you can code a search that performs a scroll if needed, but you only code it once in the POM. It’s my best suggestion for you:

1 Like

A few suggestions:

  1. As @wreed said, you can use POM, I recommend it as well.
  2. Not ideal, you can use branching to separate the test for the small device.
  3. pass the device’s name/dimensions using command line when executing the test and then just use if statements or any other conditions in your code in order to know if you need to perform a scroll or not.
  4. This is what I would probably do and this is what I do in my code as well. I have a scrolling method that just stop scrolling when it finds the desired element so, if you will call it with a big device, it won’t scroll, it will just immediately return the element(because it is visible already) and if you are using a small device, it won’t find it, then will perform a scroll and then will try to locate the desired element again. The desired element is used to indicate if the screen is on the desired display - you don’t have to use POM for this, you can just create a utils class if you want but of course it works great with POM as well.
1 Like

Thank you very much for the above suggestions. Screen objects are being used so will code a search that performs a scroll when needed and see how I get on :slight_smile: Thanks again!

1 Like

if you do not mind to have a bit slowness for check and such screens NOT much you may add check element visible before you going to tap on it. And scroll to it if not visible.

better in code get ONE time after open driver and use it everywhere in all tests:

        final Dimension dims = driver.manage().window().getSize();
        final boolean isSmallScreen = dims.height < 300; // correct 300 to size you need