0

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.

I can't build my test case in eclipse or in cmd line, because eclipse doesn't recognized my import of testNg libraries. TestNG is well installed on my project.

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 ?

My java test using testNG.xml worked perfeclty in eclipse with my testNg version: 6.14. I tried to execute it with my cmd line, I had a NullPointerError error. 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).

I installed the new version of testNG, and test everything I found on the web, but nothing worked. I can't build my test anymore.

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

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.

    The import org.testng cannot be resolved

  • when I runned my TestNG.xml as "TestNG Suite"

    An internal error occurred during: "Launching Test2 TAP_TestNG.xml". java.lang.NullPointerException

  • in the tab "Problems" of eclipse

    Invalid classpath container: 'TestNG' in project 'Test2 TAP' - Test2 TAP -Build path - Build Path Problem

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.

Thanks for your help.

Mark Melgo
  • 1,477
  • 1
  • 13
  • 30
campao
  • 23
  • 4
  • provide command used in cmd to build – murali selenium Jul 15 '19 at 09:54
  • @muraliselenium java -cp "C:\Users\Camille\eclipse-workspace\Test2 TAP\lib\*" org.testng.TestNG TestNG.xml – campao Jul 15 '19 at 10:03
  • this will help you https://stackoverflow.com/questions/11896791/how-to-run-testng-from-command-line make sure that you have testng and it dependency jar files in lib folder – murali selenium Jul 16 '19 at 06:12
  • @muraliselenium Yes it is correctly installed. Like I said, the issue about the cmd line was a [bug](https://github.com/cbeust/testng/pull/1811) on version 6.14. My problem is that TestNG 7.0 doesn't built in eclipse (and cmd line). Thank you – campao Jul 16 '19 at 08:24
  • see its not about installation in eclipse. in lib folder you have to place testng and its dependency jar files. download those from maven repository and place it in lib folder. then try once – murali selenium Jul 16 '19 at 14:23
  • @muraliselenium All my jar files is in a lib folder on my projet. I'm in the same situation than this [case] (https://github.com/cbeust/testng/issues/1810) when I ant to build my code with TestNG 6.14.3. I don't understand why I have to download those from maven because I don't want to used maven a this time. It is necessary to installed it ? – campao Jul 17 '19 at 06:03

2 Answers2

0

This could be due to some trivial issues. A couple of checks:

  1. Have you installed the TestNG plugin for eclipse? If not go to marketplace and do that Link for TestNG- Eclipse
  2. Make sure the build path for your project has TestNG libraries. If not go to build path and click on Add Library. This will allow you to add TestNG libraries.

This has nothing to do with Maven and should work independently as well. You can also refer TestNG-Eclipse doc

NiNa
  • 111
  • 1
  • 4
0

I believe it is happening due to multiple versions of testng in your .m2 folder. There are 2 solutions I can think of

  1. Delete all the items in TestNG folder and recompile the project.
  2. Delete TestNG versions which you don't require and then recompile the project.
Vishal Gada
  • 201
  • 3
  • 12
  • Thanks for your help. I already delete and add just the files needed. I uninstalled the version 7.0 of TestNG and re installed the version 6.14.3 wich is working again correctly on eclipse (but not on cmd line). I'm supposed there is some issue on the version 7.0 and the building on eclipse. If anyone is using TestNG version 7.0 with the lastest version of eclipse, please let me know. – campao Jul 16 '19 at 01:24