代码之家  ›  专栏  ›  技术社区  ›  ssakl

我为什么要获得互操作服务。尝试从C#启动QTP时发生COM异常?

  •  1
  • ssakl  · 技术社区  · 17 年前

    Can I use a language other than VBScript to programmatically execute QTP Tests?

    System.Runtime.InteropServices.COMException 这似乎是由COM对象抛出 RPC_E_SERVERFAULT

    virtual public QuickTest.Application LaunchQuickTestPro()
    {
        QuickTest.Application qtpApp = new QuickTest.Application();
        qtpApp.Launch();
        qtpApp.Visible = false;
        return qtpApp;
    }
    

    qtpApp.Launch();

    更新 (没有开发环境),但是 发布版本不

    更新2 Main() 方法和我的 ExitQTP()

    ref 但是,每次在IDE(SharpDevelop 2.2.1)中运行时,代码都会工作。

        //Program starts here
        [STAThread]
        public static void Main(string[] args)
        {      
            string configFileName = 
                ConfigurationManager.AppSettings.Get("TestPathsConfigFile");
    
            TextReader configFile = new StreamReader(configFileName);
            QTPLauncher launcher = new QTPLauncher();
            string testName = null; 
            try
            {
                Debug.WriteLine("Creating QuickTest.Application object...");
                QuickTest.Application qtpApp = launcher.LaunchQuickTestPro();
                Debug.WriteLine("Successfully created QuickTest.Application object...");
    
                while((testName = configFile.ReadLine()) != null)
                {
                    if((testName != string.Empty) &&
                       (!(testName.TrimStart()).StartsWith(COMMENT_START)))
                    {
                        Debug.WriteLine(testName);
    
                        launcher.ExecuteQTPTest(testName, ref qtpApp);
    
                    }
                } 
    
                configFile.Close(); 
    
               ... //code unrelated to problem removed.
    
                configFile = null;
                launcher.ExitQTP(ref qtpApp);
            }
            catch(System.Runtime.InteropServices.COMException ce)
            {
                Console.Error.WriteLine(ce.StackTrace);
            }
        }
    
    //Exits QTP
    virtual public void ExitQTP(ref QuickTest.Application qtpApp)
    {
        qtpApp.Quit();
        qtpApp = null;
    }
    
    2 回复  |  直到 9 年前
        1
  •  1
  •   Robert Horvick    17 年前

    有一篇不错的博客文章,Grant Holliday将QT自动化,以便在Team Build下运行。许多相同的原则也适用。

    http://ozgrant.com/2008/02/28/running-hp-quicktest-professional-ui-tests-with-team-build/

    如果这不是问题所在,您需要提供有关如何处理QT应用程序对象的更多详细信息。

        2
  •  0
  •   forsvarir    15 年前

    使用以下内容:

    Object oQTPapp;
    
    oQTPapp = Server.CreateObject("QuickTest.Application");
    
    Application qtpApp = (Application) oQTPapp;
    

    希望它能解决你的问题。

    推荐文章