0

I have the following class:

import static org.junit.Assert.*;

import org.openqa.selenium.WebElement;

 public class ClasseTeste extends Navegadores {

  public static void verificarTitulo() {
     abrirChrome();
     String titulo = driver.getTitle();
     assertTrue(titulo.contains("google"));
     fecharNavegador(); 
  }

}

When I execute a main method

public static void main( String[] args )
{
     verificarTitulo();     
}

This exception happens:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/Assert
at test.NovoProjeto.ClasseTeste.verificarTitulo(ClasseTeste.java:11)
at test.NovoProjeto.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: org.junit.Assert
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more

I'm trying create some simple tests for a selenium webdriver.

Nathan S.
  • 5,244
  • 3
  • 45
  • 55
andrepm
  • 867
  • 4
  • 13
  • 31
  • This link will likely help: http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java – Richard Aug 11 '14 at 19:44

2 Answers2

0

This error

Caused by: java.lang.ClassNotFoundException: org.junit.Assert

means that you need junit.jar to be on your classpath when you run your tests.

Nathan S.
  • 5,244
  • 3
  • 45
  • 55
0

as you are using maven as build manager add the following dependencies in POM.xml file:

             <dependency>
                 <groupId>org.seleniumhq.selenium</groupId>
                 <artifactId>selenium-java</artifactId>
                 <version>2.41.0</version>
             </dependency>

             <dependency>
                 <groupId>org.seleniumhq.selenium</groupId>
                 <artifactId>selenium-support</artifactId>
                 <version>2.41.0</version>
             </dependency>



             <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.10</version>
                <scope>test</scope>
            </dependency>

and in code your import will look like:

import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.PageFactory;

import org.openqa.selenium.WebElement;

Hope this works for you.

eugene.polschikov
  • 7,254
  • 2
  • 31
  • 44