Best way to implement REST API testing with Nightwatch.js - rest

I'm using Nightwatch-Cucumber that based on Nightwatch.js. And I want to integrate REST API tests in my Nightwatch framework. Currently I only have End2End tests based on Selenium, but in future I want to have both test types in one framework to make it also possible to use the End2End tests and the REST API tests in harmony within one Cucumber test. So, I want to combine both tests.
What is the best and smartest way to implement such REST API tests in my test framework based on Nightwatch-Cucumber? I've tried some stuff with frisby.js, but this framework uses Jasmine and Jest and it's not a good idea to use it in combination with Nightwatch and Cucumber.
Any recommendations?

You can use request-promise.
In nearest future, new version of nightwatch-cucumber will work with Jasmine and Jest too.

Related

Is it possible end-to-end tests using react-testing-library?

I know that we can test the component label test using the React Testing Library. But from my curiosity, I want to know that is there any way to do an end-to-end test on the react components using this library.
I'll be grateful if I get some nice information on it.
There's an example of using React Router within the RTL docs: https://testing-library.com/docs/example-react-router/ so it looks like it's possible. However, I'd recommend using a dedicated e2e testing library such as Cypress to do the job. There is an RTL integration for Cypress so you can follow the same testing principles that RTL advocates.

Automation testing for RestApi and UI in one application

I have an application in which I need to do UI testing as well as rest Api testing.Could anyone suggest me any testing tool for this.
My framework will be data driven.
Also, it is 20% UI and 80% rest api testing.
It is good that you have decided 80% API tests and 20% UI tests, which will satisfy the test automation pyramid. Well, the test tools and frameworks completely depend on your language of choice.
For API tests
Java -- RestAssured
Python -- requests library
For UI tests, Selenium webdriver is my preferred choice.
If you are starting test automation, I would suggest start with reading the documentation.

Rest Assured vs Cucumber

I know what Rest Assured is and for what purpose it is used and the same for the cucumber.
But the thing is what we can achieve with Rest Assured, we can also do with Cucumber for testing.
Rest Assured simply calls the web service and validates the response. We can't use Rest Assured during the Maven build because the service needs to be up and running.
But with Cucumber I can directly call the web service's business service layer and DOA layer and validate the response. Cucumber can invoke this at Maven build time.
So question is which one is better? I know we can use/integrate Cucumber with Rest Assured but.
Cucumber is a BDD tool and can be used to describe the expected behavior and use those descriptions as the basis for test automation.
RestAsured is a tool to test API's/http calls.
They do something different.
You could use them both: Cucumber to describe you functionality, and RestAssured to do http calls.
But with Cucumber i can directly call the web service's business service layer and doa layer and validate the response.
This is not necessarily true, and it has to do with the test level you want to achieve.
So if you just want to do tests on a unit level, then yes, you don't need to use REST assured, you can perfectly specify your tests with Cucumber feature files, and in the step definitions, you can test the service layer and the DOA layer directly, like you mentioned.
If you want to test a running instance of the webservice then you can use REST Assured or REST Assured plus Cucumber. REST Assured will only help you simplify the actual definition of each part of the test and the interactions with endpoints and its expectations, and Cucumber will allow you to define the high-level scenarios made of those steps.
So the question is which one is better? I knew we can use integrate cucumber with rest assured but.
All in all, it's not a matter of which one is better, but what level of testing you're trying to achieve and how you want to achieve it. A unit level you might not need REST assured. On an integration/live-execution level, then yes, you can use that library. In both levels, you can specify your tests using Cucumber.
Rest assured is java Api libraries to do automate REST web services. we can automated Rest apis by using BDD method,BDD is method and Cucumber is leading and free tool for that
Rest assured is not a tool it is a java library which we can use for test restful webservices, and yes cucumber is recommended to use because customer is giving better reporting which rest assured is not supporting to reports.
So I can recommend use cucumber framework to test API

Can we use Selenium Webdriver or Watir WebDriver to automate Restful API?

Can we use Selenium Webdriver or Watir WebDriver to automate Restful API?
Is there any tool that we can use to automate Restful API?
You could probably hack a horrible solution, but what you really want is rest-client:
https://github.com/rest-client/rest-client
It's designed for exactly the set of use cases that you're describing.
I've only used REST-Assured to populate test data for Selenium test which was very efficient.
Have a look at the API its simple to use and you can easily automate your Restful API alternatively SOAPUI will be your best bet.
https://code.google.com/p/rest-assured/
Not sure how one would use WebDriver for Restful API tests other than creating a UI that WebDriver would use. If that was the approach the tests would be much slower and more complicated than using rest-client.
We use rest-client, and prefer it over SoapUI because we also re-use the same code to set up and tear down Watir-WebDriver tests.
SoapUI works too and will likely deliver tests faster, but there is a lot of value in using rest-client to also keep the UI tests fast and reliable.
When considering load and performance tests, we are considering flood.io, SoapUI/LoadUI, and SOASTA. If we go with flood.io, we would still be using rest-client and re-using the same code for that as well.

how to use rest-assured for integration tests on my WS without modyfing database state?

I'm currently developping a REST Web service with Spring MVC.
And I am struggling to find the best way to do integration tests on my WS.
First solution : using rest-assured
Advantage : fluent api, really easy to use with its cool DSL
Drawback : when i perform POST or PUT requests on my WS, the state of my database is modified, and next tests are corrupted.
Second solution : unit test the controllers and perform integration tests at the service level separately
Advantage : i can control the state of my database, using Spring Test Framework and perform rollback after each test
Disadvantage : i do not perform end-to-end integration tests anymore.
Question : how can i use rest-assured to do integration tests without modifying the state of my database ?
Thanks a lot.
Why don't you delete the rest assured doubles and redirects before every test and set them up fresh for the test?
RestClient.delete "#{RestAssured::Server.address}/redirects/all"
RestClient.delete "#{RestAssured::Server.address}/doubles/all"
Or alternatively you can use different doubles for the GET and POST/PUT calls to the rest assured and use the redirects in between these calls.
I am not sure, your request makes sense as you state it.
RestAssured is just a framework to support you with testing. You can also write unit tests, that do the equivalent of PUT and DELETE (basically the internal implementations), which then modify the database state.
Or you can only issue HEAD and GET requests with RestAssured and not modify the database state by this.
Both of the options will only test parts of the code path if you leave any updates out, so your issue is orthogonal to the selection of RestAssured or hand written unit tests.
Of course you can mock your backend away, but either the mocks are trivial and you don't gain any insight. Or they are complex and you will need separate tests to assure that the mock objects to what you think they are doing.
In order to perform integration tests on a REST Spring MVC Web Service, the SpringSource team has provided a new library called spring-test-mvc, which is now integrate to spring-test.
http://blog.springsource.org/2012/11/12/spring-framework-3-2-rc1-spring-mvc-test-framework/
For my special purpose, it is more adapted than Rest-Assured.