Hey guys and welcome to Nomadic Dmitry channel
This channel is about travel but not only travel, it's about tech as well and
since we're talking about tech let's talk a bit about test automation
I already have a few videos about test automation
I already have a few videos about it
But today we are going to talk about some other tool
This is called TestCafe
I enjoy using it
I think it's powerful and doesn't have flaws that WebDriver/Selenium has
This is the developer website, you can learn more about the tool
Basically we are going to set it up today and run our tests
I'm running this in a Visual Studio code and have my tests written
We are going to automate the Formy App
We already had some experience automating this in the past
Today we are going to use TestCafe instead to achieve this goal
This is a simple, typical webform
We are going to fill this out and click "Submit"
That's a very simple test to confirm that the form is submitted and we got the success result
First step - download the Visual Studio Code, I already have it installed
We also need to install Node.js (npm package manager)
You can see the link in the description below
We are going to run this command right there
"npm install -g testcafe"
This is going to integrate TestCafe in our package
You should also initialize npm by typing "npm init"
Initialize Node.JS
And then install TestCafe there
again this is the test documentation which you can read to get started it's
also quite easy to automate our page we're gonna do this basically so first
This is structure of our TestCafe tests
This is a typical structure of tests without a PageObjects or anything like that
Let's just discuss it without PageObjects for now
We just import a "selector" from a TestCafe which allows us to interact with objects
It's a way of finding objects for the page
We can just inspect objects and find what are the specifics of accessing those
object let's say it's gonna say what it's going to say
This is going to display an ID for that specific object
We're using this to find the object
Simple to see what's happening in our tests
We are just typing the values inside the objects and clicking the buttons here
And then we are submitting the form
Since there is no unique ID for the submit button
We are using the class here and it's called "a"
And then we submit it
The second test is a "resize window" test which is also simple and it just resizes your browser to a proper width
Another test is to verify that after we submit this form - the success text is displayed
we have an assert that that confirms that the operation was successful
Again, we are finding the "h1" class
which defines the size of the text
and we are just checking that the value of this text is correct
How to run all those tests now?
Comparing to WebDriver - we don't need to initialize many things, it's all done easily
But here it's all managed for us
We just type "testcafe chrome [name of the test]"
It just launches the instance of TestCafe and executes test there
Then it's going to check the value of the text right there
You can do the same thing for executing the test in some other browser
You can also use "edge" or "firefox"
It works really good without any kind of configuration
It works really simple like that
You can also run those tests in parallel, for example if you have many tests
Just specify "-c 2" for two browser windows running at the same time
This way we can see all those tests running in parallel like that
You can see multiple browser windows running at the same time
It's all done!
By the way, all those actions are done using TestController and "t" represents that
You can also execute those tests separately
by using the "-t" parameter there
This way it executed just one test
There are also other nice features like scripts for the "npm" package
You can also execute tests "headless" which means not running the actual browser window (tests are executed without the user interface")
It will execute those without opening the browser
You just add "headless" as a parameter there
and specify the "headless" parameter as usual
The instance of a browser started for a second and then everything was running without the User Interface itself
The main advantage over the Selenium Webdriver is that you don't need to manage timeouts
It also has a very nice syntax like that
The only catch is that by default TestCafe doesn't know how to work with "Xpath"
You need to be creative and find a way of adding Xpath functionality yourself if needed
There is also a TestCafe IDE available
Which might help you setup your project more easily
Unfortunately, it costs money and it's not cheap
Thank you for watching! Please subscribe and press the "like" button if you liked this video