Can Twist use a browser that is open?

Comments

2 comments

  • Avatar
    Prateek Kumar Baheti

    Twist currently cannot use an already open browser. The browser instance needs to be launched by twist. 

    0
    Comment actions Permalink
  • Avatar
    Gennadiy Kasyan

    Theoretically, you can attach with a RemoteWebDriver to already opened IE if you have the session id.

    Please have a look on ReusableRemoteWebDriver.java on GitHub and the RemoteWebDriver.java Selenium source code.

    You need to modify ReusableRemoteWebDriver.java, override  protected void startSession(Capabilities desiredCapabilities, Capabilities requiredCapabilities) in a similar way.

    JS execution will not work if you attach to an open IE.

    To enable it, add to the ReusableRemoteWebDriver.java

    private Capabilities capabilities

    @Override
    public Capabilities getCapabilities() {
    return capabilities;
    }

    private boolean isJavascriptEnabled() {
    return capabilities.isJavascriptEnabled();
    }

    public Object executeScript(String script, Object... args) {
    if (!capabilities.isJavascriptEnabled()) {
    throw new UnsupportedOperationException(
    "You must be using an underlying instance of WebDriver that supports executing javascript");
    }

    // Escape the quote marks
    script = script.replaceAll("\"", "\\\"");

    Iterable<Object> convertedArgs = Iterables.transform(
    Lists.newArrayList(args), new WebElementToJsonConverter());

    Map<String, ?> params = ImmutableMap.of(
    "script", script,
    "args", Lists.newArrayList(convertedArgs));

    return execute(DriverCommand.EXECUTE_SCRIPT, params).getValue();
    }
    }

    0
    Comment actions Permalink

Please sign in to leave a comment.