Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Grid plugin: create a separate video for each test #77

Closed
elgalu opened this issue Apr 20, 2016 · 2 comments
Closed

Grid plugin: create a separate video for each test #77

elgalu opened this issue Apr 20, 2016 · 2 comments

Comments

@elgalu
Copy link
Owner

elgalu commented Apr 20, 2016

Refs:
https://github.com/rossrowe/sauce-grid-plugin
https://github.com/freynaud/grid-plugin-tutorial
https://github.com/calabash-driver/grid-calabash-node-plugin
https://github.com/jenkinsci/selenium-plugin
https://github.com/groupon/Selenium-Grid-Extras

@elgalu
Copy link
Owner Author

elgalu commented Apr 28, 2016

Also read blog post http://qa-automation-notes.blogspot.de/2016/04/docker-selenium-and-bit-of-allure-how.html

Now we need to create a HubProxy, which will intercept sessions

@Override
public void beforeSession(final TestSession session) {
 super.beforeSession(session);
 processRecording(session, Command.START_RECORDING);
}

@Override
public void afterSession(final TestSession session) {
 super.afterSession(session);
 processRecording(session, Command.STOP_RECORDING);
}

private void processRecording(final TestSession session, final Command command) {
 final String videoInfo = getCapability(session, "videoInfo");

 if (!videoInfo.isEmpty()) {
  final String url = "http://" + this.getRemoteHost().getHost() + ":" + this.getRemoteHost().getPort() +
   "/extra/" + VideoRecordingServlet.class.getSimpleName() + "?command=" + command;

  switch (command) {
   case START_RECORDING:
    sendRecordingRequest(url, videoInfo);
    break;
   case STOP_RECORDING:
    sendRecordingRequest(url, "");
    break;
  }
 }
}

private void sendRecordingRequest(final String url, final String entity) {
 CloseableHttpResponse response = null;

 try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
  final HttpPost post = new HttpPost(url);

  if (!entity.isEmpty()) {
   post.setEntity(new StringEntity(entity, ContentType.APPLICATION_JSON));
  }

  response = client.execute(post);
  LOGGER.info("Node response: " + response);
 } catch (Exception ex) {
  LOGGER.severe("Unable to send recording request to node: " + ex);
 } finally {
  HttpClientUtils.closeQuietly(response);
 }
}

Note that we're getting video options from end-user in a form of DesiredCapabilities. It means that on proxy level we need to retrieve corresponding json and put it into request's entity, which will be sent then to VideoRecordingServlet.
That's it. Now you can rebuild selenium-server-standalone.jar with video recording feature on board using maven-assembly-plugin.
Modify NodeChrome / NodeFirefox config.json to allow our custom servlet and proxy support.

{
  "capabilities": [
    {
      "browserName": "chrome",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "configuration": {
    "proxy": "com.blogspot.notes.automation.qa.grid.HubProxy",
    "servlets": "com.blogspot.notes.automation.qa.grid.VideoRecordingServlet",
    "maxSession": 1,
    "port": 5555,
    "register": true,
    "registerCycle": 5000
  }
}

Usage

private Capabilities getCapabilities() {
 DesiredCapabilities capabilities = new DesiredCapabilities();
 capabilities.setBrowserName(getBrowser());
 capabilities.setPlatform(getDefaultPlatform());

 String videoInfo = getVideoRecordingInfo();
 if (!videoInfo.isEmpty()) {
  capabilities.setCapability("videoInfo", videoInfo);
 }

 return capabilities;
}

public String getVideoRecordingInfo() {
 try {
  VideoInfo videoInfo = new VideoInfo("/e2e/uploads", getVideoRecordingPath(), 18, 25);
  return new ObjectMapper().writeValueAsString(videoInfo);
 } catch (Exception ignored) {
  return "";
 }
}

@elgalu
Copy link
Owner Author

elgalu commented Nov 10, 2016

Closed via zalando/zalenium#17 thanks @diemol !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant