我正在尝试通过Appium运行我的第一个测试并获得以下错误。
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Did not get session redirect from Chromedriver) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 4.64 seconds Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32' os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51' Driver info: org.openqa.selenium.remote.RemoteWebDriver
Appium Logs:
ERROR: debug: Appium request initiated at /wd/hub/session
info: Looks like we want chrome on android
info: Creating new appium session 99ff77a0-86fa-4851-93ad-5375c95656e7
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" devices
info: Preparing device for session
info: Not checking whether app is present since we are assuming it's already on the device
info: Checking whether adb is present
info: [ADB] Using adb from D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe
info: Trying to find a connected android device
info: [ADB] Getting connected devices...
info: [ADB] 1 device(s) connected
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 wait-for-device
info: Setting device id to emulator-5554
info: [ADB] Waiting for device to be ready and to respond to shell commands (timeout = 5)
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 shell "echo 'ready'"
info: Starting logcat capture
ERROR: debug: Pushing unlock helper app to device...
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 install "C:\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 shell "dumpsys window"
info: Writing dumpsys output to C:\Appium\node_modules\appium\.dumpsys.log
ERROR: debug: Screen already unlocked, continuing.
info: Creating Chrome session
info: Ensuring Chromedriver exists
info: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %b))
info: No old chromedrivers seemed to exist
info: Spawning chromedriver with: C:\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [CHROMEDRIVER] Starting ChromeDriver (v2.9.248315) on port 9515
info: Making http request with opts: {"url":"http://****:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.browser","androidActivity":"com.android.browser.BrowserActivity","androidDeviceSerial":"emulator-5554"}}}}
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 devices
info: [CHROMEDRIVER STDERR] [0.003][SEVERE]: Could not bind socket to 0.0.0.0:9515
info: [CHROMEDRIVER] Port not available. Exiting...
info: Chromedriver exited with code 1
info: [ADB] Getting connected devices...
ERROR: error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"ba9a494082776d6b4836da850072cbcb","status":13,"value":{"message":"unknown error: Device emulator-5554 is already in use\n (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86)"}}
info: Cleaning up appium session
ERROR: error: Failed to start an Appium session, err was: Error: Did not get session redirect from Chromedriver
info: Error: Did not get session redirect from Chromedriver
at null. (C:\Appium\node_modules\appium\lib\devices\android\chromedriver.js:195:12)
at Request._callback (C:\Appium\node_modules\appium\lib\devices\common.js:104:5)
at Request.self.callback (C:\Appium\node_modules\appium\node_modules\request\request.js:121:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request. (C:\Appium\node_modules\appium\node_modules\request\request.js:985:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (C:\Appium\node_modules\appium\node_modules\request\request.js:936:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Did not get session redirect from Chromedriver)","origValue":"Did not get session redirect from Chromedriver"},"sessionId":null}
我想只使用Android默认浏览器,而不是Chrome。我不知道Appium为什么要推出Chromedriver和Chrome浏览器。以下是我使用的代码。
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Appium {
public WebDriver driver;
@BeforeMethod
public void beforeMethod() throws Exception {
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformVersion", "4.4.2");
WebDriver driver = new RemoteWebDriver(new URL(
http://****:4723/wd/hub), capabilities);
driver.get("http://www.yahoo.com");
}
@Test
public void f() {
}
@AfterMethod
public void afterMethod() {
driver.quit();
}
}
答案 0 :(得分:1)
您需要将以下网址设置为http://0.0.0.0:9515/wd/hub
,而不是****:4723
...
WebDriver driver = new RemoteWebDriver(new URL(http://****:4723/wd/hub), capabilities);
Chromedriver的端口默认为9515,而非4723. You should read the documentation on this. There are other capabilities that need to be set correctly (如BROWSER_NAME
)
答案 1 :(得分:0)
为android功能设置最安全的方法= DesiredCapabilities.android()
PS:您的会话未创建,因为您的脚本无法连接到selenium node / hub;你应该检查你的配置
与你的帖子堆栈跟踪一样,它连接到http:// **:9515 /(与你提到的端口4723不一样)
答案 2 :(得分:0)
虽然这个问题很旧,但很多定义在appium客户端使用方面也发生了变化,同时Chrome驱动程序版本更新也发生了变化。然而我能想到的是,这里的问题来自日志:
错误:错误:Chromedriver创建会话无法正常工作。状态是200 和身体是 { “的sessionId”: “ba9a494082776d6b4836da850072cbcb”, “状态”:13, “值”:{ “消息”:“未知 错误:设备模拟器-5554已在使用中 \ n(驱动程序信息: chromedriver = 2.9.248315,platform = Windows NT 6.1 SP1 x86)“}}
进一步导致:
org.openqa.selenium.SessionNotCreatedException:新会话可以 不被创造。 (原始错误:未获得会话重定向 Chromedriver )(警告:服务器没有提供任何堆栈跟踪 信息)
因此 SessionNotCreatedException 。
更简单的解决方法是确保在启动另一个会话之前没有其他会话正在进行,以避免端口冲突和会话失败。
答案 3 :(得分:0)
在评论下面的语句
后尝试运行 capabilities.setCapability("platformVersion", "4.4.2");
答案 4 :(得分:0)
将旧的Chrome驱动程序替换为appium位置的新chrome驱动程序,它对我有用。
Appium的位置应该是:
C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\
Appium版本:1.4.16.1