简体   繁体   English

Win7上的硒错误

[英]Selenium error on Win7

I'm starting Selenium server with the following on a command line: 我在命令行上使用以下命令启动Selenium服务器:

java -jar selenium-server.jar

Here is the code: 这是代码:

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());  
    }  
}

Here is the error: 这是错误:

.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

On the advise of answerers - I've modified the code to this: 在回答者的建议下-我已将代码修改为:

package file; 打包文件;

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

public class Reset extends SeleneseTestCase { 公共类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");   
    }   

} }

This now hangs with the output: 现在,这与输出一起挂起:

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...

There do appear to be two firefox processes running - but no screens appearing. 确实有两个运行中的Firefox进程-但没有出现任何屏幕。

This occurs whether I run eclipse in Administrator mode or not. 无论我是否在管理员模式下运行Eclipse,都会发生这种情况。

If I kill one firefox process, then a Firefox window appears, but doesn't open anything. 如果我杀死了一个Firefox进程,则会显示Firefox窗口,但没有打开任何窗口。

What's wrong with Selenium in Win7? Win7中的Selenium有什么问题?

It looks like you need to initialize selenium in your setup (Point to the correct selenium server, port, browser, etc). 看起来您需要在设置中初始化Selenium(指向正确的Selenium服务器,端口,浏览器等)。 Put the following code in the setup and see if this works better. 将以下代码放入设置中,看看是否可以更好地工作。 Also, try out using the *chrome command for firefox instead of *firefox. 另外,尝试将* chrome命令用于firefox而不是* firefox。 It seems to work better. 看来效果更好。

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

This link has program structure which can be used in all test cases, 该链接具有可在所有测试用例中使用的程序结构,

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

have a look at it.. Cheers!!! 看看吧。。干杯!!!

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

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