/
native.rb
110 lines (91 loc) · 4.42 KB
/
native.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'perfecto-reporting'
require 'appium_lib'
desired_caps = {
# 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
appium_lib: {
server_url: 'https://%s.perfectomobile.com/nexperience/perfectomobile/wd/hub' % "<<cloud name>>",
},
caps: {
# 2. Replace <<security token>> with your perfecto security token.
securityToken: '<<security token>>',
# 3. Set device capabilities.
platformName: 'Android',
model: 'Galaxy S.*|LG.*',
# 4. Set Perfecto Media repository path of App under test.
app: 'PUBLIC:ExpenseTracker/Native/android/ExpenseAppVer1.0.apk',
# 5. Set the unique identifier of your app
appPackage: 'io.perfecto.expense.tracker',
# Set other capabilities.
enableAppiumBehavior: true, # Enable new architecture of Appium
autoLaunch: true, # Whether to have Appium install and launch the app automatically.
# fullReset: false, # Reset app state by uninstalling app
takesScreenshot: false,
screenshotOnError: true,
openDeviceTimeout: 5
}
}
# Initialize the Appium driver
@driver = Appium::Driver.new(desired_caps, true).start_driver
# Setting implicit wait
@driver.manage.timeouts.implicit_wait = 5
# Initialize Smart Reporting
if ENV["jobName"] != nil
perfectoExecutionContext = PerfectoExecutionContext.new(PerfectoExecutionContext::PerfectoExecutionContextBuilder
.withWebDriver(@driver).withJob(Job.new(ENV["jobName"], ENV["jobNumber"].to_i)).build)
else
perfectoExecutionContext = PerfectoExecutionContext.new(PerfectoExecutionContext::PerfectoExecutionContextBuilder
.withWebDriver(@driver).build)
end
@reportiumClient = PerfectoReportiumClient.new(perfectoExecutionContext)
tec = TestContext::TestContextBuilder.build()
@reportiumClient.testStart("Native Ruby Android Sample", tec)
begin
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
@reportiumClient.stepStart('Enter email')
wait.until{ @driver.find_element(:id => 'login_email') }
@driver.find_element(:id => 'login_email').send_keys('test@perfecto.com')
@reportiumClient.stepEnd()
@reportiumClient.stepStart('Enter password')
wait.until{ @driver.find_element(:id => 'login_password').displayed? }
@driver.find_element(:id => 'login_password').send_keys('test123')
@reportiumClient.stepEnd()
@reportiumClient.stepStart('Click login')
@driver.hide_keyboard
wait.until{ @driver.find_element(:id => 'login_login_btn').displayed? }
@driver.find_element(:id => 'login_login_btn').click
@reportiumClient.stepEnd()
@reportiumClient.stepStart('Add expense')
wait.until{ @driver.find_element(:id => 'list_add_btn').displayed? }
@driver.find_element(:id => 'list_add_btn').click
@reportiumClient.stepEnd()
@reportiumClient.stepStart('Select head')
wait.until{ @driver.find_element(:id => 'input_layout_head').displayed? }
@driver.find_element(:id => 'input_layout_head').click
wait.until{ @driver.find_element(:xpath => "//*[@text='Flight']").displayed? }
@driver.find_element(:xpath => "//*[@text='Flight']").click
@reportiumClient.stepEnd()
@reportiumClient.stepStart('Enter amount')
wait.until{ @driver.find_element(:id => 'add_amount').displayed? }
@driver.find_element(:id => 'add_amount').send_keys('100')
@reportiumClient.stepEnd()
@reportiumClient.stepStart('Save expense')
wait.until{ @driver.find_element(:id => 'add_save_btn').displayed? }
@driver.find_element(:id => 'layout_buttons').click
@reportiumClient.stepEnd()
@reportiumClient.stepStart("Verify alert");
expectedText = "Select Currency"
wait.until{ @driver.find_element(:xpath => "//*[@text='"+expectedText+"']").displayed? }
@reportiumClient.reportiumAssert(expectedText, @driver.find_element(:xpath => "//*[@text='"+expectedText+"']").text === expectedText)
@reportiumClient.stepEnd();
@reportiumClient.testStop(TestResultFactory.createSuccess(), tec)
rescue Exception => exception
@exception = exception
@reportiumClient.testStop(TestResultFactory.createFailure(@exception.exception.message, @exception.exception, nil), tec)
raise exception
ensure
# Prints the report url
puts 'Report url - ' + @reportiumClient.getReportUrl
#Quits the driver
@driver.quit
puts "Ruby Android Execution completed"
end