我创建了一个用于编写移动自动测试的appium项目,appium服务器运行在:
0.0.0.0:4000
Apium Inspector 成功连接到该地址,但是当我尝试通过 IntelliJ 运行测试时,出现错误:
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Host info: host: 'DESKTOP-HD34DIE', ip: '192.168.1.122'
具有功能配置的文件:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
public class LoginTest {
private AppiumDriver driver;
@BeforeMethod
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("deviceName", "Pixel_8");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "11");
capabilities.setCapability("appPackage", "com.example.login");
capabilities.setCapability("app", "E:/mobileTests/MobileTest/src/test/resourses/app/calculator.apk");
driver = new AndroidDriver(new URL("http://0.0.0.0:4000"), capabilities);
}
我尝试更改端口和主机值,但似乎没有看到这些设置。 我不完全理解这个问题,为什么它不起作用。
Appium 默认在本地主机(URL - 127.0.0.1)和端口 - 4723 上运行。您应该使用 URL“http://127.0.0.1:4723/wd/hub”来创建新会话。