phadaphunk
phadaphunk

Reputation: 13283

Programmatically start selenium test

Using C#, is it possible to start a selenium test?

The only way I found is via the UI by right clicking on the test itself and starting it manually.

enter image description here

Upvotes: 1

Views: 1261

Answers (2)

Anton
Anton

Reputation: 11

Yes, just to expand on the original post, you can run selenium test as a C Sharp class as follows:

Download Visual studio community edition.

Create a project with template Visual C#: unit test project

Add selenium webdriver package

add selenium support

under the new project, add a new C sharp class: Add : Unit Test

A selenium test is a C# class

Now you create the test case

Add [TestClass] and [TestMethod] and so on

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

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. It boils down to whichever language you have the most experience with(your comfort zone).

Upvotes: 0

Yi Zeng
Yi Zeng

Reputation: 32855

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.

Since you can run the test from command line, what you need is just to start calling the command from your C# code.

For example, here is how to start mstest.exe with your tests (see MSDN documentation from more test options please):

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();

Upvotes: 3

Related Questions