简体   繁体   中英

Can Selenium be used in a stand-alone c# program?

is it possible to integrate the Selenium tests into an own program in C# and the user only has to execute the program which then performs actions in the browser without the user having installed Selenium?

My goal is to create a bot that performs certain actions on a website that the user has previously configured in a WinForm/WPF program.

In my opinion that should generally be possible, but it might be tricky.

For the Microsoft Internet Explorer there is a driver needed. If you want to use Chrome you will have to use the open source implementation and a driver.
These drivers are only executables, which could be deployed with the *.exe

If you want to use Firefox the user needs to install the Version cooperating with the Selenium version.
You can look up the supported Versions for Firefox and Co on the selenium page .

I hope i could help you a bit...

If you have configured "stuff" and test steps in windows forms, just create a "RUN" button that will execute the test. Well, at this point, whatever your test does, should no longer be a "test", it should be a function that takes whatever input you have from your form, and do steps accordingly.

For example:

public void RunTest()
{
    IWebDriver driver = new ChromeDriver(); //Or whatever driver you use.
    /*
    *   Do all your "test" steps.
    *   
    *   Basically, in here put all code from SetupTest & Test Method & Teardown 
    *   methods so the browser is initialized, all steps are done, and the browser
    *   is closed in the end.
    */
}

And just call RunTest() when your button is pressed. Of course, at this point like I said, this is not a test, it's just a function that opens the browser and (with the help of selenium), does whatever you want it to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM