当我使用appium在日食中运行我的第一个测试时,我在日食中遇到错误。
以下是我的代码:
package Appium;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
//import org.openqa.selenium.remote.CapabilityType;
public class Appium {
WebDriver driver;
@BeforeClass
public void Appium() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("BROWSER_NAME", "Chrome");
capabilities.setCapability("VERSION", "5.1");
capabilities.setCapability("deviceName","Nexus 5");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create RemoteWebDriver instance and connect to the Appium server
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCal() throws Exception {
//locate the Text on the calculator by using By.name()
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
//locate the edit box of the calculator by using By.tagName()
WebElement results=driver.findElement(By.tagName("EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
}
@AfterClass
public void teardown(){
//close the app
driver.quit();
}
}
当我使用testNg运行此代码时,我收到以下错误。
FAILED CONFIGURATION:@BeforeClass Appium java.lang.NoClassDefFoundError:org / json / JSONObject at org.openqa.selenium.logging.profiler.HttpProfilerLogEntry.constructMessage(HttpProfilerLogEntry.java:36) 在 org.openqa.selenium.logging.profiler.HttpProfilerLogEntry。(HttpProfilerLogEntry.java:28) 在 org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:133) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242) 在 org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:128) 在 org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:155) 在Appium.Appium.Appium(Appium.java:47)
答案 0 :(得分:0)
确保您已在项目中正确导入所有外部jar包
答案 1 :(得分:0)
正如上面的回答所示,您的项目中可能缺少google-gson jar。 您将在同一页面上找到maven依赖项。