1
1
// Ruby instructions and commands for App SDK utilities
2
2
import {
3
- AppSDKSupportedTestingFramework ,
4
- AppSDKSupportedTestingFrameworkEnum ,
5
3
createStep ,
6
4
combineInstructions ,
7
5
createEnvStep ,
8
6
PLATFORM_UTILS ,
9
7
} from "../index.js" ;
10
8
11
- export function getRubyAppInstructions (
12
- testingFramework : AppSDKSupportedTestingFramework ,
13
- ) : string {
14
- if ( testingFramework === AppSDKSupportedTestingFrameworkEnum . cucumberRuby ) {
15
- return getCucumberRubyInstructions ( ) ;
16
- }
17
-
18
- if ( testingFramework === AppSDKSupportedTestingFrameworkEnum . rspec ) {
19
- return getRSpecInstructions ( ) ;
20
- }
9
+ const username = "${process.env.BROWSERSTACK_USERNAME}" ;
10
+ const accessKey = "${process.env.BROWSERSTACK_ACCESS_KEY}" ;
21
11
22
- return "" ;
23
- }
24
-
25
- function getCucumberRubyInstructions ( ) : string {
12
+ export function getRubyAppInstructions ( ) : string {
26
13
const configStep = createStep (
27
14
"Create/Update the config file (config.yml) as follows:" ,
28
15
`\`\`\`yaml
29
16
server: "hub-cloud.browserstack.com"
30
17
31
18
common_caps:
19
+ "browserstack.user": "${ username } "
20
+ "browserstack.key": "${ accessKey } "
32
21
"project": "First Cucumber Android Project"
33
22
"build": "Cucumber Android"
34
23
"browserstack.debug": true
35
24
36
25
browser_caps:
37
26
-
38
- "device ": "Google Pixel 3"
27
+ "deviceName ": "Google Pixel 3"
39
28
"os_version": "9.0"
40
29
"app": "bs://<app-id>"
41
30
"name": "first_test"
@@ -50,12 +39,14 @@ require 'appium_lib'
50
39
51
40
# Load configuration from config.yml
52
41
caps = Appium.load_appium_txt file: File.expand_path('./../config.yml', __FILE__)
42
+ username = "${ username } "
43
+ password = "${ accessKey } "
53
44
54
45
# Create desired capabilities
55
46
desired_caps = {
56
47
caps: caps,
57
48
appium_lib: {
58
- server_url: "https://hub-cloud.browserstack.com /wd/hub"
49
+ server_url = "https://#{username}:#{password}@#{caps['server']} /wd/hub"
59
50
}
60
51
}
61
52
@@ -85,81 +76,14 @@ bundle exec cucumber
85
76
return combineInstructions ( configStep , envStep , runStep ) ;
86
77
}
87
78
88
- function getRSpecInstructions ( ) : string {
89
- const specHelperStep = createStep (
90
- "Create/Update your spec_helper.rb file:" ,
91
- `\`\`\`ruby
92
- require 'rubygems'
93
- require 'appium_lib'
94
-
95
- RSpec.configure do |config|
96
- config.before(:all) do
97
- # Define desired capabilities
98
- desired_caps = {
99
- 'platformName' => 'Android',
100
- 'platformVersion' => '9.0',
101
- 'deviceName' => 'Google Pixel 3',
102
- 'app' => 'bs://<app-id>',
103
- 'project' => 'First RSpec Android Project',
104
- 'build' => 'RSpec Android',
105
- 'name' => 'first_test',
106
- 'browserstack.debug' => true
107
- }
108
-
109
- # Initialize Appium driver
110
- begin
111
- $appium_driver = Appium::Driver.new({
112
- caps: desired_caps,
113
- appium_lib: {
114
- server_url: "https://hub-cloud.browserstack.com/wd/hub"
115
- }
116
- }, true)
117
- $driver = $appium_driver.start_driver
118
- rescue Exception => e
119
- puts e.message
120
- Process.exit(0)
121
- end
122
- end
123
-
124
- config.after(:all) do
125
- $driver.quit if $driver
126
- end
127
- end
128
- \`\`\`` ,
129
- ) ;
130
-
131
- const testFileStep = createStep (
132
- "Create your test file (e.g., spec/app_spec.rb):" ,
133
- `\`\`\`ruby
134
- require 'spec_helper'
135
-
136
- describe 'App Test' do
137
- it 'should launch the app successfully' do
138
- # Your test code here
139
- expect($driver).not_to be_nil
140
- end
141
- end
142
- \`\`\`` ,
143
- ) ;
144
-
145
- const runStep = createStep (
146
- "Run the test:" ,
147
- `\`\`\`bash
148
- bundle exec rspec
149
- \`\`\`` ,
150
- ) ;
151
-
152
- return combineInstructions ( specHelperStep , testFileStep , runStep ) ;
153
- }
154
-
155
79
export function getRubySDKCommand (
156
80
framework : string ,
157
81
username : string ,
158
82
accessKey : string ,
159
83
) : string {
160
84
const { isWindows, getPlatformLabel } = PLATFORM_UTILS ;
161
85
162
- if ( framework === "rspec" || framework === " cucumberRuby") {
86
+ if ( framework === "cucumberRuby" ) {
163
87
const envStep = createEnvStep (
164
88
username ,
165
89
accessKey ,
@@ -177,11 +101,8 @@ gem install bundler
177
101
# Install Appium Ruby client library
178
102
gem install appium_lib
179
103
180
- # For Cucumber projects, also install cucumber
181
- ${ framework === "cucumberRuby" ? "gem install cucumber" : "" }
182
-
183
- # For RSpec projects, also install rspec
184
- ${ framework === "rspec" ? "gem install rspec" : "" }
104
+ # Install Cucumber
105
+ gem install cucumber
185
106
\`\`\`` ,
186
107
) ;
187
108
@@ -192,8 +113,7 @@ ${framework === "rspec" ? "gem install rspec" : ""}
192
113
source 'https://rubygems.org'
193
114
194
115
gem 'appium_lib'
195
- ${ framework === "cucumberRuby" ? "gem 'cucumber'" : "" }
196
- ${ framework === "rspec" ? "gem 'rspec'" : "" }
116
+ gem 'cucumber'
197
117
\`\`\`
198
118
199
119
Then run:
0 commit comments