如何在泛型类中拥有动态URL

时间:2009-04-22 12:35:23

标签: vb.net nunit watin

我需要一个最好来自Test Class的动态URL。任何人都可以帮我格式化这个设计模式来处理来自测试的动态链接。而不是一个恒定的HomePageURL。

Namespace TestDesign
Public Class HomePage
    Inherits IE
    Public Const HomePageURL As String = "testlink"

    Public Sub New()
        MyBase.New(HomePageURL)
    End Sub

    Public Sub New(ByVal instance As IE)
        MyBase.New(instance.InternetExplorer)
    End Sub

    Public ReadOnly Property UserIDField() As TextField
        Get
            Return TextField(Find.ById(New Regex("txtuserName")))
        End Get
    End Property
    Public ReadOnly Property PasswordField() As TextField
        Get
            Return TextField(Find.ById(New Regex("txtPassword")))
        End Get
    End Property
    Public ReadOnly Property ContinueButton() As Button
        Get
            Return Button(Find.ById(New Regex("Submit")))
        End Get
    End Property
    Public ReadOnly Property LogoutLink() As Link
        Get
            Return Link(Find.ById(New Regex("lnkLogout")))
        End Get
    End Property

    Friend Sub Login(ByVal username As String, ByVal password As String)
        UserIDField.TypeText(username)
        PasswordField.TypeText(password)
        ContinueButton.Click()
    End Sub

    Friend Sub Logout()
        LogoutLink.Click()
    End Sub

End Class    

结束命名空间

1 个答案:

答案 0 :(得分:0)

我如何处理这个问题是将基本网址放入应用程序配置中,然后构建一个URL类来构建它们就是一个例子:

在app config中

<appSettings> <add key="TestServerUri" value="http://www.apple.com"/> </appSettings>

在课程文件

    public static Uri AppleHome

    {
        get
        {
            return new Uri(ConfigurationManager.AppSettings["TestServerUri"]);
        }
    }

    public static Uri Iphone = new Uri(AppleHome, @"/iphone/");
相关问题