Show Table of Content

Instruction: How to Execute GET/POST Requests

GET Request

  1. Go to Parameters tab and add a parameter with name url and some URL as a value (e.g. http://google.com?q=screenster)
  2. Create or edit test and add Selenium command with the next code:
     

    package commands;

    import com.agileengine.screenster.logic.browsers.Browser;
    import org.openqa.selenium.WebDriver;
    import java.util.Map;
    import utils.Screenster;
    import play.libs.WS;

    /**
    * This is an example test
    **/
    public class SeleniumCommand {
     /**
     * Main entry point, don’t rename this method, class and package
     **/
     public void run(WebDriver driver, Browser browser, Map parameters) throws Exception {
      String url = parameters.get(“url”);
      WS.HttpResponse response = WS.url(url).get();
      //if HTTP code is not 200 – fail test
      if (!response.getStatus().equals(200)) {
       Screenster.failTest(“HTTP code is wrong”);
      }
      //get response body
      String body = response.getString();
      //if body does not contain some text – fail test
      if (!body.contains(“screenster”)) {
       Screenster.failTest(“HTTP response is wrong”);
      }
     }
    }

POST Request

  1. Go to Parameters tab and add parameters:
     a) a parameter with name url and some URL as a value (e.g. http://google.com?q=screenster) and
     b) a parameter with name body and some value, an example is: {“name”: “json”}
  2. Create or edit test and add Selenium command with the next code:
     

    package commands;

    import com.agileengine.screenster.logic.browsers.Browser;
    import org.openqa.selenium.WebDriver;
    import java.util.Map;
    import utils.Screenster;
    import play.libs.WS;

    /**
    * This is an example test
    **/
    public class SeleniumCommand {
     /**
     * Main entry point, don’t rename this method, class and package
     **/
     public void run(WebDriver driver, Browser browser, Map parameters) throws Exception {
      String url = parameters.get(“url”);
      String body = parameters.get(“body”);
      WS.HttpResponse response = WS.url(url)
       .setHeader(“Content-Type”, “application/json”)
       .body(body)
       .post();
      //if HTTP code is not 200 – fail test
      if (!response.getStatus().equals(200)) {
       Screenster.failTest(“HTTP code is wrong”);
      }
     }
    }



Visit the Release History page to check what is new and what has been improved in your current Screenster version.



 

Want to try Screenster on the cloud?

Try Online


 

WordPress Image Lightbox Plugin