繁体   English   中英

Win7上的硒错误

[英]Selenium error on Win7

我在命令行上使用以下命令启动Selenium服务器:

java -jar selenium-server.jar

这是代码:

import com.thoughtworks.selenium.*;  
import java.util.regex.Pattern;  

import org.openqa.selenium.server.SeleniumServer;

import junit.framework.*;  

public class orkut extends SeleneseTestCase {   
    public void setUp() throws Exception {    
        //SeleniumServer server = new SeleniumServer();
        //server.start();


        setUp("https://www.google.com/", "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");   
    }  

    public void testOrkut() throws Exception {    
        selenium.setTimeout("10000");    
        selenium.open("/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0&cd=IN&skipvpage=true&sendvemail=false");    
        selenium.type("Email", "username");    
        selenium.type("Passwd", "password");    
        selenium.click("signIn");    
        selenium.selectFrame("orkutFrame");    
        selenium.click("link=Communities");    
        selenium.waitForPageToLoad("10000");   
        }   

    public static Test suite() {    
        return new TestSuite(orkut.class);   
        }   

    public void tearDown(){    
        selenium.stop();   
    }   

    public static void main(String args[]) {    
        junit.textui.TestRunner.run(suite());  
    }  
}

这是错误:

.E
Time: 33.386
There was 1 error:
1) testOrkut(orkut)java.lang.RuntimeException: Could not start Selenium session:     Failed to start new browser session: Unable to delete file     C:\Users\user\AppData\Local\Temp\customProfileDir78cf02e3efca4772a71525c4a7523cac\parent.lock
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:89)
at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:123)
at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:104)
at com.thoughtworks.selenium.SeleneseTestCase.setUp(SeleneseTestCase.java:78)
at orkut.setUp(orkut.java:14)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212)
at orkut.main(orkut.java:37)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: Unable to delete file C:\Users\M022534\AppData\Local\Temp\customProfileDir78cf02e3efca4772a71525c4a7523cac\parent.lock
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:223)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:81)
... 16 more

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1

在回答者的建议下-我已将代码修改为:

打包文件;

导入com.thoughtworks.selenium。*; 导入org.openqa.selenium.server.SeleniumServer;

公共类Reset扩展了SeleneseTestCase {

private SeleniumServer seleniumServer;

private Selenium selenium = new DefaultSelenium("localhost", 4444,
        "*chrome", "http://");

public void setUp() throws Exception {
    seleniumServer = new SeleniumServer();
    seleniumServer.start();
    selenium.start();
}

// Test methods shd go here
public void tearDown() throws Exception {
    selenium.stop();
    seleniumServer.stop();
}

public void testOrkut() throws Exception {    
    selenium.setTimeout("10000");    
    selenium.open("/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0&cd=IN&skipvpage=true&sendvemail=false");    
    selenium.type("Email", "username");    
    selenium.type("Passwd", "password");    
    selenium.click("signIn");    
    selenium.selectFrame("orkutFrame");    
    selenium.click("link=Communities");    
    selenium.waitForPageToLoad("10000");   
    }   

}

现在,这与输出一起挂起:

11:22:15.571 INFO - Java: Sun Microsystems Inc. 16.3-b01
11:22:15.571 INFO - OS: Windows 7 6.1 x86
11:22:15.586 INFO - v1.0.1 [2696], with Core v@VERSION@ [@REVISION@]
11:22:15.686 INFO - Version Jetty/5.1.x
11:22:15.686 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
11:22:15.686 INFO - Started HttpContext[/selenium-server,/selenium-server]
11:22:15.686 INFO - Started HttpContext[/,/]
11:22:15.686 INFO - Started SocketListener on 0.0.0.0:4444
11:22:15.686 INFO - Started org.mortbay.jetty.Server@1f630dc
11:22:15.748 INFO - Checking Resource aliases
11:22:15.748 INFO - Command request: getNewBrowserSession[*chrome, http://, ] on session null
11:22:15.764 INFO - creating new remote session
11:22:16.435 INFO - Allocated session dc869f4254414d05b7f1d028dcf33123 for http://, launching...
11:22:16.559 INFO - Preparing Firefox profile...

确实有两个运行中的Firefox进程-但没有出现任何屏幕。

无论我是否在管理员模式下运行Eclipse,都会发生这种情况。

如果我杀死了一个Firefox进程,则会显示Firefox窗口,但没有打开任何窗口。

Win7中的Selenium有什么问题?

看起来您需要在设置中初始化Selenium(指向正确的Selenium服务器,端口,浏览器等)。 将以下代码放入设置中,看看是否可以更好地工作。 另外,尝试将* chrome命令用于firefox而不是* firefox。 看来效果更好。

selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");
selenium.start()

该链接具有可在所有测试用例中使用的程序结构,

http://seleniumready.blogspot.com/2010/12/code-to-start-and-stop-selenium-server.html

看看吧。。干杯!!!

暂无
暂无

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

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