简体   繁体   English

以编程方式启动硒测试

[英]Programmatically start selenium test

Using C#, is it possible to start a selenium test? 使用C#,是否可以开始硒测试?

The only way I found is via the UI by right clicking on the test itself and starting it manually. 我发现的唯一方法是通过右键单击测试本身并手动启动它来通过UI。

在此输入图像描述

As what Arran said, this question is really just about how to run tests written using Visual Studio Unit Testing Framework and has nothing to do with Selenium. 正如Arran所说,这个问题实际上只是关于如何运行使用Visual Studio单元测试框架编写的测试,而与Selenium无关。

Since you can run the test from command line, what you need is just to start calling the command from your C# code. 由于您可以从命令行运行测试,因此您只需从C#代码开始调用命令即可。

For example, here is how to start mstest.exe with your tests (see MSDN documentation from more test options please): 例如,以下是如何使用您的测试启动mstest.exe(请参阅更多测试选项中的 MSDN文档):

Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(PATH_TO_MSTEST_EXE, "/testcontainer:" + PATH_TO_TEST_DLL);

myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();

Yes, just to expand on the original post, you can run selenium test as a C Sharp class as follows: 是的,只是为了扩展原始帖子,你可以运行selenium test作为C Sharp类,如下所示:

Download Visual studio community edition. 下载Visual Studio社区版。

Create a project with template Visual C#: unit test project 使用模板Visual C#创建项目:单元测试项目

Add selenium webdriver package 添加selenium webdriver包

add selenium support 添加硒支持

under the new project, add a new C sharp class: Add : Unit Test 在新项目下,添加一个新的C sharp类:Add:Unit Test

A selenium test is a C# class 硒测试是C#类

Now you create the test case 现在您创建测试用例

Add [TestClass] and [TestMethod] and so on 添加[TestClass]和[TestMethod]等

Now you can run the selenium test 现在你可以运行硒测试了

You can keep adding test cases under the same project 您可以在同一项目下继续添加测试用例

Each test case is saved as a .cs file 每个测试用例都保存为.cs文件

After a while , you will have a bunch of test cases under the same project and you can run them automatically one after the other by just right clicking the editor and click 'run tests' 过了一会儿,你会在同一个项目下有一堆测试用例,你可以通过右键单击编辑器并点击“运行测试”来一个接一个地自动运行它们

A lot more is involved, and its best to buy books on this area. 涉及的内容更多,最好在这个地区购买书籍。 A lot of reading to be done. 要做很多阅读。 Personally, I prefer Python for test scripting but I am sure others have their own favorite language. 就个人而言,我更喜欢Python用于测试脚本,但我相信其他人都有自己喜欢的语言。 It boils down to whichever language you have the most experience with(your comfort zone). 它归结为您最熟悉的语言(您的舒适区)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式在远程计算机上启动Selenium Hub - Start a selenium hub on a remote machine programmatically 以编程方式启动用于Selenium测试的.NET Core Web应用程序 - Programmatically start a .NET Core web app for Selenium testing 如何以编程方式从单元测试启动WPF应用程序? - How to programmatically start a WPF application from a unit test? 如何使按钮在MVC中启动新的硒单元测试? - How to make a button start a new selenium unit test in MVC? 硒测试开始后,Chromedriver 不断失去连接 - Chromedriver keeps losing connection right after the start of the selenium test C# selenium 目标机器只有在我尝试以编程方式启动它时才主动拒绝它 - C# selenium target machine actively refused it only when I try to start it programmatically 在C#selenium测试运行时打开Goog​​le Chrome开发人员工具控制台,或以编程方式阅读 - Open Google Chrome developer tool console while C# selenium test is running, or read it programmatically 以编程方式排序开始菜单 - Programmatically Sort Start Menu 以编程方式开始移动表格 - Programmatically start moving a form 以编程方式启动 Windows 服务 - Start Windows Service programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM