Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/android-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Android Test

on:
workflow_dispatch:
inputs:
runner:
description: 'Runner to use'
required: true
default: 'ubuntu-ltqa'
type: choice
options:
- ubuntu-ltqa
- ubuntu
- ubuntu-latest
schedule:
- cron: '0 */2 * * *' # Runs every 2 hours (at minute 0)
timezone: 'Asia/Kolkata'

env:
LT_USERNAME: ${{ secrets.LT_USERNAME }}
LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }}
LT_APP_ID: ${{ secrets.LT_APP_ID }}

jobs:
test:
runs-on: ${{ github.event.inputs.runner || 'ubuntu-ltqa' }}

steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: |
echo "Installing dependencies..."
npm install --no-package-lock
npm install file:packages/appium-navigation-tracker-1.0.0.tgz --no-package-lock
echo "\nVerifying installations:"
ls -la node_modules/wd || true
ls -la node_modules/appium-navigation-tracker || true

- name: Configure LambdaTest credentials
run: |
echo "LT_USERNAME=${{ secrets.LT_USERNAME }}" >> $GITHUB_ENV
echo "LT_ACCESS_KEY=${{ secrets.LT_ACCESS_KEY }}" >> $GITHUB_ENV
echo "LT_APP_ID=${{ secrets.LT_APP_ID }}" >> $GITHUB_ENV

- name: Run Android Test
id: test
run: |
echo "Running Android test..."
node Android.js 2>&1 | tee android-test.log
continue-on-error: true

- name: Debug - Show test logs
if: failure()
run: |
echo "Android test log:"
cat android-test.log || true

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: test-results/
if-no-files-found: warn
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

node_modules
.DS_Store
.idea/
test-results/
153 changes: 153 additions & 0 deletions Android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
const { NavigationTracker } = require('appium-navigation-tracker');
const wd = require("wd");

/**
* Username to be used for running the test.
*/
const username = process.env.LT_USERNAME;

/**
* The access key to be used for running test test.
*/
const accessKey = process.env.LT_ACCESS_KEY;

/**
* App ID to be used for running the test.
*/
const appId = process.env.LT_APP_ID;

/**
* Capabilities to be passed while running the test.
*/
const desiredCapabilities = {
app: appId,
build: "NodeJS - Android",
name: "Sample Test NodeJS",
deviceName: "Galaxy S20",
isRealMobile: true,
appiumVersion: "1.22.3",
platformName: "android",
platformVersion: "11",
video: true,
visual: true,
};

const driver = wd.promiseRemote(
`https://${username}:${accessKey}@mobile-hub.lambdatest.com/wd/hub`
);

const DEFAULT_TIMEOUT = 10000;

/**
* Run an android test.
*/
async function runAndroidTest() {
try {
console.log("Starting Android test...");
console.log("Initializing driver with capabilities:", JSON.stringify(desiredCapabilities, null, 2));

// Initialize navigation tracker without API upload
const navigationTracker = new NavigationTracker(driver, {
enableApiUpload: false
});

driver
.init(desiredCapabilities)
.then(async function () {
console.log("Driver initialized successfully");
// Start tracking navigation
await navigationTracker.trackNavigation();
return driver.waitForElementById("color", DEFAULT_TIMEOUT);
})
.then(async function (colorButton) {
console.log("Found color button, clicking...");
await navigationTracker.beforeClick("color");
await colorButton.click();
await navigationTracker.afterClick();
return driver.waitForElementById("Text", DEFAULT_TIMEOUT);
})
.then(async function (text) {
console.log("Found Text element, clicking...");
await navigationTracker.beforeClick("Text");
await text.click();
await navigationTracker.afterClick();
return driver.waitForElementById("toast", DEFAULT_TIMEOUT);
})
.then(async function (toast) {
console.log("Found toast element, clicking...");
await navigationTracker.beforeClick("toast");
await toast.click();
await navigationTracker.afterClick();
return driver.waitForElementById("notification", DEFAULT_TIMEOUT);
})
.then(async function (notification) {
console.log("Found notification element, clicking...");
await navigationTracker.beforeClick("notification");
await notification.click();
await navigationTracker.afterClick();
return driver.waitForElementById("geoLocation", DEFAULT_TIMEOUT);
})
.then(async function (geoLocation) {
console.log("Found geoLocation element, clicking...");
await navigationTracker.beforeClick("geoLocation");
await geoLocation.click();
await navigationTracker.afterClick();
return driver.waitForElementById("buttonPage", DEFAULT_TIMEOUT);
})
.then(async function (Home) {
console.log("Found Home button, clicking...");
await navigationTracker.beforeClick("Home");
await Home.click();
await navigationTracker.afterClick();
return driver.waitForElementById("speedTest", DEFAULT_TIMEOUT);
})
.then(async function (speedTest) {
console.log("Found speedTest element, clicking...");
await navigationTracker.beforeClick("speedTest");
await speedTest.click();
await navigationTracker.afterClick();
return driver.waitForElementById("webview", DEFAULT_TIMEOUT);
})
.then(async function (Browser) {
console.log("Found Browser element, clicking...");
await navigationTracker.beforeClick("Browser");
await Browser.click();
await navigationTracker.afterClick();
return driver.waitForElementById("url", DEFAULT_TIMEOUT);
})
.then(async function () {
console.log("Waiting 5 seconds for webview to load...");
await new Promise(resolve => setTimeout(resolve, 5000));
return driver.waitForElementById("url", DEFAULT_TIMEOUT);
})
.then(async function (url) {
console.log("Found URL input field, typing LambdaTest URL...");
await navigationTracker.recordUserAction("url");
await url.type("https://www.lambdatest.com");
return driver.waitForElementById("find", DEFAULT_TIMEOUT);
})
.then(async function (find) {
console.log("Found find button, clicking...");
await navigationTracker.beforeClick("find");
await find.click();
await navigationTracker.afterClick();
console.log("Test completed successfully");
// Save navigation results locally
await navigationTracker.saveResults();
driver.quit();
})
.catch(async function(error) {
console.error("Error during test execution:", error);
console.error("Error stack:", error.stack);
// Save navigation results even if there's an error
await navigationTracker.saveResults();
driver.quit();
});
} catch (e) {
console.error("Android Test Failed with error:", e);
console.error("Error stack:", e.stack);
driver.quit();
}
}

runAndroidTest();
112 changes: 112 additions & 0 deletions IOS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
var wd = require("wd")
var assert = require("assert");
var asserter = wd.asserters;

username = (process.env.LT_USERNAME == undefined) ? "username" //Enter the username here
: process.env.LT_USERNAME
accesskey = (process.env.LT_ACCESS_KEY == undefined) ? "access_key" //Enter the access_key here
: process.env.LT_ACCESS_KEY

desired_capabilities = {
'deviceName': 'iPhone 12',
'platformVersion': '14',
'platformName': 'iOS',
'isRealMobile': true,
'appiumVersion': "1.22.3",
'app': 'lt://proverbial-ios', //Enter the app_url here
'visual': true,
'video': true,
'build': 'NodeJS Vanilla - iOS',
'name': 'Sample Test - NodeJS'
}

driver = wd.promiseRemote(`https://${username}:${accesskey}@mobile-hub.lambdatest.com/wd/hub`)

async function iOStest() {
try {
console.log("Starting iOS test...");
console.log("Initializing driver with capabilities:", JSON.stringify(desired_capabilities, null, 2));

driver.init(desired_capabilities)
.then(function () {
console.log("Driver initialized successfully");
return driver.waitForElementById('color', 10000)
})
.then(function (color) {
console.log("Found color button, clicking...");
return color.click();
})
.then(function () {
console.log("Looking for Text element...");
return driver.waitForElementById('Text', 10000)
})
.then(function (text) {
console.log("Found Text element, clicking...");
text.click()
return driver.waitForElementById('toast', 10000)
})
.then(function (toast) {
console.log("Found toast element, clicking...");
toast.click()
return driver.waitForElementById('notification', 10000)
})
.then(function (notification) {
console.log("Found notification element, clicking...");
notification.click()
return driver.waitForElementById('geoLocation', 10000)
})
.then(function (geoLocation) {
console.log("Found geoLocation element, clicking...");
return geoLocation.click()
})
.then(async function () {
console.log("Waiting 10 seconds after geolocation click...");
await new Promise(resolve => setTimeout(resolve, 10000));
console.log("Looking for Back button...");
return driver.waitForElementById('Back', 10000)
})
.then(function (Back) {
console.log("Found Back button, clicking...");
Back.click()
return driver.waitForElementById('speedTest', 10000)
})
.then(async function (speedTest) {
console.log("Found speedTest element, clicking...");
speedTest.click()
return driver.waitForElementById('Back', 10000)
})
.then(function (back) {
console.log("Found Back button, clicking...");
back.click()
return driver.waitForElementById('Browser', 10000)
})
.then(function (Browser) {
console.log("Found Browser element, clicking...");
Browser.click()
return driver.waitForElementById('url', 10000)
})
.then(function (url) {
console.log("Found url element, typing LambdaTest URL...");
url.type("https://www.lambdatest.com")
return driver.waitForElementById('find', 10000)
})
.then(function (find) {
console.log("Found find element, clicking...");
find.click()
console.log("Test completed successfully");
driver.quit()
})
.catch(function(error) {
console.error("Error during test execution:", error);
console.error("Error stack:", error.stack);
driver.quit();
});
}
catch (e) {
console.error("iOS Test Failed with error:", e);
console.error("Error stack:", e.stack);
driver.quit()
}
}

iOStest();
Loading