簡體   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