Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
1.2k views
by Contributing Tester (54 points)
edited by

Hi all,

I am automating API using rest-assured tool, using JAVA.

My approach is as follows:

package com.restapi.test;

        import com.jayway.restassured.RestAssured;
        import org.testng.annotations.BeforeClass;

    public class baseUrl {
        @BeforeClass
        public void setup() {

            String basePath = System.getProperty("server.base");
            if(basePath==null){
                basePath = "/tbiauth/";
            }
            RestAssured.basePath = basePath;

            String baseHost = System.getProperty("server.host");
            if(baseHost==null){
                baseHost = "http://192.168.1.3";
            }
            RestAssured.baseURI = baseHost;

        }

    }
    package com.restapi.test;

    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;

    import static com.jayway.restassured.RestAssured.given;
    import static org.hamcrest.CoreMatchers.containsString;

    public class KioskRegister extends baseUrl{

        @Test(dataProvider = "start")
        public void md5JsonTest(String access,String device ,String id,String md5Hash) {

            given().
                    parameters("s",access).parameters("m",device).parameters("d",id).
                    when().
                    get("/register/device").

                    then().
                    assertThat().


                    body(containsString(md5Hash));

        }

        @DataProvider(name = "start")
        public Object[][] createMD5TestData() {

            return new String[][] {
                    {"723efb","123456789","17","REG_DEV_EXISTS_1_00"},
                    {"723efb","","17","REG_DEV_PRMS_2_00"},
                    {"","123456789","17","REG_DEV_PRMS_1_00"},
                    {"723efb","123456789","","REG_DEV_PRMS_3_00"},



            };
        }
    }

Is my apporach right?

Is there any better approach to this?

2 Answers

0 like 0 dislike
by The go-to Tester (143 points)
selected by
 
Best answer

There is no best practice because technology is rest-assured.

We use cucumber to organize our tests. Some of the tests are UI oriented while others are API focused. For the latter, we use a mixture of rest-assured and DAO (for accessing database and business intelligence data warehouse back ends).

Cucumber supports Behavior Driven Development. Some of the Given, When, Then statements implement web testing. 

UI-based test execution is time-consuming. Endpoint tests and back-end tests have much shorter elapsed execution times. So using a testing pyramid only a small percentage of your tests should be UI focused.

Lastly, we execute our features in parallel to minimize total execution elapsed time.

0 like 0 dislike
by


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...