Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 18, 2017 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/48bc48252be3f1c11d08d3e7cf321aa2 to your computer and use it in GitHub Desktop.
Save shankardevy/48bc48252be3f1c11d08d3e7cf321aa2 to your computer and use it in GitHub Desktop.
Acceptance Test for Mango Homepage
defmodule MangoWeb.Acceptance.HomepageTest do
use ExUnit.Case
use Hound.Helpers
hound_session()
test "presence of seasonal products" do
## GIVEN ##
# There are two products Apple and Tomato price 100 and 50 respectively
# Where Apple being the only seasonal product
## WHEN ##
# I navigate to homepage
navigate_to("/")
## THEN ##
# I expect the page title to be "Seasonal products"
page_title = find_element(:css, ".page-title") |> visible_text()
assert page_title == "Seasonal Products"
# And I expect Apple in the product displayed
product = find_element(:css, ".product")
product_name = find_within_element(product, :css, ".product-name") |> visible_text()
product_price = find_within_element(product, :css, ".product-price") |> visible_text()
assert product_name == "Apple"
# And I expect its price to be displayed on screen
assert product_price == "100"
# And I expect that Tomato is not present on screen.
refute page_source() =~ "Tomato"
end
end
@ocwang
Copy link

ocwang commented Jul 20, 2017

I had to add |> visible_test() at the end of both line 23 and 24 or my tests would fail as below:

screen shot 2017-07-19 at 5 06 32 pm

To fix change lines 23 and 24 to the following:

product_name = find_within_element(product, :css, ".product-name") |> visible_test()
product_price = find_within_element(product, :css, ".product-price") |> visible_test()

@e0
Copy link

e0 commented Jul 28, 2017

@ocwang Good catch, but to further clarify, it should be visible_text() instead of visible_test().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment