Monday, June 10, 2013

[android help] Questions about calabash-android support in Android Studio: Ruby, Editing features and steps, Launching tests


Questions about calabash-android support in Android Studio: Ruby, Editing features and steps, Launching tests



I'm working with Android Studio on Windows 7, 64 bit. I'm a noobie on Android Studio (or any Intelij IDE).


I downloaded and installed Ruby 1.9.3, The Ruby DevKit and calabash-android and I can successfully run Cucumber tests on my Android app using the command line (calabash-android run )


I also managed to install the Cucumber plugin for Android Studio, so that my feature files can benefit from autocomplete and such.


I have the following questions:



  • Can I install a Ruby plugin (RubyMine?) so that I can write step definitions for my tests? If so, I've heard that people can debug Cucumber tests: Can this be accomplished as well in Android Studio for Android apps?




  • Can I launch a calabash test for an Android app from Android Studio? If so, how would I go about it?




  • Can I integrate (automated) tests using calabash in Gradle builds of an Android app? If so, how would I go about it?



Thank you!


Update:


I attached a custom gradle Plugin (see groove code below that I wrote to have a basic support for running calabash-android tests.


These manual steps are still necessary:
- Install Ruby 1.9.x and its Devkit, install the calabash-android gem, etc.
- Build the appropriate (flavor of an) APK using android gradle plugin (manual or automated)


In the app's build.gradle, adding apply plugin: 'calabash' now works and it allows the build to run a feature file as a calabash test.
It examines the available product-flavors (build-flavors) and adds the appropriate calabash related tasks (e.g. calabashDebug or calabashFlavor1Release, etc).


I still haven't quite figured out how to make these tasks dependent on the build of the actual APK, so that I can be sure the appropriate APK is built and available before the calabash-task runs a test on it. If someone can help me out, that would be great! :)


Below is the groovy file that implements my 'calabash' plugin (Windows only for now):



package com.mediaarc.gradle.plugins

import org.gradle.api.*
import org.gradle.api.plugins.*
import org.gradle.api.tasks.*

class CalabashPlugin implements Plugin {
void apply(Project project) {
project.extensions.create("calabash", CalabashPluginExtension)

if (!project.android) {
throw new IllegalStateException("Android plugin is not configured.")
}

project.android.applicationVariants.each { variant ->
//println "Adding task for variant ${variant.name}"

final def buildName = variant.name
final def buildVar = variant.baseName
final def packageApp = variant.packageApplication;

//
project.task("doPrepare${buildName}") << {
project.calabash.init(project, buildVar)

def apkFile = packageApp.outputFile
project.calabash.writeCommandFile(apkFile)
}

project.task("doClean${buildName}") << {
project.calabash.init(project, buildVar)

project.calabash.clean()
}

project.task("calabash${buildName}", type: Exec, dependsOn: project["doPrepare${buildName}"]) {
project.calabash.init(project, buildVar)

project.calabash.execute(project[name])
}

project.task("cleanCalabash${buildName}", dependsOn: project["doClean${buildName}"]) {
project.calabash.init(project, buildVar)
}
}

}
}

class CalabashPluginExtension {
def root = 'src/calabash'
def resultFile = "calabash-results.html"

//protected def hash = new Object()
protected File outputFile
protected File workingDir
protected File tmpFile

protected init(Project project, def buildVariant) {
if (!buildVariant) {
buildVariant = "debug"
}

File rootFile = project.file(root)
outputFile = new File(project.file("build/reports/calabash/${buildVariant}"), resultFile)
workingDir = rootFile
}

protected writeCommandFile(def apkFile) {
if (!workingDir.exists()) {
throw new IllegalStateException("The root directory for the calabash-tests could not be found: '${workingDir}'")
}

if (!(new File(workingDir, "features").exists())) {
throw new IllegalStateException("The required 'features' directory could not be found in '${workingDir}'")
}

outputFile.parentFile.mkdirs()

def calabashCmd = "cd ${workingDir.canonicalPath}\r\ncalabash-android run \"${apkFile.canonicalPath}\" --format html --out \"${outputFile.canonicalPath}\"\r\n"
getCommandFile().write calabashCmd
}

protected execute(Exec exec) {
exec.commandLine 'cmd', '/c', getCommandFile().canonicalPath
}

protected clean() {
outputFile.delete()
}

private File getCommandFile() {
if (!tmpFile) {
tmpFile = File.createTempFile("run-calabash", ".bat")
tmpFile.deleteOnExit()
}
return tmpFile
}
}


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...