-
Notifications
You must be signed in to change notification settings - Fork 1
Hometask/a.korobitsyna #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: inclass
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package skeleton; | ||
|
|
||
| import cucumber.api.java.en.Given; | ||
| import cucumber.api.java.en.Then; | ||
| import cucumber.api.java.en.When; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| /** | ||
| * Created by korobitsyna on 5/24/15. | ||
| */ | ||
| public class ListSteps { | ||
|
|
||
| private ArrayList<String> testList; | ||
| private String testString = "String"; | ||
|
|
||
| @Given("I have an empty list") | ||
| public void i_have_an_empty_list() { | ||
| testList = new ArrayList<String>(); | ||
| } | ||
|
|
||
| @Given("I have a list with (\\d+) elements") | ||
| public void i_have_a_list_with_elements(int quantity) { | ||
| testList = new ArrayList<String>(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FIY |
||
| for(int i = 0; i < quantity; i++) { | ||
| testList.add(testString); | ||
| } | ||
| } | ||
|
|
||
| @When("I add string \"(.*?)\" to a list") | ||
| public void i_add_string_to_list(String s) { | ||
| testList.add(s); | ||
| } | ||
|
|
||
| @When("I remove last element") | ||
| public void i_remove_element() { | ||
| testList.remove(testList.size()-1); | ||
| } | ||
|
|
||
| @Then("List length is (\\d+)") | ||
| public void list_length(int length) { | ||
| assertEquals(length, testList.size()); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI |
||
| } | ||
|
|
||
| @Then("List contains string \"(.*?)\"$") | ||
| public void list_contains_string(String s) { | ||
| assertTrue(testList.contains(s)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI |
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import cucumber.api.java.en.Given; | ||
| import cucumber.api.java.en.Then; | ||
| import cucumber.api.java.en.When; | ||
| import org.json.JSONArray; | ||
| import org.json.JSONObject; | ||
| import sun.misc.IOUtils; | ||
|
|
||
|
|
@@ -20,6 +21,7 @@ | |
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| /** | ||
| * @author Alexey Lyanguzov | ||
|
|
@@ -46,7 +48,7 @@ public void sum_must_be(int sum) { | |
|
|
||
| @Given("^I have no users$") | ||
| public void i_have_no_users() { | ||
| doRequest(Unirest.delete(usersBaseUrl)); | ||
| i_delete_all_users(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good! |
||
| } | ||
|
|
||
| @When("^I add users$") | ||
|
|
@@ -60,12 +62,53 @@ public void i_add_users(List<User> users) { | |
| } | ||
| } | ||
|
|
||
| @When("I delete user (.*?)$") | ||
| public void i_delete_user(String email) { | ||
| doRequest( | ||
| Unirest.delete(usersBaseUrl).queryString("email", email) | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| @When("I delete all users") | ||
| public void i_delete_all_users() { | ||
| doRequest(Unirest.delete(usersBaseUrl)); | ||
| } | ||
|
|
||
| @When("I edit user (.*?) with (.*?) and (.*?)$") | ||
| public void i_edit_user(String email, String newFirstname, String newLastname) { | ||
|
|
||
| doRequest( | ||
| Unirest.post(usersBaseUrl + "/edit") | ||
| .queryString("email", email) | ||
| .body("{\"firstName\":\"" + newFirstname + "\",\"lastName\":\"" + newLastname + "\"}") | ||
| .getHttpRequest() | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| @Then("^there are (\\d+) users$") | ||
| public void there_are_users(int expectedUsersCount) { | ||
| doRequest(Unirest.get(usersBaseUrl)); | ||
| int actualUsersCount = response.getBody().getObject().getJSONArray("users").length(); | ||
| assertEquals("BBB!", expectedUsersCount, actualUsersCount); | ||
| } | ||
|
|
||
| @Then("User (.*?) has firstname (.*?) and lastname (.*?)$") | ||
| public void user_has_credentials(String email, String firstname, String lastname) { | ||
| doRequest(Unirest.get(usersBaseUrl)); | ||
| JSONArray users = response.getBody().getObject().getJSONArray("users"); | ||
| int index; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int index is excess.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can compare within the 'for' loop just after you have find a user. |
||
| for(index = 0; index < users.length(); index++) { | ||
| JSONObject userRecord = users.getJSONObject(index); | ||
| if (userRecord.getString("email").equals(email)) break; | ||
|
|
||
| } | ||
| String actualFirstname = users.getJSONObject(index).getString("first_name"); | ||
| String actualLastname = users.getJSONObject(index).getString("last_name"); | ||
|
|
||
| assertTrue(actualFirstname.equals(firstname) && actualLastname.equals(lastname)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Such assertTrue is not good practice. It's not clear what has really happened. Better than better solution 1 is better solution 2. It requires some additional work but I'll always advocate for using such an approach.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solution 2 might look a little bit complicated but it's the best one when you have dozens of tests. I can show how code might actually look late if you are interesting. (Now I do not have IDE and have only HTTP access to github). |
||
| } | ||
|
|
||
| private void doRequest(HttpRequest request){ | ||
| response = null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Feature: test java.util.ArrayList | ||
|
|
||
| @my | ||
| Scenario: empty list length | ||
| Given I have an empty list | ||
| Then List length is 0 | ||
| @my | ||
| Scenario: add element to list | ||
| Given I have an empty list | ||
| When I add string "abc" to a list | ||
| Then List contains string "abc" | ||
| @my | ||
| Scenario: remove element from list | ||
| Given I have a list with 5 elements | ||
| When I remove last element | ||
| Then List length is 4 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,39 @@ Feature: test through Rest | |
| | u1@a.b | aa | bb | | ||
| | u2@c.d | cc | dd | | ||
| Then there are 2 users | ||
|
|
||
| #Homework test scenarios | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good! |
||
| @my | ||
| Scenario: delete a user | ||
| Given I have no users | ||
| And I add users | ||
| | email | firstName | lastName | | ||
| | test1@mail.com | test1FirstName | test1LastName | | ||
| | test2@mail.com | test2FirstName | test2LastName | | ||
| When I delete user test1@mail.com | ||
| Then there are 1 users | ||
| @my | ||
| Scenario: delete all users | ||
| Given I add users | ||
| | email | firstName | lastName | | ||
| | test3@mail.com | test3FirstName | test3LastName | | ||
| | test4@mail.com | test4FirstName | test4LastName | | ||
| When I delete all users | ||
| Then there are 0 users | ||
|
|
||
| @my | ||
| Scenario Outline: editing users | ||
| Given I have no users | ||
| And I add users | ||
| | email | firstName | lastName | | ||
| | <email> | <oldFirstname> | <oldLastname> | | ||
| When I edit user <email> with <newFirstname> and <newLastname> | ||
| Then User <email> has firstname <newFirstname> and lastname <newLastname> | ||
|
|
||
| #test valid editing, test editing with empty fields | ||
| Examples: | ||
| | email | oldFirstname | oldLastname | newFirstname | newLastname | | ||
| | test1@mail.com | oldfirstname1 | oldlastname1 | newf1 | newl1 | | ||
| | test1@mail.com | oldfirstname1 | oldlastname1 | | | | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,32 @@ Feature: Selenium WebDriver | |
| When I try to return back | ||
| Then text 'Wow! You have clicked me!' is shown | ||
| And About page is still opened | ||
|
|
||
|
|
||
|
|
||
| #Homework test scenarios | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good! |
||
| @my | ||
| Scenario: list users | ||
| Given I have no users | ||
| And I add users | ||
| | email | firstName | lastName | | ||
| | test1@mail.com | test1FirstName | test1LastName | | ||
| | test2@mail.com | test2FirstName | test2LastName | | ||
| And I am on home page | ||
| When I go to List User page | ||
| Then List User page is opened | ||
| And User table contains 2 records | ||
|
|
||
| @my | ||
| Scenario: list empty user list | ||
| Given I have no users | ||
| And I am on home page | ||
| When I go to List User page | ||
| Then List User page is opened | ||
| And User table contains 0 records | ||
| When I add users | ||
| | email | firstName | lastName | | ||
| | test1@mail.com | test1FirstName | test1LastName | | ||
| And I reload the page | ||
| Then User table contains 1 records | ||
| And User test1@mail.com is on the list | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI
Here, usage of ArrayList as an argument type might be correct because we are testing this Java's class.
Usually it's always better to use interface List rather than ArrayList:
private List testLst;