简体   繁体   English

Appium:连接到127.0.0.1:4723 [/127.0.0.1]失败:连接被拒绝:connect

[英]Appium: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect

I am trying to write my first Java Appium test. 我正在尝试编写我的第一个Java Appium测试。
Each time I'm running my code the following errors are presented: 每次我运行代码时,都会出现以下错误:

org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect  
....  
at MyFirstTest.setupTest(MyFirstTest.java:52)  
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect  
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)  
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)  

Here is my code: 这是我的代码:

public class MyFirstTest  
{  
    public AppiumDriver<MobileElement> driver;  
    public WebDriverWait wait;  
    String usersEmail = "xxxx@gmail.com";  
    String userPassword = "aaaaaa";  

    public void login() throws InterruptedException  
    {  
        WebElement email = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Enter Email')]"));  
        email.sendKeys(usersEmail);  
        Sleeper.SYSTEM_SLEEPER.sleep(new Duration(1000, TimeUnit.MILLISECONDS));  
        driver.findElement(By.xpath("//android.widget.RelativeLayout[contains(@resource-id,'edtPassword')]//android.widget.EditText[contains(@resource-id,'edtText')]")).sendKeys(userPassword);  
    driver.findElement(By.xpath("//android.widget.Button[contains(@resource-id,'btnLogin')]")).click();  
    }  
    @Before  
    public void setupTest() throws Exception  
    {  
        DesiredCapabilities capabilities = new DesiredCapabilities();  
        capabilities.setCapability("platormName", "Android");  
        capabilities.setCapability("deviceName", "Redmi");  
        capabilities.setCapability("appPackage","com.ls.stockpair");  
        capabilities.setCapability("appActivity","com.ls.stockpair.activity.SplashActivity");  
        driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);  
        Thread.sleep(8000);  
    }  
    @Test  
    public void go() throws InterruptedException  
    {  

    WebElement email = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Enter Email')]"));  
    email.sendKeys(usersEmail);  
    Sleeper.SYSTEM_SLEEPER.sleep(new Duration(1000, TimeUnit.MILLISECONDS));  
    driver.findElement(By.xpath("//android.widget.RelativeLayout[contains(@resource-id,'edtPassword')]//android.widget.EditText[contains(@resource-id,'edtText')]")).sendKeys(userPassword);  
    driver.findElement(By.xpath("//android.widget.Button[contains(@resource-id,'btnLogin')]")).click();  

    Sleeper.SYSTEM_SLEEPER.sleep(new Duration(2000, TimeUnit.MILLISECONDS));  
        }  
}  

Currently I'm starting Appium manually before running the code. 目前,我在运行代码之前手动启动Appium。 Also tried to start Appium from the code - this did not help. 还尝试从代码启动Appium-这没有帮助。
This code worked in the first day I started writing this code however somehow (I really do not know why) this stopped working. 该代码在我开始编写此代码的第一天就起作用了,但是以某种方式(我真的不知道为什么)停止了工作。
I saw many questions with different answers about this issue in the web but no one helped me so far. 我在网路上看到许多关于这个问题有不同答案的问题,但到目前为止,没有人帮助过我。
I'm working with a real Android device connected via USB to my Windows machine. 我正在使用通过USB连接到Windows计算机的真实Android设备。

Below is the best solution, You don't need to start appium manually everytime. 以下是最佳解决方案,您无需每次都手动启动appium。

public static AndroidDriver<MobileElement> driver=null;
    public static AppiumDriverLocalService service=null;

    service = AppiumDriverLocalService.buildDefaultService();
    DesiredCapabilities capabilities = new DesiredCapabilities();  
    capabilities.setCapability("platormName", "Android");  
    capabilities.setCapability("deviceName", "Redmi");  
    capabilities.setCapability("appPackage","com.ls.stockpair");  
    capabilities.setCapability("appActivity","com.ls.stockpair.activity.SplashActivity");  

    service.start();
    driver = new AndroidDriver<MobileElement>(service, capabilities);

Note : If you are using appium version 1.5.3+ then you need to set APPIUM_BINARY_PATH in environmental variable. 注意:如果您使用的是appium版本1.5.3+,则需要在环境变量中设置APPIUM_BINARY_PATH。

eg APPIUM_BINARY_PATH=C:\\Users\\YourUserName\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js 例如APPIUM_BINARY_PATH = C:\\ Users \\ YourUserName \\ AppData \\ Roaming \\ npm \\ node_modules \\ appium \\ build \\ lib \\ main.js

For more details on how to set APPIUM_BINARY_PATH please refer below screen shot: 有关如何设置APPIUM_BINARY_PATH的更多详细信息,请参见以下屏幕截图:

APPIUM_BINRAYPATH

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.http.conn.HttpHostConnectException:连接到127.0.0.1:7055 [/127.0.0.1]失败:连接被拒绝:connect - org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 [/127.0.0.1] failed: Connection refused: connect HttpHostConnectException:连接到 localhost:2375 [localhost/127.0.0.1] 失败:连接被拒绝 - HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1] failed: Connection refused TestRestTemplate HttpHostConnectException:连接到本地主机:8082 [localhost/127.0.0.1] 失败:连接被拒绝 - TestRestTemplate HttpHostConnectException: Connect to localhost:8082 [localhost/127.0.0.1] failed: Connection refused java.net.ConnectException:无法连接到 localhost/127.0.0.1(端口 80):连接失败:ECONNREFUSED(连接被拒绝) - java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused) IOException java.net.ConnectException:无法连接到/127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) - IOException java.net.ConnectException: failed to connect to /127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) 无法执行 HTTP 请求:连接到 localhost:8000 [localhost/127.0.0.1] 失败:连接被拒绝(连接被拒绝) - Unable to execute HTTP request: Connect to localhost:8000 [localhost/127.0.0.1] failed: Connection refused (Connection refused) 无法连接到服务器:localhost / 127.0.0.1:9000:尝试一次失败。 java.net.ConnectException:连接被拒绝 - Failed to connect to server: localhost/127.0.0.1:9000: try once and fail. java.net.ConnectException: Connection refused Cassandra nodetool:无法连接到“ 127.0.0.1:7199” - Cassandra nodetool: Failed to connect to '127.0.0.1:7199' 无法连接到 /127.0.0.1:443 - ANDROID STUDIO - FAILED TO CONNECT TO /127.0.0.1:443 - ANDROID STUDIO localhost/127.0.0.1:9042] 无法连接 - localhost/127.0.0.1:9042] Cannot connect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM