英文:
Error InvalidTestClassError in Appium test
问题
我正在尝试学习如何在Appium中自动化移动应用程序测试。
我遇到了一个奇怪的问题。测试抛出了一个错误:
org.junit.runners.model.InvalidTestClassError: 无效的测试类 'com.example.TestMovil':
- main() 方法不应该是静态的
- 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.xxx.xxx");
capabilities.setCapability("appActivity", "com.xxx.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.xxx.xxx:id/activity_onboarding_sign_in_button"));
iniciarSesion.click();
}
}
尝试在Android设备上测试登录会话。
英文:
I'm trying to learn how to automate mobile app tests in Appium.
I have a strange problem. The test throws me an error:
org.junit.runners.model.InvalidTestClassError: Invalid test class 'com.example.TestMovil':
- Method main() should not be static
- Method main should have no parameters
The strangest thing of all is that when I wrote the test everything worked fine, it was when I restarted it days later that it started to fail.
I show you the code:
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.xxx.xxx");
capabilities.setCapability("appActivity", "com.xxx.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.xxx.xxx:id/activity_onboarding_sign_in_button"));
iniciarSesion.click();
}
}
Try to test a login session on Android device
答案1
得分: 0
你的测试应该放在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();
}
}
英文:
Your tests should be under src/test
folder, therefore there is no main
method. You should remove the main method, right click on the file and run it if you use IDE, otherwise, you need to use CLI.
The end result would look like this :
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();
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论