-
Notifications
You must be signed in to change notification settings - Fork 23
My First Android Test
Writing tests in Optimus is no different than the tests you write everyday, except that it does most of the heavy lifting, helping you to focus entirely on the test, thus the philosophy of Optimus
Focus On Functionality
If there is anything at your disposal to tame the mighty Optimus, then it's your TestFeed. Let us build a simple test feed now.
Under resources
folder create a new json file called OptimusAndroid.json
. You can copy below content in your newly created test feed.
{
"executionDetails": {
"appium_js_path": "/usr/local/bin/appium",
"appium_node_path": "/usr/local/bin/node"
},
"testFeed":[
{
"belongsTo":"optimus",
"runsOn": "any",
"appDir": "app",
"nativeApp":true,
"optimusDesiredCapabilities": {
"appiumServerCapabilities": {
"app": "hellooptimus.apk",
"platformName": "Android"
},
"androidOnlyCapabilities": {
"appActivity": "com.testvagrant.hellooptimus.MainActivity",
"appPackage": "com.testvagrant.hellooptimus",
"avdLaunchTimeout": 300000,
"useKeystore": false
}
},
"deviceState": {
"captureVideo": true
}
}
]
}
Optimus would generally read this test feed as
Create a driver which belongsTo optimus for an app hellooptimus running on emulator on Android platform.
You can create number of variations to this test feed matching your functionality.
Under package features
create a new feature HelloOptimus.feature
.
Feature: Say Hello to Optimus
@helloOptimus
Scenario: Hello Optimus
Given I have optimus hello application
When I open it on either emulator, simulator or device on any platform
Then I should be able to say a hello to optimus
Go ahead and create a step definition file for above feature under steps
package.
public class HelloOptimusSteps extends BaseSteps{
@Given("^I have optimus hello application$")
public void iHaveOptimusHelloApplication() throws Throwable {
getDriverInstanceFor("optimus");
}
@When("^I open it on either emulator, simulator or device on any platform$")
public void iOpenItOnEitherEmulatorSimulatorOrDeviceOnAnyPlatform() throws Throwable {
}
@Then("^I should be able to say a hello to optimus$")
public void iShouldBeAbleToSayAHelloToOptimus() throws Throwable {
}
}
To access the webDriver for your application, all you would need is getDriverInstanceFor(<belongsTo>)
. This is a powerful approach when you do interApp testing.
Now you are all set to run your first test. Lets get a bit geeky here. Bootup your favourite emulator. Open your terminal and navigate to your project folder and try below command.
./gradlew runFragmentation -DtestFeed="helloOptimus" -Dtags=@helloOptimus
or
./gradlew runDistribution -DtestFeed="helloOptimus" -Dtags=@helloOptimus
In case you have a gradle distribution on local you can run below commands
gradle runFragmentation -DtestFeed="helloOptimus" -Dtags=@helloOptimus
or
gradle runDistribution -DtestFeed="helloOptimus" -Dtags=@helloOptimus
After all the initial setup process you will be able to see optimushello
app appear on your emulator screen
Kudos for your first successful test with Optimus. Now that you have reached here, let us understand the basic features and building blocks of Optimus, the TestFeed