简体   繁体   English

Eclipse:使用过不带Maven的testNG 7吗? ClassPath问题

[英]Eclipse : Used testNG 7 without built with maven ? ClassPath issue

I'm writting some testCases on Windows in java using eclipse IDE, version : 2019-06 (4.12.0), selenium WebDriver 4.0.0, testNG 7.0.0-beta7 and PageFactory POM. 我正在使用eclipse IDE在Java上的Windows上编写一些TestCases,版本:2019-06(4.12.0), Selenium WebDriver 4.0.0, testNG 7.0.0- beta7和PageFactory POM。

I can't build my test case in eclipse or in cmd line, because eclipse doesn't recognized my import of testNg libraries. 我无法在eclipse或cmd行中构建测试用例,因为eclipse无法识别我导入的testNg库。 TestNG is well installed on my project. TestNG在我的项目中安装得很好。

I'm supposed that is a class path issue. 我认为这是一个类路径问题。 I would like to know if it's because i'm not using Maven (I don't have to used it for the moment), or if there is some issues with the latest version of testNG lib ? 我想知道是否是因为我没有使用Maven(暂时不必使用它),或者最新版本的testNG lib是否存在问题?

My java test using testNG.xml worked perfeclty in eclipse with my testNg version: 6.14. 我使用testNG.xml的Java测试在testNg版本为6.14的情况下在eclipse中正常运行。 I tried to execute it with my cmd line, I had a NullPointerError error. 我试图用我的cmd行执行它,但出现了NullPointerError错误。 There was a bug with this exception in the previous versions of testNG: https://github.com/cbeust/testng/pull/1811 and they fixed it on the latest version (7.0.0). 在以前的testNG版本中存在一个带有此异常的错误: https : //github.com/cbeust/testng/pull/1811 ,他们将其修复为最新版本(7.0.0)。

I installed the new version of testNG, and test everything I found on the web, but nothing worked. 我安装了新版本的testNG,并测试了我在网上找到的所有内容,但没有任何效果。 I can't build my test anymore. 我无法建立测试了。

CreateSingleOrder_BondsPage.java CreateSingleOrder_BondsPage.java

import org.openqa.selenium.Keys;

public class CreateSingleOrder_BondsPage {

    WebDriver driver;

    public CreateSingleOrder_BondsPage(WebDriver driver) {
        // TODO Auto-generated constructor stub
        this.driver = driver;
    }

    @FindBy(id="M1_3") WebElement tabOrderManagement;

 public void hoverTabOrderManagement() {
    Actions action = new Actions(driver);
    action.moveToElement(tabOrderManagement).perform(); //move 
   to the element

    }
}

CreateSingleOrder_BondsTest.java CreateSingleOrder_BondsTest.java

import org.testng.annotations.Test;

public class CreateSingleOrder_BondsTest extends BasicTest { /*BasicTest 
contains initialization of driver in @BeforeMethod and @AfterMethod also 
*/

    @Test
    public void buyBonds() throws Exception {
        CreateSingleOrder_BondsPage createBonds = 
    PageFactory.initElements(driver, CreateSingleOrder_BondsPage.class);
        Thread.sleep(1000); //loading data
        createBonds.hoverTabOrderManagement();
   }
}

I have these errors : 我有这些错误:

  • for my import in my java class. 在我的java类中导入。

    The import org.testng cannot be resolved 导入org.testng无法解析

  • when I runned my TestNG.xml as "TestNG Suite" 当我将TestNG.xml运行为“ TestNG Suite”时

    An internal error occurred during: "Launching Test2 TAP_TestNG.xml". 在以下过程中发生内部错误:“启动Test2 TAP_TestNG.xml”。 java.lang.NullPointerException java.lang.NullPointerException

  • in the tab "Problems" of eclipse 在Eclipse的“问题”标签中

    Invalid classpath container: 'TestNG' in project 'Test2 TAP' - Test2 TAP -Build path - Build Path Problem 无效的类路径容器:项目“ Test2 TAP”中的“ TestNG”-Test2 TAP-生成路径-生成路径问题

If anyone can help me with the idea of using maven for the class path, if it's could be a solution or other solutions I can use to run my test again would be very helpful. 如果有人可以帮助我将maven用于类路径,那么如果可以使用它作为解决方案或其他解决方案,那么我可以再次使用它来进行测试将非常有帮助。

Thanks for your help. 谢谢你的帮助。

This could be due to some trivial issues. 这可能是由于一些琐碎的问题。 A couple of checks: 几项检查:

  1. Have you installed the TestNG plugin for eclipse? 您是否已为Eclipse安装了TestNG插件? If not go to marketplace and do that Link for TestNG- Eclipse 如果不去市场,那就去TestNG- Eclipse链接
  2. Make sure the build path for your project has TestNG libraries. 确保项目的构建路径具有TestNG库。 If not go to build path and click on Add Library. 如果没有,请转到构建路径,然后单击添加库。 This will allow you to add TestNG libraries. 这将允许您添加TestNG库。

This has nothing to do with Maven and should work independently as well. 这与Maven无关,也应该独立工作。 You can also refer TestNG-Eclipse doc 您还可以参考TestNG-Eclipse文档

I believe it is happening due to multiple versions of testng in your .m2 folder. 我相信这是由于您的.m2文件夹中有多个testng版本导致的。 There are 2 solutions I can think of 我可以想到2种解决方案

  1. Delete all the items in TestNG folder and recompile the project. 删除TestNG文件夹中的所有项目,然后重新编译项目。
  2. Delete TestNG versions which you don't require and then recompile the project. 删除不需要的TestNG版本,然后重新编译项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM