Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
如何使selenium java项目运行使用testng xml的jar文件_Java_Selenium_Selenium Webdriver_Webdriver_Selenium Chromedriver - Fatal编程技术网

如何使selenium java项目运行使用testng xml的jar文件

如何使selenium java项目运行使用testng xml的jar文件,java,selenium,selenium-webdriver,webdriver,selenium-chromedriver,Java,Selenium,Selenium Webdriver,Webdriver,Selenium Chromedriver,我正在尝试用runnable jar文件构建我的selenium项目 我使用以下代码:- public static void main(String[] args) { TestListenerAdapter tla = new TestListenerAdapter(); TestNG testng = new TestNG(); testng.setTestClasses(new Class[] { LoginTest.class }); testng.a

我正在尝试用runnable jar文件构建我的selenium项目

我使用以下代码:-

public static void main(String[] args) {

    TestListenerAdapter tla = new TestListenerAdapter();
    TestNG testng = new TestNG();
    testng.setTestClasses(new Class[] { LoginTest.class });
    testng.addListener(tla);
    testng.run();       
    }
它不会给我带来配置故障:1如下所示:-

[TestNG] Running:
  Command line suite


===============================================
Command line suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0
===============================================
上面的代码只运行我的类。我需要运行testng.xml。我不知道我做错了什么

我也试过使用sh文件

public static void main(String[] args) {
        ProcessBuilder pb = new ProcessBuilder("./shtry.sh", "myArg1", "myArg2");
        try {
         Process p = pb.start();
         BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
         String line = null;

            while ((line = reader.readLine()) != null)
             {
                System.out.println(line);
             }
        } catch (Exception e) {
            e.getMessage();
        }
    }
它在IDE中工作得很好,即使它运行my testng.xml,但在创建运行jar之后,它并没有在终端上显示任何内容

我还尝试了以下代码:-

  List<String> testFilesList = new ArrayList<String>();
    testFilesList.add("./testng.xml"); //test suite resides in the working directory's root folder
    **testng.setTestSuites(testFilesList);** //you can addd multiple suites either here by adding multiple files or include all suites needed in the testng.xml file 
    testng.setUseDefaultListeners(false);
    testng.addListener(htmlRep); 
    testng.run();
List testFilesList=newarraylist();
testFilesList.add(“./testng.xml”)//测试套件驻留在工作目录的根文件夹中
**testng.setTestSuites(testFilesList);**//您可以在此处通过添加多个文件或在testng.xml文件中包含所需的所有套件来添加多个套件
setUseDefaultListeners(false);
testng.addListener(htmlRep);
testng.run();

即使在IDE中运行my testng.xml,它也可以正常工作,但同样没有任何效果

请重写您的问题标题。真令人费解,我已经做了改变。这是我目前所能做的最好的了,请重写你的问题标题。真令人费解,我已经做了改变。这是我目前能做的最好的了