简体   繁体   中英

java.lang.NullPointerException thrown when launching Selenium project

I'm a newbie in Selenium. I created a simple testcase with Selenium IDE recorder, saved it, and exported it as a Java file.
I created a new Java project on Eclipse, imported external jars and the Java code according to http://university.utest.com/selenium-basics-part-1-how-to-set-up-selenium/ tutorial.
When trying to run this it throws java.lang.NullPointerException without pointing to any specific problem. Nothing appears on Console. The error appears as pop-up notification.
I have no idea what's wrong.
I guess the problem is with some Eclipse Run settings or something like this.
The java code is:

import com.thoughtworks.selenium.*;  
import org.junit.After;  
import org.junit.Before;  
import org.junit.Test;  
import static org.junit.Assert.*;  
import java.util.regex.Pattern;  

public class wrongLogin {  
    private Selenium selenium;

    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://am2-qa.einsteinworld.info/en/activities/view");
        selenium.start();
    }

    @Test
    public void testWrongLogin() throws Exception {
        selenium.open("/en/login/view/");
        selenium.type("id=txtUserName", "forg");
        selenium.type("id=txtPassword", "sdsdsd");
        selenium.click("id=loginSubmit");
        assertTrue(selenium.isElementPresent("id=userDetailsError"));
    }

    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }
}

The screenshot can be seen here ' http://www.filedropper.com/npepop-up '

UPD After totally erasing Eclipse with all it's settings and re-installing it from scratch now it works OK

Most probably it seems like you may have forgotten to start the selenium server before running the tests.

Please try running the selenium server for running Selenium Server Go to the directory where Selenium RC's server is located and run the following from a command-line console.

java -jar selenium-server-standalone-<version-number>.jar

Clean and build your project and try again

OR

  1. Exit Eclipse
  2. Go to your workspace
  3. Delete .metadata file
  4. Start Eclipse
  5. Import all your projects in Eclipse

OR

Just create a new Workspace and all your java files in the new workspace.

Could you see if you have any errors in the eclipse log? You can activate it by going to Window -> Show view -> Error Log and see if there's any error there? (I know this isn't an answer, just dont have enough rep to post as comment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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