Skip to content

Commit 326c64a

Browse files
committed
Enhance App SDK support for additional testing frameworks
1 parent feb301d commit 326c64a

File tree

5 files changed

+27
-100
lines changed

5 files changed

+27
-100
lines changed

src/tools/appautomate-utils/appium-sdk/config-generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export function generateAppBrowserStackYMLInstructions(
1515
): string {
1616
if (
1717
testingFramework === AppSDKSupportedTestingFrameworkEnum.nightwatch ||
18-
testingFramework === AppSDKSupportedTestingFrameworkEnum.webdriverio
18+
testingFramework === AppSDKSupportedTestingFrameworkEnum.webdriverio ||
19+
testingFramework === AppSDKSupportedTestingFrameworkEnum.cucumberRuby
1920
) {
2021
return "";
2122
}

src/tools/appautomate-utils/appium-sdk/instructions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function getAppInstructionsForProjectConfiguration(
3434
case "python":
3535
return getPythonAppInstructions(testingFramework);
3636
case "ruby":
37-
return getRubyAppInstructions(testingFramework);
37+
return getRubyAppInstructions();
3838
case "csharp":
3939
return getCSharpAppInstructions();
4040
default:

src/tools/appautomate-utils/appium-sdk/languages/nodejs.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ exports.config = {
145145
}
146146

147147
function getNightwatchCommand(username: string, accessKey: string): string {
148-
const prerequisiteStep = createStep(
148+
const prerequisiteStep = createStep(
149149
"Prerequisite Setup:",
150150
` a. Ensure you do not modify or replace any existing local driver code,
151151
as it will be automatically managed and overwritten by the BrowserStack SDK/Driver.
@@ -155,15 +155,15 @@ function getNightwatchCommand(username: string, accessKey: string): string {
155155

156156
const envStep = createStep(
157157
"Set your BrowserStack credentials as environment variables:",
158-
`\`\`\`bash
158+
`\`\`\`bash
159159
export BROWSERSTACK_USERNAME=${username}
160160
export BROWSERSTACK_ACCESS_KEY=${accessKey}
161161
\`\`\``,
162162
);
163163

164164
const installStep = createStep(
165165
"Install Nightwatch and BrowserStack integration:",
166-
`\`\`\`bash
166+
`\`\`\`bash
167167
npm install --save-dev @nightwatch/browserstack
168168
\`\`\``,
169169
);
@@ -232,7 +232,12 @@ npm install --save-dev @nightwatch/browserstack
232232
\`\`\``,
233233
);
234234

235-
return combineInstructions(prerequisiteStep, envStep, installStep, configStep);
235+
return combineInstructions(
236+
prerequisiteStep,
237+
envStep,
238+
installStep,
239+
configStep,
240+
);
236241
}
237242

238243
function getJestCommand(username: string, accessKey: string): string {

src/tools/appautomate-utils/appium-sdk/languages/ruby.ts

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
11
// Ruby instructions and commands for App SDK utilities
22
import {
3-
AppSDKSupportedTestingFramework,
4-
AppSDKSupportedTestingFrameworkEnum,
53
createStep,
64
combineInstructions,
75
createEnvStep,
86
PLATFORM_UTILS,
97
} from "../index.js";
108

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}";
2111

22-
return "";
23-
}
24-
25-
function getCucumberRubyInstructions(): string {
12+
export function getRubyAppInstructions(): string {
2613
const configStep = createStep(
2714
"Create/Update the config file (config.yml) as follows:",
2815
`\`\`\`yaml
2916
server: "hub-cloud.browserstack.com"
3017
3118
common_caps:
19+
"browserstack.user": "${username}"
20+
"browserstack.key": "${accessKey}"
3221
"project": "First Cucumber Android Project"
3322
"build": "Cucumber Android"
3423
"browserstack.debug": true
3524
3625
browser_caps:
3726
-
38-
"device": "Google Pixel 3"
27+
"deviceName": "Google Pixel 3"
3928
"os_version": "9.0"
4029
"app": "bs://<app-id>"
4130
"name": "first_test"
@@ -50,12 +39,14 @@ require 'appium_lib'
5039
5140
# Load configuration from config.yml
5241
caps = Appium.load_appium_txt file: File.expand_path('./../config.yml', __FILE__)
42+
username = "${username}"
43+
password = "${accessKey}"
5344
5445
# Create desired capabilities
5546
desired_caps = {
5647
caps: caps,
5748
appium_lib: {
58-
server_url: "https://hub-cloud.browserstack.com/wd/hub"
49+
server_url = "https://#{username}:#{password}@#{caps['server']}/wd/hub"
5950
}
6051
}
6152
@@ -85,81 +76,14 @@ bundle exec cucumber
8576
return combineInstructions(configStep, envStep, runStep);
8677
}
8778

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-
15579
export function getRubySDKCommand(
15680
framework: string,
15781
username: string,
15882
accessKey: string,
15983
): string {
16084
const { isWindows, getPlatformLabel } = PLATFORM_UTILS;
16185

162-
if (framework === "rspec" || framework === "cucumberRuby") {
86+
if (framework === "cucumberRuby") {
16387
const envStep = createEnvStep(
16488
username,
16589
accessKey,
@@ -177,11 +101,8 @@ gem install bundler
177101
# Install Appium Ruby client library
178102
gem install appium_lib
179103
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
185106
\`\`\``,
186107
);
187108

@@ -192,8 +113,7 @@ ${framework === "rspec" ? "gem install rspec" : ""}
192113
source 'https://rubygems.org'
193114
194115
gem 'appium_lib'
195-
${framework === "cucumberRuby" ? "gem 'cucumber'" : ""}
196-
${framework === "rspec" ? "gem 'rspec'" : ""}
116+
gem 'cucumber'
197117
\`\`\`
198118
199119
Then run:

src/tools/appautomate-utils/appium-sdk/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export async function getAppUploadInstruction(
4848
detectedTestingFramework: AppSDKSupportedTestingFramework,
4949
): Promise<string> {
5050
if (
51-
detectedTestingFramework === AppSDKSupportedTestingFrameworkEnum.nightwatch ||
51+
detectedTestingFramework ===
52+
AppSDKSupportedTestingFrameworkEnum.nightwatch ||
5253
detectedTestingFramework === AppSDKSupportedTestingFrameworkEnum.webdriverio
5354
) {
5455
const app_url = "bs://ff4e358328a3e914fe4f0e46ec7af73f9c08cd55";

0 commit comments

Comments
 (0)