Win7 上的 Selenium 错误

发布于 2024-10-09 01:23:55 字数 5220 浏览 2 评论 0原文

我在命令行上使用以下命令启动 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

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

package file;

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

public class Reset extends 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有什么问题?

I'm starting Selenium server with the following on a command line:

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.*;
import org.openqa.selenium.server.SeleniumServer;

public class Reset extends 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.

This occurs whether I run eclipse in Administrator mode or not.

If I kill one firefox process, then a Firefox window appears, but doesn't open anything.

What's wrong with Selenium in Win7?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜你已久 2024-10-16 01:23:56

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

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

It looks like you need to initialize selenium in your setup (Point to the correct selenium server, port, browser, etc). 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. It seems to work better.

selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");
selenium.start()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文