Selenium C# MSTest Test Automating Angular, React, VueJS and 20 More
source link: https://www.automatetheplanet.com/selenium-automate-all-cshap-mstest/?utm_campaign=selenium-automate-all-cshap-mstest
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Selenium C# MSTest Test Automating Angular, React, VueJS and 20 More
In the new article from the Web Automation Series with C#, we will talk about creating a data-driven MSTest test automating all major web technologies such as React, Angular, Vue.js, and many more. Many people speculate that Selenium WebDriver is outdated and cannot work for modern web technologies, thus promoting other questionable tools such as Cypress, Playwright, Protractor (which is going away). Again if you apply the proper design patterns and best practices, you can make almost any tool work. I am not entirely against the mentioned solutions. You can still succeed. I am just saying that many people started recently saying awful stuff about Selenium. I can say the same about these solutions. With the proper knowledge, you can easily automate everything with Selenium. This article is the proof.
The Use Case
What are we going to test? Recently, I watched a webinar organized by the Test team of JetBrains. It was OK. It was in Java. The most helpful thing I got was this fantastic website on which we will experiment. The website is called TodoMVC and is implementing the same TODO app functionality using 30+ most popular web technologies. Everything is open-source and free.
When you click on a particular technology, the corresponding app written on it opens.
We will create a single data-driven test using MSTest, where we will open 20+ technologies. Then we will add a few TODO items, mark as complete the first one and verify the numbers of the items left.
The Selenium Test
I suggest to check out MSTest Cheat Sheet. Below you can see how a single test looks like automating the jQuery TODO app. On purpose I organized the login into few private methods.
The method WaitAndFindElement waits for the web elements to appear on the page, and then we return them. We use the WebDriverWait + the ExpectedConditions methods that come from the DotNetSeleniumExtras.WaitHelpers NuGet package. We use another method part of the same package in the ValidateInnerTextIs method - TextToBePresentInElement.
Another interesting point is that I used lots of XPath Axes locators for most elements to make the tests stable and maintainable. You can check two articles that can help you write maintainable good locators - Most Underrated WebDriver Locator – XPath and Most Exhaustive XPath Locators Cheat Sheet. I suggest you learn to write the XPath yourself than relying on plugins since they generate, most of the time, ugly, not maintainable XPath.
Another interesting point is how we add a TODO item to the list. We don't have a submit button, but instead, we need to press Enter. To do that, we use the Actions class, which allows us to do all sorts of advanced interactions. To learn all different actions you can do in WebDriver check - Most Complete Selenium WebDriver C# Cheat Sheet
Data-driven Test for 22 Web Technologies
To test all major technologies in a single test, we can use the MSTest DataRow attribute. Next, the TestInit method marked with the TestInitialize attribute executes before each test. There we start the browser each time and initialize the WebDriverWait + Actions classes. Finally, the TestCleanup method marked with the TestCleanup attribute closes the browser.
Video Explanation
Recently as part of my XUnit Selenium Video Course for LambdaTest, I recorded a chapter where I explain step by step how to create a similar project and tests using xUnit. You can find the video below.
Online Training
NON-FUNCTIONAL
START:13 October 2021
Enterprise Test Automation Framework
LEVEL: 3 (Master Class)
After discussing the core characteristics, we will start writing the core feature piece by piece.
We will continuously elaborate on why we design the code the way it is and look into different designs and compare them. You will have exercises to finish a particular part or extend it further along with discussing design patterns and best practices in programming.
Duration: 30 hours
4 hour per day
-20% coupon code:
BELLATRIX20
Recommend
-
11
MS Test v2 RunSettings for Selenium Tests on Multiple Browsers Our team has been using the DataSource attribu...
-
8
Selenium C# NUnit Test Automating Angular, React, VueJS and 20 More
-
3
Selenium VB.NET NUnit Test Automating Angular, React, VueJS and 20 More
-
2
低代码要对 vuejs/react/angular 降维打击? V2EX › 程序员 低代码要对 vuejs/react/angular 降维打击?
-
8
LambdaTest Team Posted on Mar...
-
5
MSTest tutorial | Selenium In C# Using MSTest | C# (4 Part Series) Learn to write and run your first test scr...
-
3
By Nish Tahir in Programmi...
-
7
Unit Testing with NUnit and MSTest and TX Text Control .NET 32.0 Important Notice This article explains how to use build servers for the following versions and requirements:
-
4
Introducing the MSTest Runner – CLI, Visual Studio, & More Amaury Le...
-
6
Introducing the MSTest Runner – CLI, Visual Studio, & More Amaury Le...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK