Search code examples
windowsshellautomationadbeggplant

How do I execute shell commands through eggPlant on Windows?


I am working on test automation for an Android app. I am currently using eggPlant for Android. Summary of my present situation:

  • I am successfully running tests on one Android device, that runs eggOn and is connected to eggPlant Functional
  • eggPlant Functional is being run on a Windows 7 Pro (SP1, 64-bit) machine.
  • I have about 50 manual functional tests that presently need automation; many of which will require some adb shell scripting alongside eggPlant automation.

Documentation on eggPlant websites (1 and 2) talks about the ability in eggPlant to run commands on the local shell. The examples (at the time of writing) are for Mac. I tried various modifications to these examples to make them run on Windows, such as:

e.g. 1

put shell("dir")

e.g. 2

set the shellCommand to "ShellExecute"
shell "example.bat" //where example.bat contains "dir"

e.g. 3

shell "C:\Windows\system32\cmd.exe /c dir" 

My ultimate objective is to run adb commands off the Windows shell. But the problems I am facing are:

  • Silent failure with no "cause" whatsoever
  • No way to observe the output of the commands

How do I proceed?


Solution

  • I was able to get this working in conjunction with TestPlant Support.

    • Windows + eggPlant does not have the ability to read console output. You need to dump the output to a file and then read it back.
    • First make a handler (or in plain words, function) as follows.
    • Modify the path sdkPath according to your Windows system.

    In this example I want to run adb shell "df | grep data | awk '{print $4}'" which will basically print out the free space in the /data folder of my Android Device.

    Since my code has quotes, I have to enclose the code within <<>> .

    to adb
        set command to <<shell "df | grep data  | awk '{print $4}'">>
        put "D:\adt-bundle\sdk\platform-tools" into sdkPath 
        set cmd to " /c " && sdkPath & "\adb.exe" && command && " > C:\adbOutput.txt"
        put cmd
        shell "C:\Windows\system32\cmd.exe", cmd
    end adb
    

    The value of the variable cmd expands to /c D:\adt-bundle\sdk\platform-tools\adb.exe shell "df | grep data | awk '{print $4}'" > C:\adbOutput.txt.

    Ultimately what gets executed is equivalent to

    cmd /c D:\adt-bundle\sdk\platform-tools\adb.exe shell "df | grep data  | awk '{print $4}'"  > C:\adbOutput.txt
    

    If I want to make the adb handler accept parameters, I'd add a Params cmd line to the adb handler, obviously.