@@ -9,17 +9,17 @@ weight: 2
99{{% /notice %}}
1010
1111First, start by asking yourself whether or not you really need to use a browser.
12- Odds are good that, at some point, if you're working on a complex web application,
12+ Odds are that, at some point, if you are working on a complex web application,
1313you will need to open a browser and actually test it.
1414
1515Functional end-user tests such as Selenium tests are expensive to run, however.
1616Furthermore, they typically require substantial infrastructure
1717to be in place to be run effectively.
18- It's a good rule to always ask yourself if what you want to test
18+ It is a good rule to always ask yourself if what you want to test
1919can be done using more lightweight test approaches such as unit tests
2020or with a lower-level approach.
2121
22- Once you have made the determination that you're in the web browser testing business,
22+ Once you have made the determination that you are in the web browser testing business,
2323and you have your Selenium environment ready to begin writing tests,
2424you will generally perform some combination of three steps:
2525
@@ -28,7 +28,7 @@ you will generally perform some combination of three steps:
2828* Evaluate the results
2929
3030You will want to keep these steps as short as possible;
31- one to two operations should be enough much of the time.
31+ one or two operations should be enough most of the time.
3232Browser automation has the reputation of being "flaky",
3333but in reality, that is because users frequently demand too much of it.
3434In later chapters, we will return to techniques you can use
@@ -41,7 +41,7 @@ and using the web browser only when you have absolutely no alternative,
4141you can have many tests with minimal flake.
4242
4343A distinct advantage of Selenium tests
44- are their inherent ability to test all components of the application,
44+ is their inherent ability to test all components of the application,
4545from backend to frontend, from a user's perspective.
4646So in other words, whilst functional tests may be expensive to run,
4747they also encompass large business-critical portions at one time.
@@ -50,7 +50,7 @@ they also encompass large business-critical portions at one time.
5050### Testing requirements
5151
5252As mentioned before, Selenium tests can be expensive to run.
53- To what extent depends on the browser you're running the tests against,
53+ To what extent depends on the browser you are running the tests against,
5454but historically browsers' behaviour has varied so much that it has often
5555been a stated goal to cross-test against multiple browsers.
5656
@@ -66,39 +66,39 @@ will quickly become a non-trivial undertaking.
6666Larry has written a web site which allows users to order their
6767custom unicorns.
6868
69- The general workflow (what we'll call the "happy path") is something
69+ The general workflow (what we will call the "happy path") is something
7070like this:
7171
7272* Create an account
73- * Configure their unicorn
74- * Add her to the shopping cart
73+ * Configure the unicorn
74+ * Add it to the shopping cart
7575* Check out and pay
76- * Give feedback about their unicorn
76+ * Give feedback about the unicorn
7777
7878
7979It would be tempting to write one grand Selenium script
8080to perform all these operations–many will try.
8181** Resist the temptation!**
82- Doing so will result in a test that
82+ Doing so will result in a test that
8383a) takes a long time,
8484b) will be subject to some common issues around page rendering timing issues, and
85- c) is such that if it fails,
86- it won't give you a concise, "glanceable" method for diagnosing what went wrong.
85+ c) is such that if it fails,
86+ it will not give you a concise, "glanceable" method for diagnosing what went wrong.
8787
8888The preferred strategy for testing this scenario would be
8989to break it down to a series of independent, speedy tests,
9090each of which has one "reason" to exist.
9191
92- Let's pretend you want to test the second step:
92+ Let us pretend you want to test the second step:
9393Configuring your unicorn.
9494It will perform the following actions:
9595
9696* Create an account
9797* Configure a unicorn
9898
99- Note that we're skipping the rest of these steps,
99+ Note that we are skipping the rest of these steps,
100100we will test the rest of the workflow in other small, discrete test cases
101- after we're done with this one.
101+ after we are done with this one.
102102
103103To start, you need to create an account.
104104Here you have some choices to make:
@@ -109,11 +109,11 @@ Here you have some choices to make:
109109 taken into account before configuration begins?
110110
111111Regardless of how you answer this question,
112- the solution is to make it part of the "set up the data" portion of the test–
113- if Larry has exposed an API that enables you (or anyone)
112+ the solution is to make it part of the "set up the data" portion of the test.
113+ If Larry has exposed an API that enables you (or anyone)
114114to create and update user accounts,
115- be sure to use that to answer this question–
116- if possible, you want to launch the browser only after you have a user "in hand",
115+ be sure to use that to answer this question.
116+ If possible, you want to launch the browser only after you have a user "in hand",
117117whose credentials you can just log in with.
118118
119119If each test for each workflow begins with the creation of a user account,
@@ -184,7 +184,7 @@ var user = userFactory.createCommonUser(); //This method is defined elsewhere.
184184// Logging in on this site takes you to your personal "My Account" page, so the
185185// AccountPage object is returned by the loginAs method, allowing you to then
186186// perform actions from the AccountPage.
187- var accountPage = loginAs(user.email, user.password);
187+ var accountPage = loginAs(user.email, user.password);
188188 {{< / code-panel >}}
189189 {{< code-panel language="kotlin" >}}
190190// Create a user who has read-only permissions--they can configure a unicorn,
@@ -235,12 +235,12 @@ Here is one way of doing this (continuing from the previous example):
235235
236236{{< code-tab >}}
237237 {{< code-panel language="java" >}}
238- // The Unicorn is a top-level Object--it has attributes, which are set here.
238+ // The Unicorn is a top-level Object--it has attributes, which are set here.
239239// This only stores the values; it does not fill out any web forms or interact
240240// with the browser in any way.
241241Unicorn sparkles = new Unicorn("Sparkles", UnicornColors.PURPLE, UnicornAccessories.SUNGLASSES, UnicornAdornments.STAR_TATTOOS);
242242
243- // Since we're already "on" the account page, we have to use it to get to the
243+ // Since we are already "on" the account page, we have to use it to get to the
244244// actual place where you configure unicorns. Calling the "Add Unicorn" method
245245// takes us there.
246246AddUnicornPage addUnicornPage = accountPage.addUnicorn();
@@ -322,12 +322,12 @@ unicornConfirmationPage = addUnicornPage.createUnicorn(sparkles)
322322 {{< / code-panel >}}
323323{{< / code-tab >}}
324324
325- Now that you've configured your unicorn,
325+ Now that you have configured your unicorn,
326326you need to move on to step 3: making sure it actually worked.
327327
328328{{< code-tab >}}
329329 {{< code-panel language="java" >}}
330- // The exists() method from UnicornConfirmationPage will take the Sparkles
330+ // The exists() method from UnicornConfirmationPage will take the Sparkles
331331// object--a specification of the attributes you want to see, and compare
332332// them with the fields on the page.
333333Assert.assertTrue("Sparkles should have been created, with all attributes intact", unicornConfirmationPage.exists(sparkles));
@@ -371,7 +371,7 @@ and decides to re-implement the entire site
371371in the latest Haskell bindings with a Fortran front-end.
372372
373373Your page objects will require some small maintenance in order to
374- to conform to the site redesign,
374+ conform to the site redesign,
375375but these tests will remain the same.
376376Taking this basic design,
377377you will want to keep going through your workflows with the fewest browser-facing steps possible.
@@ -390,6 +390,7 @@ and pre-configure a unicorn via the API or database.
390390Then all you have to do is log in as the user, locate Sparkles,
391391and add her to the cart.
392392
393+ 393394### To automate or not to automate?
394395
395396Is automation always advantageous? When should one decide to automate test
0 commit comments