简体   繁体   English

启动Selenium项目时抛出java.lang.NullPointerException

[英]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. 我使用Selenium IDE记录器创建了一个简单的测试用例,将其保存并导出为Java文件。
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. 根据http://university.utest.com/selenium-basics-part-1-how-to-set-up-selenium/教程,我在Eclipse上创建了一个新的Java项目,并导入了外部jar和Java代码。
When trying to run this it throws java.lang.NullPointerException without pointing to any specific problem. 尝试运行此代码时,它抛出java.lang.NullPointerException而不指向任何特定问题。 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. 我猜问题出在某些Eclipse Run设置或类似的东西上。
The java code is: Java代码是:

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 ' 屏幕快照可以在这里' 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 UPD在用所有设置全部擦除Eclipse并从头开始重新安装之后,现在可以正常工作了

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. 请尝试运行selenium服务器以运行Selenium Server。转到Selenium RC服务器所在的目录,然后从命令行控制台运行以下命令。

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

Clean and build your project and try again 清理并构建您的项目,然后重试

OR 要么

  1. Exit Eclipse 退出Eclipse
  2. Go to your workspace 转到您的工作区
  3. Delete .metadata file 删除.metadata文件
  4. Start Eclipse 启动Eclipse
  5. Import all your projects in Eclipse 在Eclipse中导入所有项目

OR 要么

Just create a new Workspace and all your java files in the new workspace. 只需在新的工作区中创建一个新的工作区和所有Java文件即可。

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) (我知道这不是答案,只是没有足够的代表来发表评论)

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

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