Lesson 08 of 20 · Beginner course
Understand every line of your first test
Your first test has only a few instructions. Read them as a small recipe: choose the website, name the check, open the page, check its title, and finish.
base_url "https://aliilyas.github.io/bruster/demo/"
test "the practice page opens"
navigate "."
expect title "Bruster browser lab"
endThe website address
base_url gives the starting website address. A URL is an address such as the one in your browser’s address bar. In this example, the address ends with /bruster/demo/.
The address is between double quotation marks because it is text. Keep the final slash. Later, you will use addresses relative to this starting point, and the final slash makes the directory you mean clear.
The test name
test "the practice page opens" begins a named test. The name is for people: it appears in the result, helping you understand what passed or failed.
You can change this name without changing what the browser does. A useful name describes the intended behavior. “The practice page opens” is easier to understand than “test123”.
The navigation action
navigate "." tells the browser to open the current base directory. In this file, the dot means the demo directory given by base_url.
The dot does not refer to a folder on your computer here. It is a relative website address. Bruster combines it with the base URL to decide which page to visit.
You could use a full HTTP or HTTPS address in navigate. Keeping the address in base_url makes it easier to run the same test against another copy of the same page later.
The assertion
expect title "Bruster browser lab" checks the page’s title. This is the text normally shown on the browser tab. It is different from the large heading printed inside the page.
On our demo, the tab title is Bruster browser lab, while the visible heading says Browser smoke test. If you accidentally use the visible heading in this title assertion, the test will fail.
The word expect introduces the assertion. Read the line as “check that the page title is exactly Bruster browser lab.”
The end of the block
end closes the test. The lines between test and end belong to that test. A group of related lines like this is called a block.
The extra spaces at the beginning of the action lines are called indentation. They make the block easier to read. Bruster does not require those spaces, but keeping them is a good habit.
A few small writing rules
- Put one command on each line.
- Use straight double quotes around text and selectors.
- Make sure every opening quote has a closing quote. A missing quote changes how the line is read.
- Close each test with
end. - Use
#outside quotes to begin a comment for humans. Bruster ignores the comment, from the#to the end of that line.
For example, # Check the page title is a comment. Later you will see "#name" inside quotes; that is a selector, not a comment. The quotation marks make the difference.
Try it: rename the check
Change the test name to "my first website check", save the file, and run it again. Leave the expected title unchanged.
What should change?
The PASS line should use your new test name. The check should still pass, because changing its name did not change the page or expected title.
Explain it without reading the code
Be able to say where the test goes, what it checks, and how it knows when that test block ends.