簡體   English   中英

“System.Dynamic.ExpandoObject”不包含 Specflow C# 中“用戶名”的定義

[英]'System.Dynamic.ExpandoObject' does not contain a definition for 'UserName' in Specflow C#

我收到一條錯誤消息:

“System.Dynamic.ExpandoObject”不包含“用戶名”的定義

這是我的代碼也是 Specflow、Selenium 和 Visual Studio

設想

Feature: OasisLogin
    Login to Oasis application

Scenario: Perform Login to Oasis application site
    Given I launch the application
    #And I click login link
    And I enter the following details
    | UserID   | Password |
    | admin    | password |
    And I click login button
    Then I should see Dashboard details link

步驟定義

namespace OasisSpecFlowTest.StepDefinition
{
    [Binding]
    public sealed class OasisSteps
    {
        OasisLoginPage oasisLoginPage = null;

        [Given(@"I launch the application")]
        public void GivenILaunchTheApplication()
        {
            IWebDriver webDriver = new ChromeDriver();
            webDriver.Navigate().GoToUrl("https://oasis.com/Login.aspx");
            oasisLoginPage = new OasisLoginPage(webDriver);
        }

        //[Given(@"I click login link")]
        //public void GivenIClickLoginLink()
        //{
           // oasisLoginPage.ClickLogin();
        //}

        [Given(@"I enter the following details")]
        public void GivenIEnterTheFollowingDetails(Table table)
        {
            dynamic data = table.CreateDynamicInstance();
            oasisLoginPage.Login((string)data.UserId, (string)data.Password);
        }

        [Given(@"I click login button")]
        public void GivenIClickLoginButton()
        {
            oasisLoginPage.ClickLoginButton();
        }

        [Then(@"I should see Dashboard details link")]
        public void ThenIShouldSeeDashboardDetailsLink()
        {
            Assert.That(oasisLoginPage.IsEmployeeDetailsExist(), Is.True);
        }

    }
}

namespace OasisSpecFlowTest.StepDefinition
{
    [Binding]
    public sealed class OasisSteps
    {
        OasisLoginPage oasisLoginPage = null;

        [Given(@"I launch the application")]
        public void GivenILaunchTheApplication()
        {
            IWebDriver webDriver = new ChromeDriver();
            webDriver.Navigate().GoToUrl("https://oasis.com/Login.aspx");
            oasisLoginPage = new OasisLoginPage(webDriver);
        }

        //[Given(@"I click login link")]
        //public void GivenIClickLoginLink()
        //{
           // oasisLoginPage.ClickLogin();
        //}

        [Given(@"I enter the following details")]
        public void GivenIEnterTheFollowingDetails(Table table)
        {
            dynamic data = table.CreateDynamicInstance();
            oasisLoginPage.Login((string)data.UserId, (string)data.Password);
        }

        [Given(@"I click login button")]
        public void GivenIClickLoginButton()
        {
            oasisLoginPage.ClickLoginButton();
        }

        [Then(@"I should see Dashboard details link")]
        public void ThenIShouldSeeDashboardDetailsLink()
        {
            Assert.That(oasisLoginPage.IsEmployeeDetailsExist(), Is.True);
        }

    }
}

Selenium 頁碼

namespace OasisSpecFlowTest.Pages
{
    class OasisLoginPage
    {
        public IWebDriver WebDriver { get; }

        public OasisLoginPage(IWebDriver webDriver)
        {
            WebDriver = webDriver;
        }

        //UI Elements
        //public IWebElement InkLogin => WebDriver.FindElement(By.LinkText("Login"));

        public IWebElement TxtUserID => WebDriver.FindElement(By.Name("User ID"));

        public IWebElement TxtPassword => WebDriver.FindElement(By.Name("Password"));

        public IWebElement BtnLogin => WebDriver.FindElement(By.CssSelector(".btn-default"));

        public IWebElement InkEmployeeDetails => WebDriver.FindElement(By.LinkText("Employee Details"));

        //public void ClickLogin() => InkLogin.Click();

        public void Login(string userid, string password)
        {
            TxtUserID.SendKeys(userid);
            TxtPassword.SendKeys(password);
        }

        public void ClickLoginButton() => BtnLogin.Submit();

        public bool IsEmployeeDetailsExist() => InkEmployeeDetails.Displayed;
    }
}

也是相同的代碼,但這次使用的是 UserID??

異常信息截圖

這是它顯示的錯誤

dynamic data = table.CreateDynamicInstance();
oasisLoginPage.Login((string)data.UserName, (string)data.Password);

我想兩個都試試。

我發現我已經更改了我的代碼 public void Login(string UserID, string Password) { TxtUserName.SendKeys(UserID); TxtPassword.SendKeys(密碼); 和步驟定義動態數據 = table.CreateDynamicInstance(); oasisLoginPage.Login((string)data.UserID, (string)data.Password);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM