【发布时间】:2021-11-04 06:57:01
【问题描述】:
我正在对 Blazor Web 应用程序进行 Selenium 测试,我想设置 SfDropDownList 的值。
我使用 SfDropDownList 创建了一个空的 Blazor 项目,并使用 Selenium 和 XUnit 创建了一个测试项目。项目下载地址:https://www.syncfusion.com/downloads/support/forum/167910/ze/SYncfusionSelenium_b2ea0a0e
<SfDropDownList ID="MyDropdown" TValue="string" TItem="Games" Placeholder="Select a game" DataSource="@LocalData">
<DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings>
</SfDropDownList>
@code {
public class Games
{
public string ID { get; set; }
public string Text { get; set; }
}
List<Games> LocalData = new List<Games> {
new Games() { ID= "Game1", Text= "American Football" },
new Games() { ID= "Game2", Text= "Badminton" },
new Games() { ID= "Game3", Text= "Basketball" },
new Games() { ID= "Game4", Text= "Cricket" },
new Games() { ID= "Game5", Text= "Football" },
};
}
这就是我设法设置/更改下拉列表值的方法:我通过 ID 访问 SfDropDownList 并从我的类“游戏”中设置“文本”。我必须这样做 2 次以确保正确设置,这是迄今为止我想出的最好的。
Thread.Sleep(TimeSpan.FromMilliseconds(250));
_driver.FindElement(By.Id("MyDropdown")).SendKeys("Basketball");
Thread.Sleep(TimeSpan.FromMilliseconds(250));
_driver.FindElement(By.Id("MyDropdown")).SendKeys("Basketball");
运行 Selenium:
-
在 http://localhost:5000 启动服务器
-
打开 VS -> 选择 SyncfusionSelenium 而不是 IIS Server 作为启动选项,然后按 Ctrl+F5
-
或打开项目文件夹->打开控制台输入“dotnet watch run debug”
-
-
打开测试资源管理器并运行/调试“Test1”
我非常感谢这里的一些帮助,因为我找不到如何为 SfDropDownList 执行此操作的示例。
有用的链接:
- https://www.syncfusion.com/forums/167910/selenium-how-to-manage-a-sfdropdownlist-with-selenium
- https://blazor.syncfusion.com/documentation/dropdown-list/getting-started
- https://docs.microsoft.com/en-us/aspnet/core/blazor/test?view=aspnetcore-5.0
亚历克斯
【问题讨论】:
标签: selenium blazor xunit syncfusion