-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathalerts_spec.rb
50 lines (35 loc) · 1003 Bytes
/
alerts_spec.rb
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
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Alerts' do
let(:driver) { start_session }
before do
driver.navigate.to 'https://selenium.dev'
end
it 'interacts with an alert' do
driver.execute_script 'alert("Hello, World!")'
# Store the alert reference in a variable
alert = driver.switch_to.alert
# Get the text of the alert
alert.text
# Press on Cancel button
alert.dismiss
end
it 'interacts with a confirm' do
driver.execute_script 'confirm("Are you sure?")'
# Store the alert reference in a variable
alert = driver.switch_to.alert
# Get the text of the alert
alert.text
# Press on Cancel button
alert.dismiss
end
it 'interacts with a prompt' do
driver.execute_script 'prompt("What is your name?")'
# Store the alert reference in a variable
alert = driver.switch_to.alert
# Type a message
alert.send_keys('selenium')
# Press on Ok button
alert.accept
end
end