硒网格连接与自动不工作?

时间:2017-03-09 07:15:57

标签: selenium grid autoit

selenium grid connection with auto it  not working ?

@ daluudaluu / PartialSeleniumGridIntegrationWithAutoItExample.java     一年前最后活跃     嵌入
           下载ZIP      代码修订2分叉1     部分Selenium Grid集成支持AutoIt,Sikuli等工具。     生的      PartialSeleniumGridIntegrationWithAutoItExample.java     import static org.junit.Assert。*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import java.net.URL;

public class DemoTest {

    public WebDriver driver;
    public DesiredCapabilities capabilities;

    @Before
    public void setUp() throws Exception {
        capabilities = DesiredCapabilities.firefox();
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub" ), capabilities);
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void test() throws Exception {
        // Use RemoteWebDriver, grab actual node host info
        driver.get("http://www.google.com");        
        String sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
        //grid info extractor from: https://gist.github.com/krmahadevan/1766772
        String nodeHost = GridInfoExtracter.getHostNameAndPort("localhost", 4444, sessionId)[0];        
        System.out.println("Extracted hostname: "+nodeHost);

        // Now use node host info to handle running AutoIt on that specific node, assuming all needed files deployed to all nodes

        // Case 1 - PSExec.exe from Windows host (that is executing this Selenium code) to Selenium node that is Windows host
        //String psexecCmd = "C:\\LocalMachinePathTo\\psexec.exe \\\\%s -u %s -p %s -i C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe";
        //Process p = Runtime.getRuntime().exec(String.format(psexecCmd,nodeHost,"jdoe","hisPassword"));
        //p.waitFor();

        // Case 2 - winexe from *nix host (that is executing this Selenium code) to Selenium node that is Windows host
        // Example reference: http://secpod.org/blog/?p=661
        //String winexeCmd = "/LocalMachinePathTo/winexe -U domainName/jdoe%hisPassword //"+nodeHost+" C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe";
        //Process p = Runtime.getRuntime().exec(winexeCmd);
        //p.waitFor();

        // Case 3 - have SSH installed on Windows-based Selenium nodes, now just connect to node host via SSH to run a command, i.e. execute AutoIt script binary
        // no sample code given for Java, but maybe this gives you ideas on Java SSH connection:
        // http://stackoverflow.com/questions/995944/ssh-library-for-java

        // Case 4 - if you have implemented a custom web service (XML-RPC/SOAP/REST) for AutoIt that listens for requests/commands
        // just connect to it via (Java) HTTP library to "http://"+nodeHost+"/someWebServicePath/someCommand" (via GET or POST)
        // details not covered, this is just an example. Most people won't be taking this route due to customization & complexity in
        // building the web service first

        // Case 5 - using AutoItDriverServer that is also running on Selenium nodes
        //DesiredCapabilities autoitCapabilities = new DesiredCapabilities();
        //autoitCapabilities.setCapability("browserName", "AutoIt");
        //WebDriver autoitDriver = new RemoteWebDriver(new URL("http://"+nodeHost+":4723/wd/hub"), autoitCapabilities);
        //autoitDriver.findElement(By.id("133")).click();
        //and whatever other AutoItX commands to call that you normally have in the AutoIt script that you compile into binary
        //for more ideas on AutoIt commands issued as WebDriver commands with respect to Selenium integration, see:
        //https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py

        //or if you are old school, and want to do that same approach even with AutoItDriverServer,
        // assuming you have first set AutoItScriptExecuteScriptAsCompiledBinary to True in autoit_options.cfg file before starting AutoItDriverServer:
        //((JavascriptExecutor) autoitDriver).executeScript("C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe");

        // Case for Sikuli integration, using https://github.com/enix12enix/sikuli-remote-control
        //RemoteScreen rs = new RemoteScreen(nodeHost);
        //rs.setMinSimilarity(0.9);
        //rs.click("D://test.png");
    }

}

0 个答案:

没有答案