android Appium测试中出现错误InvalidTestClassError

nc1teljy  于 2023-06-20  发布在  Android
关注(0)|答案(1)|浏览(226)

我正在尝试学习如何在Appium中自动化移动应用程序测试。我有一个奇怪的问题。测试抛出一个错误:
org.junit.runners.model.InvalidTestClassError:无效的测试类“com.example.TestMovil”:
1.方法main()不应该是静态的
1.方法main不应该有参数
最奇怪的是,当我编写测试时,一切都很正常,当我几天后重新启动它时,它开始失败。我给你看代码:

package com.example;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class TestMovil {
    @Test
    
    public static void main(String[] args) {
        
    try{
        testAutoMovil();
    }catch(Exception exp){
        System.out.println(exp.getCause());
        System.out.println(exp.getMessage());
        exp.printStackTrace();
    }
}

    public static void testAutoMovil() throws MalformedURLException{

        AndroidDriver<MobileElement> driverAndroid;
        System.out.println("Creación del driver");

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability("deviceName", "Redmi Note 8 Pro");
        capabilities.setCapability("udid", "heifzt9xypk7jbtc");
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability("platformVersion", "10");
        capabilities.setCapability("appPackage", "com.correos.prepago");
        capabilities.setCapability("appActivity", "com.marcanditasl.bnext.architecture.views.activities.contexts.login.LoginActivity");

        URL url = new URL("http://localhost:4723/wd/hub");

        driverAndroid = new AndroidDriver<MobileElement> (url, capabilities);
        driverAndroid.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        System.out.println("Aplicación comienza");

        MobileElement iniciarSesion = driverAndroid.findElement(By.id("com.correos.prepago:id/activity_onboarding_sign_in_button"));
        iniciarSesion.click();
    }
}

尝试在Android设备上测试登录会话

h9vpoimq

h9vpoimq1#

您的测试应该在src/test文件夹下,因此没有main方法。如果你使用IDE,你应该删除main方法,然后右键单击文件并运行它,否则你需要使用CLI。
最终结果如下所示:

package com.example;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class TestMovil {
    
    @Test
    public static void testAutoMovil() throws MalformedURLException{

        AndroidDriver<MobileElement> driverAndroid;
        System.out.println("Creación del driver");

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability("deviceName", "Redmi Note 8 Pro");
        capabilities.setCapability("udid", "heifzt9xypk7jbtc");
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability("platformVersion", "10");
        capabilities.setCapability("appPackage", "com.correos.prepago");
        capabilities.setCapability("appActivity", "com.marcanditasl.bnext.architecture.views.activities.contexts.login.LoginActivity");

        URL url = new URL("http://localhost:4723/wd/hub");

        driverAndroid = new AndroidDriver<MobileElement> (url, capabilities);
        driverAndroid.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        System.out.println("Aplicación comienza");

        MobileElement iniciarSesion = driverAndroid.findElement(By.id("com.correos.prepago:id/activity_onboarding_sign_in_button"));
        iniciarSesion.click();
    }
}

相关问题