A bit about this project
I was asked by a co-worker for an example of using Selenium Web Browser Automation with C# so I wrote a quick example in C# with MSTest and DotNet Core and I posted it to Github.
https://github.com/andyrblank/Selenium-C-Sharp-Example
What is Selenium?
To answer I’ll quote directly from Selenium themselves:
Selenium automates browsers. That’s it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) be automated as well.
Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.
https://www.seleniumhq.org/
Getting Started
To use this example we’ll need a few things
Don’t worry! They’re all free as in Beer
I’ll write this blog post using Visual Studio Code because it’s available for Windows, Mac & Linux but… if you’re on Windows Visual Studio Community is my preferred IDE and I’d highly recommend it.
In Visual Studio Code we’ll use the hotkey:
CTRL + SHIFT + P
This will pull up the command window where we can type:
Git Clone
Once you see the clone option go ahead and hit ‘Enter’ and paste in the url below for the GitHub repository.
https:
Then hit enter again and choose a folder to save the code in.
Once you choose a Repository location Visual Studio Code will clone/download the code and prompt you to open the repository
Click Open Repository and expand SeleniumExample on the left until we can see GoogleSearchExample.cs
Double-click GoogleSearchExample.cs to open it.
If you haven’t used VS Code before it may prompt you to install some extensions to help with your code. I would definitely take it’s recommendation and install them.
After you install any recommended extensions VS Code will ask you to restore some dependencies for this project. In this case it’s some Selenium and MSTest Nuget packages that I’ve added to this project. Go ahead and click restore to get them.
Once the packages are restored go ahead and click terminal -> Run Build Task and Select ‘Build’ and hit enter.
After it’s done building we can now run the test. To run the test go ahead and click “Run Test” above SearchForSeleniumHQ() and the test should
- Open Chrome
- Go to google.com
- Search for ‘Selenium HQ’
- Assert some values from the results page
Here’s what that looks like
Will it Blend Run on Linux?
That’s it!
This is just a quick getting started but I’d like to go over the individual steps of this test and debugging the test in Visual Studio Code. If you like this and would like to see more on this topic drop a comment below.
Thanks!
CodeProject
The post Cross-Platform Selenium with DotNet Core appeared first on Blank's Tech Blog.