在测试类中声明页面对象会引发以下错误 - Appium

问题描述 投票:0回答:1

在测试类中声明页面对象时出现错误,如下面的代码所示。当我在测试方法中声明页面对象时,它运行得很好,我认为这是不对的。

package test;

import org.junit.jupiter.api.DisplayName;
import org.testng.Assert;
import org.testng.annotations.Test;
import screens.SmlHomeScreen;

public class LoginTest extends BaseTest {
    SmlHomeScreen smlHomeScreen = new SmlHomeScreen();

    @Test
    @DisplayName("Should login to App successfully")
    public void loginTest() throws InterruptedException {
        loginScreen.signIn(configProperty.getUsername(), configProperty.getPassword());
        Assert.assertTrue(smlHomeScreen.getSmlScreenContent().isDisplayed());
    }
}

我收到此错误:

An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details.

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details
Build info: version: '4.25.0', revision: '8a8aea2337'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '14.6', java.version: '23'

但是如果我在下面的测试方法中声明它,它就完美地工作了

package test;

import org.junit.jupiter.api.DisplayName;
import org.testng.Assert;
import org.testng.annotations.Test;
import screens.SmlHomeScreen;


public class LoginTest extends BaseTest {


    @Test
    @DisplayName("Should login into App successfully")
    public void loginTest() throws InterruptedException {
        loginScreen.signIn(configProperty.getUsername(), configProperty.getPassword());

        SmlHomeScreen smlHomeScreen = new SmlHomeScreen();
        Assert.assertTrue(smlHomeScreen.getSmlScreenContent().isDisplayed());
    }
}

我还尝试声明我的

BaseTest
中的所有页面,如下所示:

package test;

import org.junit.jupiter.api.BeforeAll;
import org.testng.annotations.*;
import screens.HomeScreen;
import screens.LoginScreen;
import screens.SmlHomeScreen;
import utils.ConfigProperty;
import utils.Driver;


public class BaseTest extends Driver {

    protected LoginScreen loginScreen;
    protected ConfigProperty configProperty
    protected HomeScreen homeScreen;
    protected SmlHomeScreen smlHomeScreen;


    @BeforeMethod
    public void preTest() {
        LoginScreen = new LoginScreen()
        homeScreen = new HomeScreen()
        smlHomeScreen = new SmlHomeScreen()
        configProperty = new ConfigurProperty().
    }

我遇到了和以前一样的错误。这是一个网络驱动程序异常,我发现很难解决这个问题。请帮忙

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details
Build info: version: '4.25.0', revision: '8a8aea2337'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '14.6', java.version: '23'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [084af3d7-627c-40e7-af94-c26e0b032d37, findElement {using=-android uiautomator, value=new UiSelector().text("Login").instance(1)}]
java android selenium-webdriver appium appium-android
1个回答
0
投票

你不能这样做:

SmlHomeScreen smlHomeScreen = new SmlHomeScreen();

你可以在类中声明类

SmlHomeScreen smlHomeScreen
的实例,但不能初始化它。

如果您不想在测试方法中分配它,请使用构造函数

package test;

import org.junit.jupiter.api.DisplayName;
import org.testng.Assert;
import org.testng.annotations.Test;
import screens.SmlHomeScreen;

public class LoginTest extends BaseTest {
    SmlHomeScreen smlHomeScreen;

    public LoginTest {
       smlHomeScreen = new SmlHomeScreen()
    }

    @Test
    @DisplayName("Should login to App successfully")
    public void loginTest() throws InterruptedException {
        loginScreen.signIn(configProperty.getUsername(), configProperty.getPassword());
        Assert.assertTrue(smlHomeScreen.getSmlScreenContent().isDisplayed());
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.