需要驱动程序在c#/ Selenium中的每个测试之前初始化(Need driver to initialise before every test in c#/Selenium)

编程入门 行业动态 更新时间:2024-10-15 12:31:56
需要驱动程序在c#/ Selenium中的每个测试之前初始化(Need driver to initialise before every test in c#/Selenium)

我有一个与启动Firefox驱动程序的测试分开的类:

public static class DriverContext { public static IWebDriver Driver { get; set; } public static void Initialize() { Driver = new FirefoxDriver(); } }

我的功能文件有一堆步骤定义类当我运行功能文件时,我希望每个方案/功能都可以调用此类,打开浏览器并导航到网页。

我怎么做?

谢谢!

I have an class separate to the tests which initiates the Firefox driver:

public static class DriverContext { public static IWebDriver Driver { get; set; } public static void Initialize() { Driver = new FirefoxDriver(); } }

I have a stack of step definition classes for my feature files When i run the feature files i want each scenario/feature to call this class, open the browser and navigate to a webpage.

How do i do that?

Thanks!

最满意答案

您的问题没有说明您使用的框架。

因此,以SpecFlow为例,您可以使用[BeforeScenario]或[BeforeFeature]等[BeforeFeature]并在那里调用初始化方法。

然后,您可能希望在每次运行后使用[AfterScenario]关闭浏览器窗口。

https://github.com/techtalk/SpecFlow/wiki/Hooks

Your question didn't indicate what framework you use.

So, taking SpecFlow as an example, you can use hooks such as [BeforeScenario] or [BeforeFeature] and call the initialise method there.

You might then want to use [AfterScenario] to close the browser windows after each run.

https://github.com/techtalk/SpecFlow/wiki/Hooks

更多推荐

本文发布于:2023-08-07 01:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458717.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   驱动程序   测试   Selenium   test

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!