当前位置 : 主页 > 网络安全 > 测试自动化 >

自动化 – 使用控制台应用程序连接到Windows Phone 8

来源:互联网 收集:自由互联 发布时间:2021-06-19
我是 Windows手机开发的新手.我想开发一个应用程序,将我的Windows 8手机连接到笔记本电脑时将启动.我正在按照这个教程( http://justinangel.net/WindowsPhone7EmulatorAutomation)并能够连接到我的Wind
我是 Windows手机开发的新手.我想开发一个应用程序,将我的Windows 8手机连接到笔记本电脑时将启动.我正在按照这个教程( http://justinangel.net/WindowsPhone7EmulatorAutomation)并能够连接到我的Windows 7手机/模拟器,但我无法连接到我的Windows 8手机或模拟器.有没有其他方法连接到Windows 8手机?

如果有任何可能的解决方案,请告诉我,

谢谢

我还没有机会更新这篇博文. Delvis Gomez(我的一位同事)已经更新了最终的代码示例,并且可以自由地分发它.我将来会更新WP8的博客文章,但同时这里有一个很好的文档代码片段,介绍如何自动化WP8模拟器.

此外,请确保添加对所需的新DLL的引用,如Microsoft.SmartDevice.MultiTargeting.Connectivity.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Reflection;

// Libraries needed to connect to the Windows Phone X Emulator
using Microsoft.SmartDevice.Connectivity;
using Microsoft.SmartDevice.Connectivity.Interface;
using Microsoft.SmartDevice.MultiTargeting.Connectivity;
using System.Globalization;
using System.Collections.ObjectModel;


namespace AutomatedUnitTestDriver
{
    class Program
    {
        static void Main(string[] args)
        {
            MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);

            // Get a connectable device for a specific Device ID (from the CoreCon datastore)
            string deviceId = "5E7661DF-D928-40ff-B747-A4B1957194F9";
            ConnectableDevice connectableDevice = connectivity.GetConnectableDevice(deviceId);
            Console.WriteLine("Found Connectable Device \'" + connectableDevice.Name + "\' for Device id {" + connectableDevice.Id + "}.");

            // Connect to the Device
            Console.WriteLine("Connecting to Device...");
            IDevice iDevice = connectableDevice.Connect();
            Console.WriteLine("Done!");

            // Check if the application is already install, if it is remove it (From WMAppManifect.xml)
            Guid appID = new Guid("{b6635769-b7ac-41a5-915d-5a7b0ae34481}"); 

            if (iDevice.IsApplicationInstalled(appID))
            {
                Console.WriteLine("Uninstalling application...");
                iDevice.GetApplication(appID).Uninstall();
                Console.WriteLine("Done!");
            }

            Guid productId = appID;
            Guid instanceId = appID;
            string applicationGenre = "NormalApp";
            string iconPath = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\ApplicationIcon.png";
            string xapPackage = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\AutomatedUnitTests.xap";

            // Install the application 
            Console.WriteLine("Installing the application...");
            IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage);
            Console.WriteLine("Done!");

            // Launch the application
            Console.WriteLine("Starting the application...");
            remoteApplication.Launch();

            int startStopWaitTime = 1000;   // msec
            int executionWaitTime = 180000; // msec

            // Note that IRemoteApplication has a 'IsRunning' method but it is not implemented.
            // So, for the moment we sleep few msec.
            Thread.Sleep(startStopWaitTime);
            Console.WriteLine("Done!");

            // Allow application to complete 
            Console.WriteLine("Application is running! Waiting few seconds...");
            Thread.Sleep(executionWaitTime);

            try
            {
                IRemoteIsolatedStorageFile remoteIsolatedStorageFile = remoteApplication.GetIsolatedStore();
                string sourceDeviceFilePath = (object)Path.DirectorySeparatorChar + "TestResults.trx";
                string targetDesktopFilePath = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\" + "TestResults.trx";
                remoteIsolatedStorageFile.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath,true);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception \'" + exception.Message + "\' reading file from device.");
            }

            // Terminate application
            Console.WriteLine("Terminating the application...");
            remoteApplication.TerminateRunningInstances();

            Thread.Sleep(startStopWaitTime);
            Console.WriteLine("\nDone!");

            // Disconnect from the emulator
            Console.WriteLine("Disconnecting Device...");
            iDevice.Disconnect();
            Console.WriteLine("\nDone!");
        }
    }
}
网友评论