我試圖做我的第一次自動測試,並不斷收到此錯誤:錯誤CS1029 #error:'Generation error:Sequence contains沒有元素「。C#specflow無法修復:錯誤CS1029 t #error:'生成錯誤:序列不包含任何元素'
有人可以幫忙嗎?
我specflow feture:
Feature: SpecFlowFeature1
In order to see and check my todos
As planning user
I want to create and see my todos and done todos
@mytag
Scenario: Check default number of todos
Given user is on todolist.me main page
Then user sees list of 7 todo's
Scenario Outline: Check todos creation
Given user is on todolist.me main page
When user creates new todo with content: <content>
Then user sees todo with content: <content>
Scenario Outline: Chech todos can be checked and mark as done
Given user is on todolist.me main page
When user creates new todo with text: <text>
Then user checks the todo with text: <text>
Then user sees no todo with text: <text>
Then user sees done todo with text: <text>
Examples:
| content |
| just plain text |
| 1234567890 |
| [email protected]#$%^&*()_-+<>|
Examples:
| text |
| customToDoText |
我的配置:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject1
{
[Binding]
public class Conf
{
private static IWebDriver driver = new ChromeDriver();
public static IWebDriver GetDriver()
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
driver.Manage().Window.Maximize();
return driver;
}
[AfterTestRun]
public static void AfterTestRun()
{
driver.Quit();
}
}
}
我的步驟:
using System;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
using OpenQA.Selenium.Interactions;
using System.Collections.Generic;
using System.Linq;
namespace UnitTestProject1
{
[Binding]
public class SpecFlowFeature1Steps
{
private static IWebDriver driver = Conf.GetDriver();
[Given(@"user is on todolist.me main page")]
public void NavigateToTodoList()
{
driver.Navigate().GoToUrl("http://todolistme.net");
}
[When(@"user creates new todo with content: (.*)")]
public void WhenUserCreatesNewTodoWithContent(String todoContent)
{
driver.FindElement(By.Id("newtodo")).SendKeys(todoContent);
new Actions(driver).SendKeys(Keys.Enter).Build().Perform();
}
[When(@"user creates new todo with text: (.*)")]
public void WhenUserCreatesNewTodoWithText(String todoText)
{
driver.FindElement(By.Id("newtodo")).SendKeys(todoText);
new Actions(driver).SendKeys(Keys.Enter).Build().Perform();
}
[Then(@"user sees list of (.*) todo's")]
public void ThenUserSeesListOfTodoS(int count)
{
Assert.AreEqual(count, driver.FindElements(By.XPath("//span[contains(@id, 'mytodo')]")).Count);
}
[Then(@"user sees todo with content: (.*)")]
public void ThenUserSeesTodoWithContent(String todoContent)
{
List<IWebElement> list = driver.FindElements(By.XPath("//span[contains(@id, 'mytodo')]")).ToList();
IWebElement elem = list.Find(x => x.Text.Equals(todoContent));
Assert.AreEqual(todoContent, elem.Text);
}
[Then(@"user checks the todo with text: (.*)")]
public void ThenUserChecksTheTodoWithText(String todoText)
{
var listItem = driver.FindElement(By.XPath("//li[./span[contains(text(), 'customToDo')]]/input"));
new Actions(driver).Click(listItem);
}
[Then(@"user sees no todo with text: (.*)")]
public void ThenUserSeesNoTodoWithText(String todoText)
{
List<IWebElement> list = driver.FindElements(By.XPath("//ul[contains(@id, 'mytodos')]//span[contains(@id, 'mytodo')]")).ToList();
IWebElement elem = list.Find(x => x.Text.Equals(todoText));
Assert.AreNotEqual(todoText, elem.Text);
}
[Then(@"user sees done todo with text: (.*)")]
public void ThenUserSeesDoneTodoWithText(String todoText)
{
List<IWebElement> list = driver.FindElements(By.XPath("//ul[contains(@id, 'mydonetodos')]//span[contains(@id, 'mytodo')]")).ToList();
IWebElement elem = list.Find(x => x.Text.Equals(todoText));
Assert.AreEqual(todoText, elem.Text);
}
}
}
這一切後,我得到一個錯誤:
Error CS1029 #error: 'Generation error: Sequence contains no elements'
不知道該怎麼做才能解決這個問題。 請幫忙。 THX提前。
我有這個錯誤,這是問題 – user515867