“System.Dynamic.ExpandoObject"在 Specflow C# 中不包含“UserName"的定义 [英] 'System.Dynamic.ExpandoObject' does not contain a definition for 'UserName' in Specflow C#

查看:38
本文介绍了“System.Dynamic.ExpandoObject"在 Specflow C# 中不包含“UserName"的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一条错误消息:

System.Dynamic.ExpandoObject"不包含UserName"的定义

'System.Dynamic.ExpandoObject' does not contain a definition for 'UserName'

这是我的代码,还有 Specflow、Selenium 和 Visual Studio

Here is my code also it Specflow, Selenium, and 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);
        }

    }
}

硒页面

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;
    }
}

也是同样的代码,但这次是用户 ID??

Also the same code but this time with 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);

I figure it out I have change my code public void Login(string UserID, string Password) { TxtUserName.SendKeys(UserID); TxtPassword.SendKeys(Password); And Step Definition dynamic data = table.CreateDynamicInstance(); oasisLoginPage.Login((string)data.UserID, (string)data.Password);

这篇关于“System.Dynamic.ExpandoObject"在 Specflow C# 中不包含“UserName"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆