Skip to content
This repository was archived by the owner on Feb 10, 2020. It is now read-only.

Added API tests for file upload and file download #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

nikolay-advolodkin
Copy link

This is a new convention that we don't really have in any of our automation where we are mixing API and UI tests using Cucumber. We are always preaching to our clients to do this, but we don't have an example. I created such examples for commonly asked scenarios of testing file upload and download. These suites may not be complete, but it should give clients a good idea into how to proceed forward.

Please take a look at the new API tests I added and if you like my implementation

@sauceaaron
Copy link

sauceaaron commented Mar 12, 2019 via email


@Given("I have a File")
public void iHaveAFile() {
filePath = "https://the-internet.herokuapp.com/download/some-file.txt";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use RestAssured's given().baseUri(url) and when().get(path) with Cucumber


@Then("The file is successfully downloaded")
public void theFileIsSuccessfullyDownloaded() {
webResponse.then().statusCode(200);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the time, you don't want to download the file -- just check that it can be downloaded:

Instead of get(url).statusCode(200);
you can do head(url).statusCode(200); and save bandwidth.

Unless, of course, you're inspecting the file, as you're doing here. But do you really want to inspect the file, or is this just a contrived example?

@@ -32,7 +34,7 @@
private final String BASE_URL = "https://www.saucedemo.com";
private SauceUtils sauceUtils;

@Before
@Before("not @api")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why separate API/Not API. I think the most common use case would be to use the API in conjunction with Selenium -- you sign up, navigate to the download page, and then get the download URL in Selenium, then use the HTTP client to do the actual download.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if I don't do this then a VM session is created for every single one of my API tests. I don't need a VM for my API test.

@mmerrell-sauce
Copy link
Contributor

mmerrell-sauce commented Mar 12, 2019

File download is not really a REST API action

This really clicked for me--we should be using more standard HTTP library stuff for performing what amounts to an API operation, rather than using RestAssured, which is a testing engine. We're not testing the API at this point, we're performing an operation.

I understand, @nikolay-advolodkin , if you don't know how to do that in Java... it's... painful. But I agree with the overall point, that we probably shouldn't do it here.

@fijiaaron do you think this should be in a Gist, linked from here? or from the Sauce wiki, like you indicated?

@sauceaaron
Copy link

sauceaaron commented Mar 12, 2019 via email

@sauceaaron
Copy link

sauceaaron commented Mar 12, 2019 via email

@nikolay-advolodkin
Copy link
Author

nikolay-advolodkin commented Mar 13, 2019 via email

@nikolay-advolodkin
Copy link
Author

File download is not really a REST API action

This really clicked for me--we should be using more standard HTTP library stuff for performing what amounts to an API operation, rather than using RestAssured, which is a testing engine. We're not testing the API at this point, we're performing an operation.

I understand, @nikolay-advolodkin , if you don't know how to do that in Java... it's... painful. But I agree with the overall point, that we probably shouldn't do it here.

@fijiaaron do you think this should be in a Gist, linked from here? or from the Sauce wiki, like you indicated?

@mmerrell-sauce agreed on the REST Assured stuff. I wasn't aware of another HTTP client, so I just went with this one. I will update to use some other HTTP client 👍

However, I would still like to clarify one point on which we seem to be on a different page. Just for my understanding, are you suggesting that we should leave the integration of API and UI automation into a sample framework up to our client?

This was actually the hardest part and nobody on the SA team knew how to combine API/UI automation into a single Cucumber framework that runs in parallel. As a result, I spent a few hours to resolve this problem. If we move this example into it is own repo or Git Gist, then we are leaving the client with the responsibility of figuring out how to integrate API and UI automation into a single framework and make it work correctly.

If that's what we want to do as a team, then that's the decision. But it seems scary to me that a couple of expert SAs took hours to resolve this issue, meaning it was tough. And we will obscure that solution from that client and will just leave it on them to figure it out.

Again, fine if we want to do that. I just wanted to make sure that we all understand the consequences of separating this example out 👍

@sauceaaron
Copy link

sauceaaron commented Mar 18, 2019 via email

@mmerrell-sauce
Copy link
Contributor

mmerrell-sauce commented Mar 18, 2019 via email

@nikolay-advolodkin
Copy link
Author

nikolay-advolodkin commented Mar 18, 2019 via email

@mmerrell-sauce
Copy link
Contributor

mmerrell-sauce commented Mar 18, 2019 via email

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

Successfully merging this pull request may close these issues.

5 participants