Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Easy automated testing in NodeJS with TestCafe


    Quickly get up and running with sensible automated testing scenarios written in ES6. Installing and creating your first automated tests with TestCafe is very easy. You can supercharge your quality control with a developer-friendly automation framework like TestCafe.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: Here, we have a mostly empty package.json, and a mostly empty directory. Getting started with TestCafe in a lot easier than some of the other Selenium-based alternatives. As you can see, we just installed the TestCafe Node module locally. We can use that version from the Node scripts directly.

    If we say TestCafe Chrome, and then the name of our test file, which we have yet to create, we'll call it egghead.io.scenario.js. Let's take a look at the empty scenario file. TestCafe test starts with a fixture. This is the next of what you're testing, like a description, and then the page you're actually going to test.

    That's egghead.io, the page, and then we're going to add the TestCafe test. We're going to say ensure that the title is correct, not the greatest test name. We're going to need a TestCafe selector in order to do the next part. It's from the TestCafe module.

    ES6, by the way, is supported automatically by TestCafe. We're going to grab the title element, and then we're going to check its inner text. We're just going to say not correct value to start. We'll start with the failing test.

    Let's run the test, and we should see the TestCafe runner open up in a browser window, and run our test for us. After loads, it'll load up the URL for us, and do the inspections. Back to our test, as expected, we have the wrong title there.

    It's "Short instructional screencast video tutorials for web developers on egghead.io." Let's grab this guy. That's what is the actual value on the site. We can verify that, if we want to look at Chrome inspector later.

    Let's run the test, and we'll see the same TestCafe runner come up, open up egghead.io, and do our quick verification for us. We have a passing test.