This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Easy automated testing in NodeJS with TestCafe

    Trevor EwenTrevor Ewen

    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.

    javascriptJavaScript
    nodeNode.js
    chromeChrome
    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    Instructor: 00:01 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.

    00:25 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.

    00:57 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.

    01:24 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.

    01:44 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.

    02:08 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.

    02:28 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.

    Discuss

    Discuss