Skip to content

Commit

Permalink
framework is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
EserQA committed Apr 17, 2024
1 parent a398ac4 commit ecb6fe9
Show file tree
Hide file tree
Showing 9 changed files with 452 additions and 83 deletions.
8 changes: 4 additions & 4 deletions configuration.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
browser:chrome
url:https://www.saucedemo.com/
username :standard_user
password:secret_sauce
browser=chrome
url=https://www.saucedemo.com/
username =standard_user
password=secret_sauce

32 changes: 12 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,33 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.0</version>
<version>4.18.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.7.0</version>
<version>7.16.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.7.0</version>
<version>7.16.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand All @@ -55,7 +48,7 @@
<testFailureIgnore>true</testFailureIgnore>
<runOrder>Alphabetical</runOrder>
<includes>
<include>**/*CukesRunner.java</include>
<include>**/*TestRunner.java</include>
<include>**/*FailedTestRunner.java</include>
</includes>
</configuration>
Expand Down Expand Up @@ -85,5 +78,4 @@

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

)

public class CukesRunner {
public class TestRunner {

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import com.saucedemo.pages.LoginPage;
import com.saucedemo.utilities.ConfigurationReader;
import com.saucedemo.utilities.Driver;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.Random;

public class BuyAnyItemStepDefs {
Expand Down Expand Up @@ -49,7 +51,7 @@ public void the_user_clicks_login_button() {
public void the_user_logins_and_lands_on_page_successfully(String expectedUrl) {

String actualUrl = Driver.get().getCurrentUrl();
Assert.assertEquals("The url does NOT match",expectedUrl,actualUrl);
Assert.assertEquals("The url does NOT match", expectedUrl, actualUrl);
}

@Given("the user clicks any add to cart button")
Expand All @@ -58,10 +60,8 @@ public void the_user_clicks_any_add_to_cart_button() {
Random rn = new Random();
int anyItem = rn.nextInt(inventoryPage.addToCartBtn.size());

WebDriverWait wait = new WebDriverWait(Driver.get(),5);
WebDriverWait wait = new WebDriverWait(Driver.get(), Duration.ofSeconds(5));
wait.until(ExpectedConditions.elementToBeClickable(inventoryPage.cartIcon));
System.out.println("new InventoryPage().addToCartBtn.size() = " + inventoryPage.addToCartBtn.size());

inventoryPage.addToCartBtn.get(anyItem).click();
}

Expand Down Expand Up @@ -111,6 +111,6 @@ public void the_user_clicks_finish_button() {
public void the_user_buys_any_item_and_see_the_following_message(String expectedMsg) {

String actualMsg = checkoutPage.checkoutMessage.getText().trim();
Assert.assertEquals("The user does NOT buy any item",expectedMsg,actualMsg);
Assert.assertEquals("The user does NOT buy any item", expectedMsg, actualMsg);
}
}
6 changes: 5 additions & 1 deletion src/test/java/com/saucedemo/stepdefinitions/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

import java.time.Duration;

public class Hooks {
@Before
public void setUp(){Driver.get().get(ConfigurationReader.get("url"));}
public void setUp(){
Driver.get().manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
Driver.get().get(ConfigurationReader.get("url"));}

@After
public void tearDown(Scenario scenario){
Expand Down
41 changes: 41 additions & 0 deletions src/test/java/com/saucedemo/utilities/ApiUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.saucedemo.utilities;

import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.openqa.selenium.WebDriverException;

import static io.restassured.RestAssured.*;

public class ApiUtils {

public static String generateToken(String email, String password) {

String payload = "{\n" +
" \"email\": \"" + email + "\",\n" +
" \"password\": {\n" +
" \"value\": \"" + password + "\"\n" +
" }\n" +
"}";

Response response = given().contentType(ContentType.JSON)
.and()
.header("api-key", ConfigurationReader.get("api-key"))
.header("idempotency-ref", "eser")
.and()
.body(payload)
.when()
.post(ConfigurationReader.get("apiUrl") + "/gateway/login");


if (response.statusCode() != 200) {

response.prettyPrint();
throw new WebDriverException("Token does NOT generated");
}

String token = response.path("token");
String bearerToken = "Bearer " + token;

return bearerToken;
}
}
Loading

0 comments on commit ecb6fe9

Please sign in to comment.