Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在TestNG中添加selenium android驱动程序jar时出错。找不到类文件?_Java_Android_Eclipse_Selenium_Testng - Fatal编程技术网

Java 在TestNG中添加selenium android驱动程序jar时出错。找不到类文件?

Java 在TestNG中添加selenium android驱动程序jar时出错。找不到类文件?,java,android,eclipse,selenium,testng,Java,Android,Eclipse,Selenium,Testng,我正在为一个Android应用程序编写一个测试类,但是我不断得到错误代码,因为它的构建路径不完整,所以项目没有构建。找不到org.openqa.selenium.html5.BrowserConnection的类文件。修复生成路径,然后尝试生成此项目。每次我尝试将selenium Android驱动程序jar文件添加到项目中时。我需要Android驱动程序正确使用TestNG和Appium,否则Appium在测试时无法在页面上找到元素。守则: package appiumTest; impor

我正在为一个Android应用程序编写一个测试类,但是我不断得到错误代码,因为它的构建路径不完整,所以项目没有构建。找不到org.openqa.selenium.html5.BrowserConnection的类文件。修复生成路径,然后尝试生成此项目。每次我尝试将selenium Android驱动程序jar文件添加到项目中时。我需要Android驱动程序正确使用TestNG和Appium,否则Appium在测试时无法在页面上找到元素。守则:

package appiumTest;

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.android.*;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;

public class TestCase {

    public class NewTest {
        WebDriver driver = new AndroidDriver();
        @BeforeClass
        protected void setUp() throws MalformedURLException {

            //Tells the program what device is used
            DesiredCapabilities capabilities = new 

            DesiredCapabilities();
            capabilities.setCapability("BROWSER_NAME", "Android");
            capabilities.setCapability("VERSION", "4.2.2"); 
            capabilities.setCapability("deviceName","Emulator");
            capabilities.setCapability("platformName","Android");
            //Tells the program what app is being run
            capabilities.setCapability("appPackage",                                 
   "com.android.testapp2");

    capabilities.setCapability("appActivity",
   "com.android.testapp2.MainActivity    ");
     driver = (AndroidDriver) new RemoteWebDriver(new
             URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        }
        @Test
        public void test() {
        WebElement userName = driver.findElement(By.id("txtUserName"));
               userName.sendKeys("a");
            WebElement button = driver.findElement(By.id("btnEnter"));
    button.click();
        };
        @AfterClass
        protected void tearDown() throws Exception {

            driver.quit();
        }

    }


}
下面是我试图编辑的pom.xml文件的代码:

<project xmlns="http://maven.apache.org/POM/4.0.0"        

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>TestProject</groupId>
  <artifactId>TestProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source/>
          <target/>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
我看不到任何地方可以放置依赖项,我甚至不确定这是否是我应该做的。

好的,我想这应该会让你重新开始

pom.xml中所做的改进:

没有定义依赖项,因此添加了所需的ONCE

testng v6.9.8 selenium java v2.39.0 selenium android驱动程序v2.39.0 备注1:据我所知,Selenium Java和Android库的版本应该相同,否则可能会出现问题。 _备注2:_SeleniumAndroid库是一个较旧的库。它实际上应该被新的替换掉。因此,一些进口也会发生变化。 改进了and,这些是小写的标准,应该代表一些逻辑和独特的东西。也许您将项目存储在bitbucket或github上,然后逻辑组id将以com.github开头

移除src

创建了src/test/java目录 将包名appiumTest添加到该测试源目录 在该包中添加了类TestCase。 Maven项目文件pom.xml:

下面的备注是正确的Maven起始标记,因为它应该在pom.xml中使用。但是,当起始标记具有属性时,StackOverflow不会正确显示它

project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd">
下面是更正的pom.xml,但没有正确的起始标记

4.0.0 org.organization.project 安卓硒 0.1.0-SNAPSHOT org.testng testng 6.9.8 测验 org.seleniumhq.selenium 硒爪哇 2.48.2 -> 2.39.0 测验 org.seleniumhq.selenium selenium android驱动程序 2.39.0 maven编译器插件 3.3 在类TestCase中所做的改进:

不需要使用内部类NewTest,所以删除了它。 删除了字段驱动程序的初始化,因为它是在@BeforeClass方法中初始化的。 在@AfterClass中添加了check,仅在驱动程序初始化时调用driver.quit。 类TestCase:

可能的改进

更正当前appiumTest的包名,但该名称不符合命名约定,全部小写,用点分隔。。还有一些有意义的东西,类似于Maven group-id.Sp,从com.github开始。。 给类TestCase起一个更好的名字 更新到Selendroid,然后也更新Selenium Java版本
您使用的是什么构建工具Maven/Gradle?您可以共享并添加构建工具的配置吗?似乎需要添加Selenium dependency.Maven。我发现Selenium依赖项和pom.xml文件需要编辑,但它不可编辑。您应该有一个本地的可编辑pom.xml文件。听起来您在某个依赖项jar中发现了pom.xml,因为它们是并且不应该编辑的。因为他们有一个特殊的罐子。你能把你的pom.xml添加到这里的问题中吗?@Verhagen pom.xml代码被添加到原始帖子中。正如您所说,我试图在jar文件中编辑pom.xml,因为我不确定该依赖项还可以放在哪里,因为它是专门针对该jar的。我甚至不知道我是否有正确的依赖关系。我稍后会检查它。问:当我需要解释事情时,您正在使用什么IDE Eclipse/IntelliJ/etc,这很方便知道。
package appiumTest;

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.android.*;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;

public class TestCase {
    WebDriver driver; // = new AndroidDriver();

    @BeforeClass
    protected void setUp() throws MalformedURLException {

        // Tells the program what device is used
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("BROWSER_NAME", "Android");
        capabilities.setCapability("VERSION", "4.2.2");
        capabilities.setCapability("deviceName", "Emulator");
        capabilities.setCapability("platformName", "Android");
        // Tells the program what app is being run
        capabilities.setCapability("appPackage", "com.android.testapp2");

        capabilities.setCapability("appActivity",
                "com.android.testapp2.MainActivity");
        driver = (AndroidDriver) new RemoteWebDriver(new URL(
                "http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @Test
    public void test() {
        WebElement userName = driver.findElement(By.id("txtUserName"));
        userName.sendKeys("a");
        WebElement button = driver.findElement(By.id("btnEnter"));
        button.click();
    };

    @AfterClass
    protected void tearDown() throws Exception {
        if (driver != null) {
            driver.quit();
        }
    }

}