Skip to content

Instantly share code, notes, and snippets.

@shankardevy

shankardevy/homepage_test.exs Secret

Last active Aug 18, 2017
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@ocwang 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

This comment has been minimized.

Copy link

@e0 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