This repository has been archived by the owner on Mar 23, 2020. It is now read-only.
/
android_on_sauce.rb
70 lines (61 loc) · 1.84 KB
/
android_on_sauce.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# This example automates a test of the Android example notepad app.
#
# To run this example, make sure you've run:
# $ bundle install
#
# And set the environment variables:
# SAUCE_USERNAME = your-sauce-username
# SAUCE_ACCESS_KEY = your-sauce-key
#
# Then just:
# bundle exec ruby android_on_sauce.rb
#
# Of note compared to the iOS example, here we're giving the package and
# activity, no OS and an empty browserName
#
# Of note compared to the non-sauce examples, you need to host your app
# somewhere Sauce Labs' cloud can fetch it for your test.
require 'rubygems'
require 'spec'
require 'appium_lib'
require 'sauce_whisk'
describe 'Notepad' do
def desired_caps
{
caps: {
:'appium-version' => '1.3.4',
platformName: 'Android',
platformVersion: '4.3',
deviceName: 'Android Emulator',
app: 'http://appium.s3.amazonaws.com/NotesList.apk',
name: 'Ruby Appium Android example'
},
appium_lib: {
wait: 60
}
}
end
before do
Appium::Driver.new(desired_caps).start_driver
end
after do
driver_quit
end
it 'can create and save new notes' do
find('New note').click
first_textfield.type 'This is a new note, from Ruby'
find('Save').click
note_count = ids('android:id/text1').length
note_count.must_equal 1
texts.last.text.must_equal 'This is a new note, from Ruby'
end
end
passed = Minitest.run_specs({ :trace => [__FILE__] }).first
# Because WebDriver doesn't have the concept of test failure, use the Sauce
# Labs REST API to record job success or failure
user = ENV['SAUCE_USERNAME']
key = ENV['SAUCE_ACCESS_KEY']
if user && !user.empty? && key && !key.empty?
passed = passed.failures == 0 && passed.errors == 0
SauceWhisk::Jobs.change_status $driver.driver.session_id, passed
end