How to use same test case for both Landscape and Portrait orientation

346 views
Skip to first unread message

Alis Way

unread,
Aug 27, 2014, 1:22:20 PM8/27/14
to appium-...@googlegroups.com
I have bunch of test cases automated using Appium for Portrait orientation. Those test cases use swipe using (x,y). If I want to use the same test cases for Landscape, how to I change my swipe method so I can use same test cases? 

Because when I change orientation all the x, y changes. I am hoping to set some Global property in my framework TEST_MODE= Landscape/ Portrait. Before starting the test I read the value from this property and if test is suppose to run on Landscape then all the test cases should automatically pick co-ordinates for landscape. Someone can please guide me what is the best way to implement this.

Also, is there a concept of relative swiping? so I can eliminate the (x,y) completely from my test cases and swipe on actual element?

Thanks,

bootstrap online

unread,
Aug 27, 2014, 1:28:13 PM8/27/14
to Alis Way, appium-...@googlegroups.com
On Wed, Aug 27, 2014 at 1:22 PM, Alis Way <naugh...@gmail.com> wrote:
> Also, is there a concept of relative swiping?

yes

Alis Way

unread,
Aug 27, 2014, 1:44:37 PM8/27/14
to appium-...@googlegroups.com
How do I implement that? Can you please give few hints.

bootstrap online

unread,
Aug 28, 2014, 1:42:57 PM8/28/14
to Alis Way, appium-...@googlegroups.com
I recommend reading the unit tests on github to see how to use swipe.
> --
> http://appium.io
> ---
> You received this message because you are subscribed to the Google Groups
> "Appium-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to appium-discus...@googlegroups.com.
> Visit this group at http://groups.google.com/group/appium-discuss.
> For more options, visit https://groups.google.com/d/optout.

Henry Hatcher

unread,
Aug 28, 2014, 4:31:19 PM8/28/14
to appium-...@googlegroups.com, naugh...@gmail.com
Bootstraponline seems to be intentionally unhelpful, so I'll spend some time on this, as the documentation is pretty spotty in this regard.  All of my examples are using java/junit, because that's what I use, but I'd expect it maps reasonably well to whatever your language of choice is.

First, the AppiumDriver has a getOrientation() method that will return a ScreenOrientation object.  ScreenOrientation has a value() method that returns either "portrait" or "landscape".  So you can pretty easily tell what your device's current orientation is by calling driver.getOrientation().value().

For element-relative swiping, you can locate whatever element you're trying to interact with, and then call element.getLocation().getX() and element.getLocation().getY() to get the upper-left coordinates of the element.   element.getSize().getWidth() and element.getSize().getHeight() will allow you to find the width and height of the element, and from there it's pretty easy to figure out the x and y for your relative swipes.  You will probably want to do a little bit of "safety padding" on those values just to make sure that you're not clicking on the absolute right or left edge of the element you're trying to interact with.

You should also be able to call driver.rotate("LANDSCAPE") or driver.rotate("PORTRAIT") to switch orientations (although I haven't actually used that functionality in any of my tests to date, so I have no idea if it actually works).

Finally, I'd recommend doing some looking into the PageObject design pattern for automated tests - it will make it much easier for you to write a resilient test suite for your app.  Instead of writing ten tests which specifically interact with (for example) a contacts screen, you write a single "ContactsScreen" object that describes the content screen and the parts of it that you can interact with, and then your tests can simply reference the ContactsScreen.  That way, if the Contacts screen changes, you only have to modify your ContactsScreen object, and maybe one or two tests, rather than having to fix all ten of your tests.

Good luck!

bootstrap online

unread,
Aug 28, 2014, 4:57:56 PM8/28/14
to Henry Hatcher, appium-...@googlegroups.com, Sun Mio
Pull requests are welcome to improve the docs. Unfortunately the best
way to learn about the advanced gestures is by reading the existing
tests on github.

Jonah Stiennon

unread,
Aug 28, 2014, 5:09:38 PM8/28/14
to appium-...@googlegroups.com, henry....@gmail.com, naugh...@gmail.com
Thanks @Henry

If you want, you could repost your explanation to our new discourse forum (which will be replacing the google-groups forum).
We can then mark your explanation as a useful guide and others will be able to find it easier :)

Henry Hatcher

unread,
Aug 28, 2014, 5:34:05 PM8/28/14
to appium-...@googlegroups.com, henry....@gmail.com, naugh...@gmail.com
I'm ashamed to admit that I'm not particularly interested in spending time documenting my own code, much less someone else's.  

I wasn't able to easily find the unit tests you mentioned, and I'm fairly experienced with Appium and the Appium documentation at this point.  I wasn't even able to find the swipe method's documentation in the Appium online javadoc.  

I really don't mean to be a jerk, but these sorts of responses are a real pet peeve of mine, and one of the reasons why I feel open source software has a reputation for shoddy support.  If you aren't interested in spending the time to provide usable feedback, why bother spending the time to respond at all?  For every person who hasn't looked at the documentation, there's another who has looked and hasn't found what they're looking for.  It takes more work to give people the benefit of the doubt, I'll freely admit, but that sort of effort is what builds strong communities.

Aaaand I've just shamed myself into updating documentation.  *sigh*



On Thursday, August 28, 2014 1:57:56 PM UTC-7, bootstraponline wrote:
Reply all
Reply to author
Forward
0 new messages