Serenity + Appium + Native app sample project ?

3,531 views
Skip to first unread message

80Vikram

unread,
Nov 20, 2015, 4:32:36 AM11/20/15
to Serenity BDD Users Group
Hi,

can somebody please share sample project showing native app automation with Serenity + Appium ?

Thanks in advance.

Regards,
Vikram

80Vikram

unread,
Nov 20, 2015, 6:01:16 AM11/20/15
to Serenity BDD Users Group
I tried migrating https://github.com/serenity-bdd/serenity-journey-demo on mobile but couldn't yet found below answers

1. Do I need to start / stop appium server externally or can be done through framework itself ?

2. how to achieve below steps in framework ?


File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "../../../apps/ContactManager");
        File app = new File(appDir, "ContactManager.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName","Android Emulator");
        capabilities.setCapability("platformVersion", "4.4");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("appPackage", "com.example.android.contactmanager");
        capabilities.setCapability("appActivity", ".ContactManager");
        driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);


Thanks in advance.

Regards,
Vikram

John Smart

unread,
Nov 20, 2015, 6:08:41 AM11/20/15
to 80Vikram, Serenity BDD Users Group
We'll be writing this up in detail in the coming months, but essentially you just set webdriver.driver to 'appium' and 'appium.*' properties to define the capabilities (appium.hub, appium.platformName, etc).

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +61 407 247 642
Optimizing your software development process
http://www.wakaleo.com  |  john....@wakaleo.com
___________________________________________________

We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Requirements Discovery, Behaviour Driven Development, Agile Development Practices, and Test Automation!
___________________________________________________

80Vikram

unread,
Nov 20, 2015, 7:22:46 AM11/20/15
to Serenity BDD Users Group, vikra...@gmail.com
Hi John,

I tried below steps

@Managed(driver = "appium")
    WebDriver driver;
in test case class

<webdriver.driver>appium</webdriver.driver> in pom.xml

appium.hub = http://127.0.0.1:4723/wd/hub
appium.platformName = android
appium.platformVersion = 5.0
appium.deviceName = device
appium.app = /Users/vikramvi/apk/sample-app.apk

in serenity.properties

To open app , I am trying to use steps' object to open app just like browser e.g. stepObject.open

Had started appium server externally , not sure if this can be done through framework itself

but still it's not working , please let me know what may be going wrong here ?


Thanks & Regards,
Vikram

80Vikram

unread,
Nov 24, 2015, 6:07:14 AM11/24/15
to Serenity BDD Users Group, vikra...@gmail.com
Hi John , all,

I did below to try out simple scenario of atleast launching app/browser on real android device but nothing happening


serenity.properties

appium.hub = http://127.0.0.1:4723/wd/hub

appium.platformName = android

appium.platformVersion = 5.0

appium.deviceName = 192.168.1.38:5555

appium.browserName = Chrome

appium.app = Chrome

driver = appium



Test_Android.java > Android_Steps.java > Android_Pages.java


Test_Android.java

@RunWith(SerenityRunner.class)

public class WL_Android {


@Managed(driver = "appium") 

WebDriver driver;

@Steps

Android_Steps wlSteps;

@Test

public void myFirstTC(){

wlSteps.open_app();

System.out.println("hello world");

}

}



Android_Steps.java


public class Android_Steps {


Android_Pages wlPage;

@Step

public void open_app(){

wlPage.open();

}

}



Android_Pages.java

public class Android_Page extends PageObject {

  //empty class

}



I'm not sure if wlPage.open(); is correct way to launch browser/app on real device ?

Thanks & Regards,
Vikram

80Vikram

unread,
Nov 24, 2015, 6:57:38 AM11/24/15
to Serenity BDD Users Group, vikra...@gmail.com
Hi John , all,


some good news , found the problem

after adding value of @DefaultURL as below

@DefaultUrl("https://www.etsy.com")

public class WL_Page extends PageObject {


}


I could launch browser on real device and goto that website 




Next question what should be value of @DefaultUrl in case of native app testing ??


Once I solve this problem , will share 2 sample projects on github


Thanks again.


Regards,

Vikram



80Vikram

unread,
Nov 25, 2015, 2:36:45 AM11/25/15
to Serenity BDD Users Group, vikra...@gmail.com
Hi John,

I tried launching android_qa.apk on real device but couldn't achieve it


appium.hub = http://127.0.0.1:4723/wd/hub

appium.platformName = android

appium.platformVersion = 5.0

appium.deviceName = 192.168.1.39:5555

appium.app = /Users/vikram-anna/Documents/workspace/Android/apk/android-qa.apk

driver = appium


Is there any unique method to launch apk file on android or void net.serenitybdd.core.pages.PageObject.open() should work ? 


Thanks in advance.


Regards,

Vikram



80Vikram

unread,
Nov 29, 2015, 11:38:36 PM11/29/15
to Serenity BDD Users Group, vikra...@gmail.com
Good morning all , I'm still struck with launching native app on real device.

Has somebody tried this already  ? Does framework supports this or only supports browser on real device ?

I'm not able to launch native app similar to browser

Thanks again.

Regards,
Vikram

b...@testautomation.com.au

unread,
Nov 30, 2015, 8:37:17 PM11/30/15
to Serenity BDD Users Group, vikra...@gmail.com
Hi Vikram,

I'm in the process of writing this up.  I did the initial integration with Appium months ago and needed to drop it temporarily - but I've picked it up again in the last few days.  Appium definitely supports native apps on both iOS and Android.  The biggest trick is to make sure that you get the right APK / APP for your scenario.  I'm a bit rusty, but I recall having issues with ensuring the builds for running on physical devices vs in the simulator were different.  The Appium documentation contains the steps to follow, and all serenity does is wrap these values as John has mentioned above using the appium.* prefix.

There's a few limitations with the page model and @FindBy annotations as a result of fixed rate instructions through iOS UIAutomator (1 call per second).  When running in the simulator you will find your test runs EXTREMELY slow if you use the annotations.  I've opted instead for inline findBy() calls - it's still slow, but substantially better than the alternative.

For finding elements, the native Appium app (have only tried it on OSX) will allow you to mess around with locator strategies and ensure you're getting the right element.  This works for both iOS and Android.

I've attached an example properties file that covered a few of these scenarios below.  Hope this helps until I can put something more detailed together.


#iOS SIMULATOR (build in XCODE with a debug simulator profile)
#-----------------------
#webdriver.driver=appium
#appium.platformName=ios
#appium.deviceName=iPhone 6
#appium.autoAcceptAlerts=true
#appium.noReset=false
#appium.app=/Users/Ben/Library/Developer/Xcode/DerivedData/ingogo-glzwuicwzbsmamdwslopjgtigbag/Build/Products/Debug-iphonesimulator/sample.app
#appium.bundleId=net.schmurgon.sample
#appium.locationServicesEnabled=true
#appium.locationServicesAuthorized=true
#serenity.jquery.integration=false

# --------------------
# REAL iOS DEVICE: Build with DEBUG / TEST for physical device, and change the appium.app path to point to the .app file
# ---------------------
# Ben's iPhone 6
# appium.udid=<your UDID here>


#---------------------------------------------
# ANDROID #
#---------------------------------------------#
#webdriver.driver=appium
#appium.platformName=Android
#appium.platformVersion=4.4
#appium.appPackage=net.schmurgon.sample
#appium.appActivity=net.schmurgon.sample.screen.main.MainActivity
#
## Android Simulator
##appium.deviceName=Nexus_4_API_19_x86
#
## Samsung Galaxy S5
#appium.deviceName=<list adb devices, will be something like "d6e853c5">
#appium.sendKeyStrategy=setValue
#
#appium.noReset=true
#appium.newCommandTimeout=99999
#appium.app=/Users/Ben/Workspace/net.schmurgon.sample-0.1.119.alpha.apk
#serenity.jquery.integration=false

b...@testautomation.com.au

unread,
Nov 30, 2015, 8:47:28 PM11/30/15
to Serenity BDD Users Group, vikra...@gmail.com

A sample page object:  This makes use of the accessibilityId (which you'll need to set in XCode / Android Studio for each element you want to interact with) and demonstrates the inline find as an alternative to the poorly performing annotations.

public class InitialLaunchPage extends PageObject
{

//@FindBy(accessibilityId = "Login")
private WebElementFacade loginButton;

//@FindBy(accessibilityId = "Join")
private WebElementFacade joinButton;

public void login()
{
WebElementFacade loginButton = this.find( MobileBy.AccessibilityId( "Login" ) )
.withTimeoutOf( 10, TimeUnit.SECONDS );
loginButton.click();
}

public void join()
{
WebElementFacade joinButton = this.find( MobileBy.AccessibilityId( "Join" ) )
.withTimeoutOf( 10, TimeUnit.SECONDS );
joinButton.click();
}


}

And the test... (this might be a bit dated, it was right in the middle of the thucydides->serenity migration)

@ContextConfiguration({ "classpath:applicationContext.xml" })
@RunWith(SerenityRunner.class)
public class WhenMakingRegisteringNewUser
{
@ManagedPages
Pages pages;

@Managed
WebDriver webDriver;

@Rule
public SpringIntegration springIntegration = new SpringIntegration();

InitialLaunchPage launchPage;
JoinPage joinPage;

@BeforeClass
public static void setEnvironment()
{
System.setProperty( "environment", "automation" );
}

@After
public void tearDown() throws Exception
{
ThucydidesWebDriverSupport.getDriver().quit();
}

@Test
public void join_for_first_time()
{
launchPage.join();
joinPage.enterName( "Ben" );
joinPage.enterMobileNumber( "0500999999" );
joinPage.sendVerificationSms();
}
}

80Vikram .

unread,
Dec 2, 2015, 8:13:08 AM12/2/15
to b...@testautomation.com.au, Serenity BDD Users Group
Hi Ben,

Thanks a ton for your time and detailed clarifications.

I'll try this out and update back by week end.

Best Regards,
Vikram

Ray Oei

unread,
Dec 17, 2015, 4:42:53 AM12/17/15
to Serenity BDD Users Group, b...@testautomation.com.au
Hi Vikram (&Ben),

Any progress?
I am also stuck on the @DefaultURL. Appium (1.4.16.1) reports an "info: [debug] Responding to client that a method is not implemented" message and my test stops.
I can instantiate my own appiumobject but that is not the road I want to go.

Any suggestions?

Cheers,

Ray

80Vikram

unread,
Dec 17, 2015, 10:14:45 AM12/17/15
to Serenity BDD Users Group, b...@testautomation.com.au
Hi Ray,

Sorry I didn't find time on this project as I struck with some blocking issues.

But am trying to get this done at the earliest , will keep updated on this thread.

Regards,
Vikram

80Vikram

unread,
Nov 22, 2016, 6:32:15 AM11/22/16
to Serenity BDD Users Group, b...@testautomation.com.au
Reply all
Reply to author
Forward
0 new messages