我试图通过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}
I want to use only Android default Browser and not Chrome. I dont know why Appium is trying to launch Chromedriver and Chrome Browser. Below is the code i used.
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();
}
}
5 回答
设置android功能最安全的方法= DesiredCapabilities.android()
PS:您的会话未创建,因为您的脚本无法连接到selenium node / hub;你应该检查你的配置
与你的邮政堆栈跟踪一样,它连接到http:// **:9515 /(不像你提到的端口4723)
您需要将以下网址设置为
http://0.0.0.0:9515/wd/hub
而不是****:4723
...Chromedriver的端口默认为9515,而不是4723. You should read the documentation on this. There are other capabilities that need to be set correctly (如
BROWSER_NAME
)虽然这个问题很古老,但很多定义在appium客户端使用方面也发生了变化,同时Chrome驱动程序版本更新也发生了变化 . 然而我能想到的是,这里的问题来自于日志:
进一步导致:
因此SessionNotCreatedException .
Simpler fix to this could be ensuring no other session is in progress before initiating another to avoid conflicts of ports and session failure.
在评论下面的声明后尝试运行
将旧的镀铬驱动程序替换为appium位置的新镀铬驱动程序,它对我有用 .
Appium的位置应该是这样的:
Appium版本:1.4.16.1