Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Webdriver (selenium2.0) + NUnit+C# (1)

Shulou Source: shulou.com Published: 2022-06-03 06:48:02 11月23日 Update

I was exposed to selenium web automation when I was in the first company, but I didn't build my own environment and configuration. I almost forgot about it now. In order to pick it up again, I specially organized this blog post. The writing style is not good, purely for the sake of recording, so that I can understand it in the future. If there is any incorrect writing, please put forward it directly

Prepare:

Install Firefox (45.0.2) browser and install plug-ins Firebug, FirePath

Following the successful installation of Selenium IDE (2.9.1 https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/),)

Install Virtual Studio2010, NUnit (2.5.10)

Http://docs.seleniumhq.org/download/ downloads C#Selenium-dotnet-2.53.0 package and IEWebdriver (IEDriverServer_Win32_2.42.0)

To create a C # project, select the Console Application template and reference all the dll files under .net40 (based on the actual. Net version) in the Selenium-dotnet package. The referenced dll is as follows

Namespace reference using

Through the above configuration, you can now simply use IEDriver to access Baidu. I put IEWebdriver under the AUTO folder under disk C, with the following code

(F 5 runs debugging, if there is an error prompt: Unexpected error launching Internet Explorer. Browser zoom level was set to 150%. It should be set to 100% (NoSuchDriver). The solution is to set the browser's zoom to 100% and maximize the Window maximize window)

7. You can also record a script using selenium IDE and run it with NUnit

Open the firefox browser, start selenium IDE in the upper right corner, record (open Baidu, search Taobao), choose to export the file to C#/NUnit/WebDriver, and save it to .cs file format.

8. When you add the recorded .cs file to the previously created project, there will be some errors. The .dll file under the NUnit installation path (lib and framework) needs to be referenced, and the namespace references using

9. Open NUnit and add project .exe (all under the Debug path by default). If there is an error as follows

The solution modifies the project properties-production, target platform, to AnyCPU. Re-produce the solution, add it to NUnit, check the case to run, and click Run. The success is shown in the following picture, ps. Script recorded with selenium IDE, the default is to use firefoxDriver, using Firefox does not need to download driver, the original support.

The first blog post of my life finally took 2 days to finish. I hope I can persevere and go further and further on the road of software testing.

Tags: File project browser browse run success method space script path production selection configuration original difficult almost family bad life code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Xiaomi Shulou Tech Info Docker