-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathmultiple_browser_session_test.exs
84 lines (65 loc) · 2.19 KB
/
multiple_browser_session_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
defmodule MultipleBrowserSessionTest do
use ExUnit.Case
use Hound.Helpers
hound_session()
test "should be able to run multiple sessions" do
url1 = "http://localhost:9090/page1.html"
url2 = "http://localhost:9090/page2.html"
# Navigate to a url
navigate_to(url1)
# Change to another session
change_session_to :another_session
# Navigate to a url in the second session
navigate_to(url2)
# Then assert url
assert url2 == current_url()
# Now go back to the default session
change_to_default_session()
# Assert if the url is the one we visited
assert url1 == current_url()
end
test "should be able to run multiple sessions using in_browser_session" do
url1 = "http://localhost:9090/page1.html"
url2 = "http://localhost:9090/page2.html"
# Navigate to a url
navigate_to(url1)
# In another session...
in_browser_session :another_session, fn->
navigate_to(url2)
assert url2 == current_url()
end
# Assert if the url is the one we visited
assert url1 == current_url()
end
test "should preserve session after using in_browser_session" do
url1 = "http://localhost:9090/page1.html"
url2 = "http://localhost:9090/page2.html"
url3 = "http://localhost:9090/page3.html"
# Navigate to url1 in default session
navigate_to(url1)
# Change to a second session and navigate to url2
change_session_to :session_a
navigate_to(url2)
# In a third session...
in_browser_session :session_b, fn ->
navigate_to(url3)
assert url3 == current_url()
end
# Assert the current url is the url we visited in :session_a
assert url2 == current_url()
# Switch back to the default session
change_session_to :default
# Assert the current url is the one we visited in the default session
assert url1 == current_url()
end
test "in_browser_session should return the result of the given function" do
url1 = "http://localhost:9090/page1.html"
# In another session, navigate to url1 and return the current url
result =
in_browser_session :another_session, fn ->
navigate_to(url1)
current_url()
end
assert result == url1
end
end