Freigeben über


Writing SmartDevice automated tests using DEM Automation Interface with Corecon Managed APIs

Few days back I presented at Techmela on automating your test cases for Devices using Device Emulator Manager automation interfaces, in association with Corecon Managed APIs (Exposed with Visual Studio 2008 Codename "Orcas") around which this blog is going to be focussed.

Using Automation Interfaces:-  

DEM v3 Beta1 (dvcemumanager.exe) has embedded TLB (as well as IDL as part of installation) for DEM Automation interfaces, so if you will do a TLBImp on this exe and view the Interop dll in Object Browser of Visual Studio, you will notice a set of interfaces, namely IDeviceEmulatorManager, IDeviceEmulatorManagerVMID, IEnumManagerSDKs and IEnumVMIDs, being exposed. (Please note with Beta2 based on feedback we will shipping Interop dll directly instead of idl file and embedding TLB in DvcEmuManager).

IDeviceEmulatorManager interface represents an instance of DEM and you can CoCreate this object (CLSID_DeviceEmulatorManager) as will be discussed in following code. On this object, you can invoke EnumerateSDKs method which will give you an instance of IEnumManagerSDKs which corresponds to Datastore, Others, My Device Emulator and All Device Emulator node in DEM view and logically represents a collection of SDKs. So, for example, if you have Visual Studio installed, first node will be corresponding to Datastore. To move to next node you can invoke MoveNext method on IDEM object. Other methods are ShowManagerUI, Reset, RegisterRefreshEvent, get_Name etc.

Once you have got an instance of IEnumManagerSDKs, you can use EnumVMIDs method to get an instance of IEnumVMIDs. An instance of IEnumVMIDs represents a collection of Device Emulator instances aka SDK in DEM view (Like Windows Mobile 5 SDKs etc). IEnumManagerSDKs interface also exposes methods like get_Name, MoveNext and Reset which can be used get name and iterate.

Using this instance of IEnumVMIDs, you can actually invoke method GetVMID and get an instance of IDeviceEmulatorManagerVMID. The instance of IDeviceEmulatorManagerVMID represents an emulator instance on which you can perform operations as exposed from DEM UI like Cradling, Connect, Shutdown, Reset, SetConfiguration, GetConfiguration, Shutdown etc.

 Following is C# code i quickly wrote to illustrate how to connect to an emulator in "Windows Mobile 6 Professional SDK" using DEM APIs

        public void Connect(string szName)
{
IDeviceEmulatorManager manager = new DeviceEmulatorManager();

            do
{
IEnumManagerSDKs sdk = manager.EnumerateSDKs();
System.Console.WriteLine("DEM " + sdk.get_Name());

                if (sdk.get_Name().Contains("Windows Mobile 6 Professional SDK"))
{
IEnumVMIDs vmids = sdk.EnumerateVMIDs();
do
{
IDeviceEmulatorManagerVMID vmid = vmids.GetVMID();
if (vmid.get_Name().Equals(szName))
{
vmid.Connect();
break;
}
try
{
vmids.MoveNext();
}
catch (Exception ex)
{
break;
}
} while (true);
}

                try
{
sdk.MoveNext();
}
catch (Exception ex)
{
break;
}
} while (true);

        }

Quick view of Corecon Managed API:-

Since this blog is focussed on DEM APIs so we will not discuss in detail about Corecon APIs. As part of Orcas, Corecon exposed managed APIs which provides Raw transport services, ability to Send a file from desktop to device (or emulator), Receive a file, Execute an app and other rich set of functionality without you needed to worry about transport details. So suppose you wanted to Send a file to an emulator in Windows Mobile 6 Professional SDK, you can use code similar to following piece of code which i wrote very quickly.

        public void SendFile(int localeId, string szEmuName)
{
DatastoreManager dsmgrObj = new DatastoreManager(1033);

            //Get Collection of platforms entries present in Data store
IEnumerable<Platform> platformcollection = dsmgrObj.GetPlatforms();

            //Iterate through Collection of platforms
foreach (Platform objplatform in platformcollection)
{
System.Console.WriteLine(objplatform.Name);
if (objplatform.Name.Contains("Windows Mobile 6 Professional SDK"))
{
IEnumerable<Device> pdeviceCollection = objplatform.GetDevices();
foreach (Device objdevice in pdeviceCollection)
{
System.Console.WriteLine("\t" + objdevice.Name);
//Check if the device is an emulator
if (objdevice.IsEmulator() == true &&
objdevice.Name.Equals(szEmuName))
{

                             FileDeployer fileDeploy;
fileDeploy = m_device.GetFileDeployer();
fileDeploy.SendFile(szDesktopPath, szDevicePath);
}
}
}
}
}

OK-OK enough of API details but how is it useful to me in writing automation:-

Ok, we'll walk through a scenario where your application is battery aware and you want to test it.

1. Start you test automation framework.

2. It will use Corecon APIs to copy you app executable on a Device emulator and execute it.

3. Now you can use the DEM APIs SetConfiguration method and modify the battery charge to 60% from 100% or A/c power mode (Look into XML schema in previous post).

4. Your app should ideally be responding to this change in battery level (It can register with State and Notification broker in Windows Mobile to get power state change notifications). You can either dump this change logs in a log file or use Corecon APIs device agent mechanism to communicate it back on desktop side.

5. Similarly now you use to reduce the charge further to Low battery and critical battery levels and accumulate the info in the logs as appropriate.

6. Once your test finishes, you can match your logs with golden file to see your app continues to work great during development phases.

You can see from this battery example, how easy it becomes to automate these scenarios where this is very difficult to even manually repro in association with actual device. Here i chose C# but DEM APIs provides you flexibility to use them from managed code, VB Script or native code. In addition, even in case of stand-alone installation of DE all Corecon-lite nodes (See previous post) are visible perfectly from DEM APIs, so you can use DEM APIs in stand-alone mode or with Visual Studio installed. However, please note that in stand-alone installation Corecon Managed APIs won't be available so you can Cradle the emulator and rely on rich set of APIs from RAPI.

 We hope you will like this feature. Please use https://connect.microsoft.com/ to give us your feedback or report us any issues you find. Your feedback is very important to us to make this produce better than itself.

-Namaste,

Mohit

This posting is provided "AS IS" with no warranties, and confers no rights.

Comments

  • Anonymous
    August 02, 2007
    Visual Studio 2008 Beta2 , as you know ships with Device Emulator V3. I have already blogged about the

  • Anonymous
    August 02, 2007
    Visual Studio 2008 Beta2 , as you know ships with Device Emulator V3. I have already blogged about the

  • Anonymous
    August 02, 2007
    In order to successfully build an application for a mobile device you need to go through the same process

  • Anonymous
    August 18, 2007
    Mohit Gogia talked about the programmatic interface to the new Device Emulator v3. The enhancements are

  • Anonymous
    August 18, 2007
    Mohit Gogia talked about the programmatic interface to the new Device Emulator v3. The enhancements are

  • Anonymous
    August 18, 2007
    Mohit Gogia talked about the programmatic interface to the new Device Emulator v3. The enhancements are