关于Android Studio中calabash-android支持的问题:Ruby,编辑功能和步骤,启动测试

时间:2022-09-05 19:57:06

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

我在64位Windows 7上使用Android Studio。我是Android Studio(或任何Intelij IDE)的noobie。

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 )

我下载并安装了Ruby 1.9.3,Ruby DevKit和calabash-android,我可以使用命令行在我的Android应用程序上成功运行Cucumber测试(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.

我还设法安装了Android Studio的Cucumber插件,这样我的功能文件就可以从自动完成等方面受益。

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?

    我可以安装Ruby插件(RubyMine?),以便我可以为我的测试编写步骤定义吗?如果是这样,我听说人们可以调试Cucumber测试:这可以在Android Studio for Android应用程序中实现吗?

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

    我可以从Android Studio为Android应用启动葫芦测试吗?如果是这样,我该怎么做呢?

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

    我可以在Gradle版本的Android应用程序中使用calabash集成(自动)测试吗?如果是这样,我该怎么做呢?

Thank you!

谢谢!

Update:

更新:

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

我附加了一个自定义gradle插件 (请参阅我编写的下面的凹槽代码,以获得运行calabash-android测试的基本支持。

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)

这些手动步骤仍然是必要的: - 安装Ruby 1.9.x及其Devkit,安装calabash-android gem等。 - 使用android gradle插件(手动或自动)构建适当的(风味的)APK

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).

在app的build.gradle中,添加apply plugin:'calabash'现在可以工作,它允许构建运行一个功能文件作为calabash测试。它检查可用的产品口味(构建口味)并添加适当的葫芦相关任务(例如calabashDebug或calabashFlavor1Release等)。

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

下面是实现我的'calabash'插件的groovy文件(仅适用于Windows):

    package com.mediaarc.gradle.plugins

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

    class CalabashPlugin implements Plugin<Project> {
        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 ->
                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["assemble${buildName}"], project["doPrepare${buildName}"] ]) {
                    println project["assemble${buildName}"]
                    project.calabash.init(project, buildVar)
                    configureTask(project[name], buildName)

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

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

        private def configureTask(def task, def buildVariant) {
            task.group = JavaBasePlugin.VERIFICATION_GROUP
            task.description = "Runs calabash tests for Build '${buildVariant}'"
        }

        private def configureClean(def task, def buildVariant) {
            task.group = BasePlugin.BUILD_GROUP
            task.description = "Deletes the calabash tests results for Build '${buildVariant}'"
        }
    }

    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\necho calabash-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
        }
    }

1 个解决方案

#1


3  

Very good question. Xamarin had a webinar on using Calabash tests in their Test Cloud product. Towards the end of the talk there is quite a bit of hands-on with setting up the testing ecosystem and running Calabash tests for Android. There's lots in there that don't apply to your environment, but some very good tips and insights from Karl Krukow - one of the main contributors to calabash-android.

非常好的问题。 Xamarin在他们的Test Cloud产品中使用了Calabash测试的网络研讨会。在演讲即将结束时,有很多动手设置测试生态系统并运行Android的Calabash测试。那里有许多不适用于你的环境,但有一些非常好的技巧和见解来自Karl Krukow - calabash-android的主要贡献者之一。

#1


3  

Very good question. Xamarin had a webinar on using Calabash tests in their Test Cloud product. Towards the end of the talk there is quite a bit of hands-on with setting up the testing ecosystem and running Calabash tests for Android. There's lots in there that don't apply to your environment, but some very good tips and insights from Karl Krukow - one of the main contributors to calabash-android.

非常好的问题。 Xamarin在他们的Test Cloud产品中使用了Calabash测试的网络研讨会。在演讲即将结束时,有很多动手设置测试生态系统并运行Android的Calabash测试。那里有许多不适用于你的环境,但有一些非常好的技巧和见解来自Karl Krukow - calabash-android的主要贡献者之一。