Max*_*iar 4 c# linq xpath qa specflow
我试图制作我的第一个自动测试并且我不断收到此错误:错误CS1029 #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 |
| ~!@#$%^&*()_-+<>|
Examples:
| text |
| customToDoText |
Run Code Online (Sandbox Code Playgroud)
我的配置:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的步骤:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
完成所有这些后,我收到一个错误:
Error CS1029 #error: 'Generation error: Sequence contains no elements'
Run Code Online (Sandbox Code Playgroud)
不知道该怎么做才能解决这个问题.请帮忙.THX提前.
小智 9
我知道答案已被接受,但我找到了一个不同的解决方案.
我认为问题是您按顺序指定了两个场景轮廓,然后将示例放在它们下面.使用"方案大纲"时,系统需要在指定其他方案之前使用示例块.因此,如果您只是在两个场景轮廓之间移动第一个示例块,则不应再发生错误.以下是您的功能文件应如下所示:
特征:
SpecFlowFeature1
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>
Examples:
| content |
| just plain text |
| 1234567890 |
| ~!@#$%^&*()_-+<>|
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:
| text |
| customToDoText |
Run Code Online (Sandbox Code Playgroud)
@mytag
场景:
检查默认的待办事项数量
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>
Examples:
| content |
| just plain text |
| 1234567890 |
| ~!@#$%^&*()_-+<>|
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:
| text |
| customToDoText |
Run Code Online (Sandbox Code Playgroud)