Visual studio 2015 编码用户界面-如何拥有可配置的URL';s

Visual studio 2015 编码用户界面-如何拥有可配置的URL';s,visual-studio-2015,coded-ui-tests,Visual Studio 2015,Coded Ui Tests,我创建了简单的编码UI测试,我在其中执行以下操作: 打开浏览器 转到网址 单击超链接(webapp域内的链接) 生成UIMapping之后,我看到了一堆自动生成的映射代码。在UIMapping文件(类)中,我看到了本质上是硬编码的URL 例如: this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://mytesturl:8000"; this.mUIItem50006598Hyperlink.FilterProper

我创建了简单的编码UI测试,我在其中执行以下操作:

  • 打开浏览器
  • 转到网址
  • 单击超链接(webapp域内的链接)
  • 生成UIMapping之后,我看到了一堆自动生成的映射代码。在UIMapping文件(类)中,我看到了本质上是硬编码的URL

    例如:

    this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://mytesturl:8000";
    this.mUIItem50006598Hyperlink.FilterProperties[HtmlHyperlink.PropertyNames.Href] = "http://mytesturl:8000/link"
    

    如何配置我的自动化UI测试,以便在不同的环境(开发、测试、产品等)下运行相同的测试?

    正如Adrian提到的,这是一个经常重复的问题,没有明确的答案。你可以找到一些关于我方法的信息

    简而言之,如果您依赖CodedUI映射功能,您将无法动态配置环境,除非您的测试方法:

    • 调用一个helper方法导航到一个基本URL,而这个URL又取决于某种数据驱动的配置(XML/app.config文件、CSV、电子表格)。你可以在上面的链接中找到关于如何解决我的问题的信息
    • 调用映射器生成的方法。创建它时,请确保假定您仅从基本URL导航,而不是打开浏览器等
    因此,您的代码将如下所示:

    [TestMethod]
    public static void GenericTestMethod() {
        //get browserWindow from your test setup method etc.
        GoToEnvironmentBaseUrl(browserWindow);
        MapperGeneratedCodedUiMethod();
        AssertStuff();
    }
    
    public static void GoToEnvironmentBaseUrl(BrowserWindow browserWindow) {
        browserWindow.NavigateToUrl(new Uri("http://www."
                + ConfigurationManager.AppSettings.Get("EnvironmentURLMod")
                + ".com"));
    }
    
    可能重复的