Transcripted Summary



Chapter 5, test cases.

We've talked a little bit about test cases.

We've mentioned that there is a Test Cases section in a test suite file. We mentioned that each section within a test case file or a test suite file is denoted by 3 asterisks, a space, the name of the section, a space, and 3 asterisks.

It's also left justified meaning it's all the way to the left. There are no spaces in between these.

As I mentioned before, spacing is very important in Robot Framework.

Robot Framework only knows a section includes Test Cases if the section heading is set up exactly like I show here.



The same is true for the Settings section and the other sections. One of those was the Keywords section we talked about in the last chapter.

Another we haven't talked about yet is called the Variables section.

# Robot Test Flow

In the Test Cases I have in front of me, from exercise directory 005-TestCases, the file first-test-case.robot, you'll notice I only have 2 sections.


*** Settings ***
Library  SeleniumLibrary

*** Test Cases ***
Check invoice manager page
    Open Browser    http://inv.beaufortfairmont.com/    chrome
    #Verify that the text "Invoice Manager" is on the front page

I wanted to use this simple example to talk about test cases and exactly what's going on. You'll notice in other test files we have other sections involved.

The flow for how Robot Framework works is easily shown here.

The first thing to happen is that the Variables section is loaded.

We don't have a Variables section here, but if we did, it might look something like this.



The Variables section is the first thing that happens within the flow of a Robot Framework script.

The variables are loaded. They're created or kept in mind to be used by the program. But the variables have to be defined so that the Settings section can use them as well.

  1. First the Variables section happens,
  2. Second, the Settings section, and
  3. Third, the **_Test Cases _**section happens.

The Keywords section doesn't actually get run until a keyword defined in the Keywords section is used within that test case.

Test cases are run from top to bottom, meaning the first test case at the top of the Test Cases section runs first.

The next one runs second, and so on.

The steps in the test case are run from top to bottom.

This example is about learning to write a test case and adding steps to it.

Like I've mentioned before, each of these exercises has a README file.



NOTE

The README talks about the objectives for this particular section. You can read them there in case that's easier for you to understand.

It's also got a challenge.

The challenge that we're going to have here is to verify that the text “Invoice Manager” is on the first page of the application.

We've shown this application before, but this is what it looks like.



It's a pretty simple invoicing application.

  • The “Invoices” page is here.
  • The “Add invoice” page is here. That allows you to add an invoice.

All this test case is going to do when you're done with it is to verify that “Invoice Manager” is on this page.

Let's go just make sure in a manual way that it's actually there. And yep, we can see that it's here. That's the text we're looking for on this page.

All this test will do is open up the browser, go to the URL and look for “Invoice Manager” on that page.

That's your challenge; you'll do those steps here.

NOTE

You may have noticed by now one thing that's a little different. I have colors in my test cases that you may or may not, depending on if you have an extension plugged in to your Visual Code IDE or your IDE, whichever one that is you're using. If you're using a different text editor, you may want to go out and see if there's a plugin that's right to highlight text for you. The one that I'm using in VS Code is called Robot Framework Language Server.

You'll notice in my test case that line 7 is green and it's green because this line is a comment.

It starts with the hash or pound sign (#). The pound sign is used to say, “don't execute anything after this line or anything on this line”.

Comments are used in programming to make sure that we can add contextual information to our code.

We'll do the same with our Robot Framework tests.

You can also stub out pseudo code for what's supposed to happen, which is what I'm doing here. I'm saying, "Hey, verify that the text ‘Invoice Manager’ is on the front page." How you do that is up to you.

So once again, you know that you can cheat and go look at the first-test-case.answer.robot file, but I'll encourage you not to.

Now, pause the video and go verify that the text “Invoice Manager” is on the front page.

SPOILER ALERT

If you've done that exercise, now take a look at my answer to this. It's very similar to what you had before.

We've got an Open Browser call and then the only thing that I really added of value was Page Should Contain and then “Invoice Manager”.


*** Settings ***
Library  SeleniumLibrary

*** Test Cases ***
Check invoice manager page
    Open Browser    http://inv.beaufortfairmont.com/    chrome
    Comment    Checking that we're on the invoice manager page
    Page Should Contain    Invoice Manager

Page Should Contain is a keyword that we found in the SeleniumLibrary.

Remember we looked up the SeleniumLibrary to find keywords in it.



If you want to know how to find specific keywords, I'm not really sure how to tell you.

It's kind of like when they taught you how to look things up to the library, to look in the card catalog and brainstorm with keyword creation. You've got to kind of brainstorm a little bit here to figure out what it is you should be looking for.

Page should contain, browser should contain, should be in


The word “should” is usually associated with some of the keywords, which assert something, or make sure that something works or does a validation or verification point.



So “should” would be in there for those.

It's going to be a little tricky to learn the language of each particular library, but you'll be able to figure it out with a little bit of time.

Worst case, read through the keywords until you see something that looks like it could work and then try it, see what happens.

# Quick Recap

So now you've been able to create a test case and run it. You should understand how a test case runs, that it runs from top to bottom,

You should understand which sections can be in a Test Case file — Settings, Test Cases, Keywords and Variables.

And you know the order of these as well, in terms of how they execute and when they execute.



Resources



© 2024 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR