Ubuntu下运行Appium的后续操作及Ionic1相关教程咨询
appium Command + Ionic1 Appium Tutorial Hey there! Let's walk through exactly what to do next now that you've got Appium and Appium Doctor set up, plus a tailored guide for testing your Ionic1 app—you're already halfway there!
First: What Happens When You Run appium?
When you execute the appium command in your terminal, you're starting the Appium server. You'll see output like this:
Appium REST http interface listener started on 0.0.0.0:4723
This means the server is listening on port 4723 for test scripts to connect to it. Leave this terminal window open—don't close it while running tests!
Step-by-Step Next Actions
1. Validate Your Environment (Quick Check)
Before diving in, double-check everything is configured correctly with Appium Doctor:
appium-doctor
Fix any red flags it throws (like missing ANDROID_HOME for Android, or Xcode command-line tools for iOS).
2. Prep Your Ionic1 App for Testing
You need a deployable version of your Ionic1 app (for emulator or real device):
- Android: Run this in your Ionic1 project folder to build a debug APK:
The APK will be located ationic cordova build androidplatforms/android/app/build/outputs/apk/debug/app-debug.apk - iOS: Build the app and open it in Xcode:
Openionic cordova build iosplatforms/ios/YourAppName.xcworkspacein Xcode, then compile it to a simulator or real device (you'll need a developer account for real devices).
3. Set Up a Test Project & Dependencies
We'll use WebdriverIO (a popular Appium client for JavaScript) since it's straightforward for Ionic apps.
- Create a new folder for your tests:
mkdir ionic1-appium-tests && cd ionic1-appium-tests npm init -y - Install required packages:
npm install webdriverio @wdio/cli @wdio/local-runner @wdio/mocha-framework @wdio/spec-reporter
4. Configure WebdriverIO (WDIO)
Generate a config file by running:
npx wdio config
Follow the prompts:
- Choose Mocha as your test framework
- Pick Spec as your reporter (simple, readable output)
- Select Appium as your service
Now open wdio.conf.js and update the capabilities section to match your device and app path. Here are examples:
Android Capabilities Example
capabilities: [{ platformName: 'Android', 'appium:deviceName': 'Pixel_3a_API_33', // Use your emulator/device name (check with `adb devices`) 'appium:automationName': 'UiAutomator2', 'appium:app': '/full/path/to/your/ionic1-app/platforms/android/app/build/outputs/apk/debug/app-debug.apk', 'appium:noReset': true, // Optional: Prevents resetting the app between tests }],
iOS Capabilities Example
capabilities: [{ platformName: 'iOS', 'appium:deviceName': 'iPhone 14', // Use your simulator/device name 'appium:automationName': 'XCUITest', 'appium:app': '/full/path/to/your/ionic1-app/platforms/ios/build/debug-iphonesimulator/YourAppName.app', 'appium:noReset': true, }],
5. Write Your First Ionic1 Test
Create a file at test/specs/app.test.js with this sample test (adjust selectors to match your app):
describe('Ionic1 App Basic Tests', () => { it('loads the home page and verifies the title', async () => { // Wait for the main content to load (Ionic1 uses ion-content) await $('ion-content').waitForDisplayed({ timeout: 10000 }); // Grab the page title (adjust selector to match your app's title element) const pageTitle = await $('ion-title').getText(); console.log('Home page title:', pageTitle); // Assert the title is correct expect(pageTitle).toBe('My Awesome Ionic1 App'); }); it('navigates to a second page when a button is tapped', async () => { // Find and tap a navigation button (use your button's ID or class) const navButton = await $('#nav-to-second-page'); await navButton.click(); // Wait for the second page to load await $('ion-page[aria-label="Second Page"]').waitForDisplayed(); // Verify the second page's title const secondPageTitle = await $('ion-title').getText(); expect(secondPageTitle).toBe('Second Page'); }); });
6. Run Your Tests
- Make sure the Appium server is still running in its terminal window (the one where you ran
appium). - In your test project's terminal, run:
npx wdio run wdio.conf.js
You'll see your emulator/real device launch your Ionic1 app, automatically run the test steps, and the terminal will output whether the tests passed or failed.
Ionic1-Specific Tips
- Element Selection: Use Chrome DevTools (for Android) or Safari Web Inspector (for iOS) to inspect your app's elements. Ionic1 adds classes like
ion-button,ion-list, andion-cardthat you can use as selectors. - WebView Handling: If your app uses WebViews (common in Ionic), switch contexts to interact with web content:
// Get all available contexts const contexts = await driver.getContexts(); // Switch to the WebView context (replace with your app's package ID) await driver.switchContext('WEBVIEW_com.your.app.id'); - Slow Load Times: Ionic1 apps can take a few seconds to load, so use
waitForDisplayed()with a reasonable timeout (10-15 seconds) instead of hardcoding delays.
内容的提问来源于stack exchange,提问作者Nidhin Kumar

