运行Appium测试用例时遇SessionNotCreatedException异常求助
Hey there! Let's work through this SessionNotCreatedException you're hitting with your first Appium test. I’ve dealt with similar issues when starting out, so here are actionable steps to fix this:
1. Fix Version Compatibility Gaps
The versions you’re using might have subtle compatibility issues:
- Appium 1.6.3 is a bit dated, and the Java Client 5.0.0-BETA7 (a pre-release version) might not play nicely with it alongside Selenium 3.4.0.
- Try switching to the stable Java Client 4.1.2 — it’s proven to work well with Appium 1.6.3 and Selenium 3.4.0.
- Alternatively, upgrade Appium to a more recent stable release (like 1.7.x or later) that has better support for Selenium 3.x and the Java Client 5.x series.
2. Double-Check Your Desired Capabilities
Incorrect or missing desired capabilities are the #1 cause of this error. Let’s verify:
- For Android, make sure you include these mandatory capabilities:
deviceName: Match the name of your connected device/emulator (runadb devicesto check)platformName: Set to"Android"(case-sensitive!)- Either
app(path to your APK) ORappPackage+appActivity(find these withaapt dump badging your-app.apk)
- For iOS, confirm you have:
deviceName,platformName,platformVersion, and theapppath to your IPA
- Watch out for typos — even a capitalization mistake (like
PlatformNameinstead ofplatformName) will break session creation.
3. Verify Appium Server & Device Connection
- Ensure your Appium Server is running properly: You should see a log line like
[Appium] Welcome to Appium v1.6.3when it starts, and it should be listening on port 4723 (the default). - Check your device/emulator connection:
- For Android: Run
adb devices— your device should show up asdevice(notofflineorunauthorized). If it’s unauthorized, unlock your device and accept the debug prompt. - For iOS: Make sure Xcode is installed, the simulator is running, and Appium has permission to access it.
- For Android: Run
- Try restarting both the Appium Server and your device/emulator — sometimes a fresh start clears up connection glitches.
4. Ditch the Standalone Selenium Server (If You’re Using It)
Appium 1.6 and later has built-in Selenium support, so you don’t need to run a separate Selenium Server alongside it. If you’re running both, they might be conflicting on ports. Stop the standalone Selenium Server and run your test directly against the Appium Server.
5. Enable Debug Logs for More Clues
If the above steps don’t work, turn on debug logging in Appium to get the full picture:
- Start Appium with this command:
appium --log-level debug - Look at the log lines right before the SessionNotCreatedException is thrown — they’ll usually point to the exact issue (like a missing app file, unrecognized device, or invalid capability value).
If you’re still stuck, share your desired capabilities code snippet and the full Appium debug log, and I can help dig deeper!
内容的提问来源于stack exchange,提问作者Aviral Srivastava

