Skip to content

Commit 902f292

Browse files
feat: initial commit with Android test workflow
1 parent a586965 commit 902f292

File tree

8 files changed

+5967
-2
lines changed

8 files changed

+5967
-2
lines changed

.github/workflows/android-test.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Android Test
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 */2 * * *' # Runs every 2 hours (at minute 0)
7+
timezone: 'Asia/Kolkata'
8+
9+
env:
10+
LT_USERNAME: ${{ secrets.LT_USERNAME }}
11+
LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }}
12+
LT_APP_ID: ${{ secrets.LT_APP_ID }}
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '18'
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: |
29+
echo "Installing dependencies..."
30+
npm install --no-package-lock
31+
npm install file:packages/appium-navigation-tracker-1.0.0.tgz --no-package-lock
32+
echo "\nVerifying installations:"
33+
ls -la node_modules/wd || true
34+
ls -la node_modules/appium-navigation-tracker || true
35+
36+
- name: Configure LambdaTest credentials
37+
run: |
38+
echo "LT_USERNAME=${{ secrets.LT_USERNAME }}" >> $GITHUB_ENV
39+
echo "LT_ACCESS_KEY=${{ secrets.LT_ACCESS_KEY }}" >> $GITHUB_ENV
40+
echo "LT_APP_ID=${{ secrets.LT_APP_ID }}" >> $GITHUB_ENV
41+
42+
- name: Run Android Test
43+
id: test
44+
run: |
45+
echo "Running Android test..."
46+
node Android.js 2>&1 | tee android-test.log
47+
continue-on-error: true
48+
49+
- name: Debug - Show test logs
50+
if: failure()
51+
run: |
52+
echo "Android test log:"
53+
cat android-test.log || true
54+
55+
- name: Upload test results
56+
if: always()
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: test-results
60+
path: test-results/
61+
if-no-files-found: warn

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
25+
package-lock.json
26+
node_modules
27+
.DS_Store
28+
.idea/
29+
test-results/

Android.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
const { NavigationTracker } = require('appium-navigation-tracker');
2+
const wd = require("wd");
3+
4+
/**
5+
* Username to be used for running the test.
6+
*/
7+
const username = process.env.LT_USERNAME;
8+
9+
/**
10+
* The access key to be used for running test test.
11+
*/
12+
const accessKey = process.env.LT_ACCESS_KEY;
13+
14+
/**
15+
* App ID to be used for running the test.
16+
*/
17+
const appId = process.env.LT_APP_ID;
18+
19+
/**
20+
* Capabilities to be passed while running the test.
21+
*/
22+
const desiredCapabilities = {
23+
app: appId,
24+
build: "NodeJS - Android",
25+
name: "Sample Test NodeJS",
26+
deviceName: "Galaxy S20",
27+
isRealMobile: true,
28+
appiumVersion: "1.22.3",
29+
platformName: "android",
30+
platformVersion: "11",
31+
video: true,
32+
visual: true,
33+
};
34+
35+
const driver = wd.promiseRemote(
36+
`https://${username}:${accessKey}@mobile-hub.lambdatest.com/wd/hub`
37+
);
38+
39+
const DEFAULT_TIMEOUT = 10000;
40+
41+
/**
42+
* Run an android test.
43+
*/
44+
async function runAndroidTest() {
45+
try {
46+
console.log("Starting Android test...");
47+
console.log("Initializing driver with capabilities:", JSON.stringify(desiredCapabilities, null, 2));
48+
49+
// Initialize navigation tracker without API upload
50+
const navigationTracker = new NavigationTracker(driver, {
51+
enableApiUpload: false
52+
});
53+
54+
driver
55+
.init(desiredCapabilities)
56+
.then(async function () {
57+
console.log("Driver initialized successfully");
58+
// Start tracking navigation
59+
await navigationTracker.trackNavigation();
60+
return driver.waitForElementById("color", DEFAULT_TIMEOUT);
61+
})
62+
.then(async function (colorButton) {
63+
console.log("Found color button, clicking...");
64+
await navigationTracker.beforeClick("color");
65+
await colorButton.click();
66+
await navigationTracker.afterClick();
67+
return driver.waitForElementById("Text", DEFAULT_TIMEOUT);
68+
})
69+
.then(async function (text) {
70+
console.log("Found Text element, clicking...");
71+
await navigationTracker.beforeClick("Text");
72+
await text.click();
73+
await navigationTracker.afterClick();
74+
return driver.waitForElementById("toast", DEFAULT_TIMEOUT);
75+
})
76+
.then(async function (toast) {
77+
console.log("Found toast element, clicking...");
78+
await navigationTracker.beforeClick("toast");
79+
await toast.click();
80+
await navigationTracker.afterClick();
81+
return driver.waitForElementById("notification", DEFAULT_TIMEOUT);
82+
})
83+
.then(async function (notification) {
84+
console.log("Found notification element, clicking...");
85+
await navigationTracker.beforeClick("notification");
86+
await notification.click();
87+
await navigationTracker.afterClick();
88+
return driver.waitForElementById("geoLocation", DEFAULT_TIMEOUT);
89+
})
90+
.then(async function (geoLocation) {
91+
console.log("Found geoLocation element, clicking...");
92+
await navigationTracker.beforeClick("geoLocation");
93+
await geoLocation.click();
94+
await navigationTracker.afterClick();
95+
return driver.waitForElementById("buttonPage", DEFAULT_TIMEOUT);
96+
})
97+
.then(async function (Home) {
98+
console.log("Found Home button, clicking...");
99+
await navigationTracker.beforeClick("Home");
100+
await Home.click();
101+
await navigationTracker.afterClick();
102+
return driver.waitForElementById("speedTest", DEFAULT_TIMEOUT);
103+
})
104+
.then(async function (speedTest) {
105+
console.log("Found speedTest element, clicking...");
106+
await navigationTracker.beforeClick("speedTest");
107+
await speedTest.click();
108+
await navigationTracker.afterClick();
109+
return driver.waitForElementById("webview", DEFAULT_TIMEOUT);
110+
})
111+
.then(async function (Browser) {
112+
console.log("Found Browser element, clicking...");
113+
await navigationTracker.beforeClick("Browser");
114+
await Browser.click();
115+
await navigationTracker.afterClick();
116+
return driver.waitForElementById("url", DEFAULT_TIMEOUT);
117+
})
118+
.then(async function () {
119+
console.log("Waiting 5 seconds for webview to load...");
120+
await new Promise(resolve => setTimeout(resolve, 5000));
121+
return driver.waitForElementById("url", DEFAULT_TIMEOUT);
122+
})
123+
.then(async function (url) {
124+
console.log("Found URL input field, typing LambdaTest URL...");
125+
await navigationTracker.recordUserAction("url");
126+
await url.type("https://www.lambdatest.com");
127+
return driver.waitForElementById("find", DEFAULT_TIMEOUT);
128+
})
129+
.then(async function (find) {
130+
console.log("Found find button, clicking...");
131+
await navigationTracker.beforeClick("find");
132+
await find.click();
133+
await navigationTracker.afterClick();
134+
console.log("Test completed successfully");
135+
// Save navigation results locally
136+
await navigationTracker.saveResults();
137+
driver.quit();
138+
})
139+
.catch(async function(error) {
140+
console.error("Error during test execution:", error);
141+
console.error("Error stack:", error.stack);
142+
// Save navigation results even if there's an error
143+
await navigationTracker.saveResults();
144+
driver.quit();
145+
});
146+
} catch (e) {
147+
console.error("Android Test Failed with error:", e);
148+
console.error("Error stack:", e.stack);
149+
driver.quit();
150+
}
151+
}
152+
153+
runAndroidTest();

IOS.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
var wd = require("wd")
2+
var assert = require("assert");
3+
var asserter = wd.asserters;
4+
5+
username = (process.env.LT_USERNAME == undefined) ? "username" //Enter the username here
6+
: process.env.LT_USERNAME
7+
accesskey = (process.env.LT_ACCESS_KEY == undefined) ? "access_key" //Enter the access_key here
8+
: process.env.LT_ACCESS_KEY
9+
10+
desired_capabilities = {
11+
'deviceName': 'iPhone 12',
12+
'platformVersion': '14',
13+
'platformName': 'iOS',
14+
'isRealMobile': true,
15+
'appiumVersion': "1.22.3",
16+
'app': 'lt://proverbial-ios', //Enter the app_url here
17+
'visual': true,
18+
'video': true,
19+
'build': 'NodeJS Vanilla - iOS',
20+
'name': 'Sample Test - NodeJS'
21+
}
22+
23+
driver = wd.promiseRemote(`https://${username}:${accesskey}@mobile-hub.lambdatest.com/wd/hub`)
24+
25+
async function iOStest() {
26+
try {
27+
console.log("Starting iOS test...");
28+
console.log("Initializing driver with capabilities:", JSON.stringify(desired_capabilities, null, 2));
29+
30+
driver.init(desired_capabilities)
31+
.then(function () {
32+
console.log("Driver initialized successfully");
33+
return driver.waitForElementById('color', 10000)
34+
})
35+
.then(function (color) {
36+
console.log("Found color button, clicking...");
37+
return color.click();
38+
})
39+
.then(function () {
40+
console.log("Looking for Text element...");
41+
return driver.waitForElementById('Text', 10000)
42+
})
43+
.then(function (text) {
44+
console.log("Found Text element, clicking...");
45+
text.click()
46+
return driver.waitForElementById('toast', 10000)
47+
})
48+
.then(function (toast) {
49+
console.log("Found toast element, clicking...");
50+
toast.click()
51+
return driver.waitForElementById('notification', 10000)
52+
})
53+
.then(function (notification) {
54+
console.log("Found notification element, clicking...");
55+
notification.click()
56+
return driver.waitForElementById('geoLocation', 10000)
57+
})
58+
.then(function (geoLocation) {
59+
console.log("Found geoLocation element, clicking...");
60+
return geoLocation.click()
61+
})
62+
.then(async function () {
63+
console.log("Waiting 10 seconds after geolocation click...");
64+
await new Promise(resolve => setTimeout(resolve, 10000));
65+
console.log("Looking for Back button...");
66+
return driver.waitForElementById('Back', 10000)
67+
})
68+
.then(function (Back) {
69+
console.log("Found Back button, clicking...");
70+
Back.click()
71+
return driver.waitForElementById('speedTest', 10000)
72+
})
73+
.then(async function (speedTest) {
74+
console.log("Found speedTest element, clicking...");
75+
speedTest.click()
76+
return driver.waitForElementById('Back', 10000)
77+
})
78+
.then(function (back) {
79+
console.log("Found Back button, clicking...");
80+
back.click()
81+
return driver.waitForElementById('Browser', 10000)
82+
})
83+
.then(function (Browser) {
84+
console.log("Found Browser element, clicking...");
85+
Browser.click()
86+
return driver.waitForElementById('url', 10000)
87+
})
88+
.then(function (url) {
89+
console.log("Found url element, typing LambdaTest URL...");
90+
url.type("https://www.lambdatest.com")
91+
return driver.waitForElementById('find', 10000)
92+
})
93+
.then(function (find) {
94+
console.log("Found find element, clicking...");
95+
find.click()
96+
console.log("Test completed successfully");
97+
driver.quit()
98+
})
99+
.catch(function(error) {
100+
console.error("Error during test execution:", error);
101+
console.error("Error stack:", error.stack);
102+
driver.quit();
103+
});
104+
}
105+
catch (e) {
106+
console.error("iOS Test Failed with error:", e);
107+
console.error("Error stack:", e.stack);
108+
driver.quit()
109+
}
110+
}
111+
112+
iOStest();

0 commit comments

Comments
 (0)