Skip to content

Commit 4db4923

Browse files
rolyatwilsonBen Bolton
authored andcommitted
Appium setup modified to truncate developer_keys table
- Mobile verify expects developer_keys to have a specific index. This resets the sequence value to 101. - To test: run specs, query test database, and verify developer_key has sequence value of 101. Change-Id: If00c387edc67c3f00a1e1ee6043546a7d2cc1577 Reviewed-on: https://gerrit.instructure.com/60373 Tested-by: Jenkins Reviewed-by: Heath Hales <hhales@instructure.com> Reviewed-by: Steven Shepherd <sshepherd@instructure.com> Product-Review: Ben Bolton <bbolton@instructure.com> QA-Review: Ben Bolton <bbolton@instructure.com>
1 parent 3aeb8ba commit 4db4923

3 files changed

Lines changed: 94 additions & 47 deletions

File tree

spec/selenium/appium/environment_setup.rb

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ module EnvironmentSetup
44
# to change is the *redirect_uri* which contains the static IP address of the Canvas-lms
55
# environment, but do not change it; modify the *host_url* method instead.
66
def create_developer_key
7-
@key = DeveloperKey.create!(
8-
name: 'appium_developer_key',
9-
tool_id: '68413514',
10-
email: 'admin@instructure.com',
11-
redirect_uri: "http://#{host_url}",
12-
api_key: 'w33UkRtGDXIjQPm32of6qDi6CIAqfeQw4lFDu8CP8IXOkerc8Uw7c3ZNvp1tqBcE'
13-
) if @key.nil?
14-
@key
7+
if @appium_dev_key.nil?
8+
truncate_table(DeveloperKey) if @appium_dev_key.nil?
9+
@appium_dev_key = DeveloperKey.create!(
10+
name: 'appium_developer_key',
11+
tool_id: '68413514',
12+
email: 'admin@instructure.com',
13+
redirect_uri: "http://#{host_url}",
14+
api_key: 'w33UkRtGDXIjQPm32of6qDi6CIAqfeQw4lFDu8CP8IXOkerc8Uw7c3ZNvp1tqBcE'
15+
)
16+
end
17+
@appium_dev_key
1518
end
1619

1720
# Static IP addresses entered into Mobile Verify. Comment/Uncomment to set the url.
@@ -46,44 +49,42 @@ def android_device_name
4649
@device_name
4750
end
4851

49-
# Appium settings are device specific. To get device version, goto on device:
52+
# Appium settings are device specific. To get iOS device info:
5053
# Settings > General > Version
51-
def ios_version
52-
# @ios_version = '8.3'
53-
@ios_version = '8.4'
54-
@ios_version
55-
end
56-
57-
# Appium settings are device specific. To get the device name for connect iOS device run:
5854
# $ idevice_id -l ### lists connected devices by UDID
5955
# $ idevice_id [UDID] ### prints device name
60-
def ios_device_name
61-
# @device_name = 'QA iPhone 6'
62-
# @device_name = 'iPad'
63-
@device_name = 'Mobile User Testing 39'
64-
@device_name
65-
end
66-
67-
# Appium settings are device specific. To list connected iOS devices by UDID run:
68-
# idevice_id -l ### lists connected devices by UDID
69-
def ios_udid
70-
# @ios_udid = 'd227f9716519ddf8959f941074d712fc5d215672' # Device: QA iPhone 6
71-
# @ios_udid = 'b94ee387573a4a0a87c877becf36eb7224e0a80b' # Device: iPad
72-
@ios_udid = 'e192d707cd42f99c957bddc51e4fbe8aba43d9db' # Device: Mobile User Testing 39
73-
@ios_udid
74-
end
56+
# $ idevice_id -l ### lists connected devices by UDID
57+
def ios_device
58+
device = 'iPad' # <--- TODO: change this line to setup environment for ios device
59+
case device
60+
when 'QA iPhone 6'
61+
@ios_version = '8.3'
62+
@device_name = 'QA iPhone 6'
63+
@ios_udid = 'd227f9716519ddf8959f941074d712fc5d215672'
64+
@ios_type = 'iPhone'
65+
when 'iPad'
66+
@ios_version = '8.4'
67+
@device_name = 'iPad'
68+
@ios_udid = 'b94ee387573a4a0a87c877becf36eb7224e0a80b'
69+
@ios_type = 'iPad'
70+
when 'Mobile User Testing 39'
71+
@ios_version = '8.4'
72+
@device_name = 'Mobile User Testing 39'
73+
@ios_udid = 'e192d707cd42f99c957bddc51e4fbe8aba43d9db'
74+
@ios_type = 'iPad'
75+
else
76+
raise('Unsupported ios device.')
77+
end
7578

76-
# Appium is not yet integrated with Jenkins, so the only way to specify the app path for iOS
77-
# is to compile it locally with XCode, and update this method with the absolute path to the icanvas.app
78-
# file in your DerivedData folder. Make sure you choose the right subfolder (iphoneos for real devices).
79-
def ios_app_path
79+
# Appium is not yet integrated with Jenkins, so the only way to specify the app path for iOS
80+
# is to compile it locally with XCode, and update this method with the absolute path to the icanvas.app
81+
# file in your DerivedData folder. Make sure you choose the right subfolder (iphoneos for real devices).
8082
@ios_app_path = '/Users/twilson/Library/Developer/Xcode/DerivedData/iCanvas-fkfdbqxlcxqugldosdstapazsjaz/Build/Products/Debug-iphoneos/iCanvas.app'
81-
# @ios_app_path = '/Users/twilson/Library/Developer/Xcode/DerivedData/iCanvas-fkfdbqxlcxqugldosdstapazsjaz/Build/Products/Debug-iphonesimulator/iCanvas.app'
82-
@ios_app_path
83+
{ versionNumber: @ios_version, deviceName: @device_name, udid: @ios_udid, app: @ios_app_path }
8384
end
8485

8586
def implicit_wait_time
8687
@implicit_wait_time = 3
8788
@implicit_wait_time
8889
end
89-
end
90+
end

spec/selenium/appium/mobile_common.rb

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,54 @@
44

55
include EnvironmentSetup
66

7+
shared_context 'appium mobile specs' do |platform_name|
8+
before(:all) do
9+
# specs are unable to start mobile app from any page, so if a spec fails
10+
# running any following specs is unsafe and will most like fail as well
11+
RSpec.configure do |c|
12+
c.fail_fast = true
13+
end
14+
create_developer_key
15+
@platform_name = platform_name # TODO: remove variable Jenkins doesn't like unused block arguments
16+
# appium_init(platform_name) # TODO: uncomment to run Appium tests
17+
skip('Appium not yet integrated with Jenkins') # TODO: removed when Appium is integrated with Jenkins
18+
end
19+
end
20+
21+
shared_context 'teacher and student users' do |platform_name|
22+
before(:all) do
23+
course(course_name: platform_name == 'Android' ? android_course_name : ios_course_name)
24+
@course.offer
25+
@teacher = user_with_pseudonym(username: 'teacher', unique_id: 'teacher', password: 'teacher', active_user: true)
26+
@student = user_with_pseudonym(username: 'student', unique_id: 'student', password: 'student', active_user: true)
27+
@course.enroll_user(@teacher, 'TeacherEnrollment').accept!
28+
@course.enroll_user(@student).accept!
29+
end
30+
end
31+
32+
shared_context 'student user' do |platform_name|
33+
before(:all) do
34+
course_with_student(
35+
course_name: platform_name == 'Android' ? android_course_name : ios_course_name,
36+
user: user_with_pseudonym(username: 'student', password: 'student', active_user: true),
37+
active_all: true
38+
)
39+
candroid_init(@user.primary_pseudonym.unique_id, @user.primary_pseudonym.unique_id, @course.name)
40+
end
41+
42+
after(:all) do
43+
logout(false)
44+
end
45+
end
46+
747
# ======================================================================================================================
848
# Appium
949
# ======================================================================================================================
1050

1151
def start_appium_driver
12-
Appium::Driver.new(caps: @capabilities, appium_lib: @appium_lib ).start_driver
52+
Appium::Driver.new(caps: @capabilities, appium_lib: @appium_lib).start_driver
1353
Appium.promote_appium_methods(RSpec::Core::ExampleGroup)
1454
set_wait(implicit_wait_time)
15-
16-
@width = window_size.width
17-
@height = window_size.height
18-
@orientation = @width < @height ? 'portrait' : 'landscape'
1955
end
2056

2157
def appium_init_android
@@ -26,12 +62,15 @@ def appium_init_android
2662
end
2763

2864
def appium_init_ios
65+
device = ios_device
2966
@capabilities = {
3067
platformName: 'iOS',
31-
versionNumber: ios_version,
32-
deviceName: ios_device_name,
33-
udid: ios_udid,
34-
app: ios_app_path
68+
versionNumber: device[:versionNumber],
69+
deviceName: device[:deviceName],
70+
udid: device[:udid],
71+
app: device[:app],
72+
autoAcceptAlerts: true,
73+
sendKeysStrategy: 'setValue'
3574
}
3675
end
3776

@@ -79,3 +118,7 @@ def scroll_vertically_in_view(scroll_view, time, direction)
79118
action = Appium::TouchAction.new.press(x: x, y: start_y).wait(time).move_to(x: x, y: end_y).release
80119
action.perform
81120
end
121+
122+
def refresh_view(view)
123+
scroll_vertically_in_view(view, 2, 'up')
124+
end

spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def truncate_table(model)
233233
begin
234234
old_proc = model.connection.raw_connection.set_notice_processor {}
235235
model.connection.execute("TRUNCATE TABLE #{model.connection.quote_table_name(model.table_name)} CASCADE")
236+
237+
# mobile verify expects specific id seq for developer key, this forces the sequence to always start at 101
238+
model.connection.execute("SELECT setval('developer_keys_id_seq', 100);") if model == DeveloperKey
236239
ensure
237240
model.connection.raw_connection.set_notice_processor(&old_proc)
238241
end

0 commit comments

Comments
 (0)