gpt4 book ai didi

java - 我无法在 JUnit 中运行第二个测试,它显示 "session not created"

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:36 25 4
gpt4 key购买 nike

当我尝试在 appium 中运行测试时,我的第二个测试没有运行。它显示“无法创建新 session ”。我的第二个测试函数名称是 BAddon,而第二个测试执行时抛出错误

这是我的代码

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class FirstAutomate {
private WebDriver driver;

@Before
public void setup() throws Exception {
//File app = new File("C:\\sdk\\platform-tools\\Myapp.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("VERSION", "5.0.2");
capabilities.setCapability("deviceName","G3 Beat");
capabilities.setCapability("appPackage", "com.myapp.app");
capabilities.setCapability("appActivity","com.myapp.app.screens.prehomescreens.activities.SplashScreen");
capabilities.setCapability("platformName","Android");

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
//capabilities.setCapability("app", app.getAbsolutePath());
try{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

}catch(MalformedURLException e)
{
e.printStackTrace();
}
// TODO Auto-generated method stub
}

@Test
public void AppLogin() throws InterruptedException {
//Tapping login button
Thread.sleep(5000);
driver.findElement(By.id("loginButtonTextView")).click();
//User inputs mail id
driver.findElement(By.id("emailIdEditText")).sendKeys("rag1@mail.com");
//User login button click
driver.findElement(By.id("loginBtnRCB")).click();
//User inputs OTP
driver.findElement(By.id("pinPadContainer")).sendKeys("123456");
WebElement loginBtn = driver.findElement(By.id("nextBtnRCB"));
if(loginBtn.isDisplayed())
{
loginBtn.click();
}else
{
System.out.println("Button is not present");
}
Thread.sleep(15000);
}



@Test
public void BAddOn() throws InterruptedException{

//Thread.sleep(10000);
WebElement AddonBtn = driver.findElement(By.id("studentStatusButton"));
if(AddonBtn.isDisplayed())
{
AddonBtn.click();
}else{
System.out.println("AddOnBtn is not visible");
}

}
}

最佳答案

我猜想 setup 是在每个测试用例之前调用的。服务器运行后,您不需要再次调用安装程序。

您需要找到一种方法,以便在开始执行测试用例之前仅调用 appium 服务器设置一次。我认为有 @BeforeClass 注释可以做到这一点。

关于java - 我无法在 JUnit 中运行第二个测试,它显示 "session not created",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com