Skip to content
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

Implementing flick action in ajio mobile #241

Merged
merged 4 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/com/znsio/teswiz/runner/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,4 +603,24 @@ public void doubleTap(WebElement element) {
.addAction(touch.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
appiumDriver.perform(Arrays.asList(clickPosition));
}


public void flick() {
AppiumDriver appiumDriver = (AppiumDriver) this.driver;
Dimension screenSize = driver.manage().window().getSize();

int startX = screenSize.width - 100;
int startY = screenSize.height / 2;
int endX = screenSize.width / 2;
int endY = screenSize.height / 2;

PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
anandbagmar marked this conversation as resolved.
Show resolved Hide resolved
Sequence flick = new Sequence(finger, 0);
flick.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), startX, startY));
flick.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
flick.addAction(finger.createPointerMove(Duration.ofMillis(100), PointerInput.Origin.viewport(), endX, endY));
flick.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));

appiumDriver.perform(Arrays.asList(flick));
}
}
47 changes: 47 additions & 0 deletions src/test/java/com/znsio/teswiz/businessLayer/ajio/HomeBL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.znsio.teswiz.businessLayer.ajio;

import com.context.TestExecutionContext;
import com.znsio.teswiz.entities.Platform;
import com.znsio.teswiz.entities.SAMPLE_TEST_CONTEXT;
import com.znsio.teswiz.runner.Runner;
import com.znsio.teswiz.screen.ajio.HomeScreen;
import org.apache.log4j.Logger;
import org.assertj.core.api.SoftAssertions;
import static org.assertj.core.api.Assertions.assertThat;

public class HomeBL {
private static final Logger LOGGER = Logger.getLogger(HomeBL.class.getName());
private final TestExecutionContext context;
private final SoftAssertions softly;
private final String currentUserPersona;
private final Platform currentPlatform;

public HomeBL(String userPersona, Platform forPlatform) {
long threadId = Thread.currentThread().getId();
this.context = Runner.getTestExecutionContext(threadId);
softly = Runner.getSoftAssertion(threadId);
this.currentUserPersona = userPersona;
this.currentPlatform = forPlatform;
Runner.setCurrentDriverForUser(userPersona, forPlatform, context);
}

public HomeBL() {
long threadId = Thread.currentThread().getId();
this.context = Runner.getTestExecutionContext(threadId);
softly = Runner.getSoftAssertion(threadId);
this.currentUserPersona = SAMPLE_TEST_CONTEXT.ME;
this.currentPlatform = Runner.getPlatform();
}


public HomeBL openProduct(String product,String category, String gender) {
assertThat(HomeScreen.get()
.goToMenu()
.selectProductFromCategory(product,category,gender)
.isProductListLoaded(product))
.as("Selected Product list is not loaded")
.isTrue();
return this;

}
}
52 changes: 52 additions & 0 deletions src/test/java/com/znsio/teswiz/businessLayer/ajio/ProductBL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.znsio.teswiz.businessLayer.ajio;

import com.context.TestExecutionContext;
import com.znsio.teswiz.entities.Platform;
import com.znsio.teswiz.entities.SAMPLE_TEST_CONTEXT;
import com.znsio.teswiz.runner.Runner;
import com.znsio.teswiz.screen.ajio.ProductScreen;
import com.znsio.teswiz.screen.ajio.SearchScreen;
import org.apache.log4j.Logger;
import org.assertj.core.api.SoftAssertions;
import static org.assertj.core.api.Assertions.assertThat;

public class ProductBL {
private static final Logger LOGGER = Logger.getLogger(ProductBL.class.getName());
private final TestExecutionContext context;
private final SoftAssertions softly;
private final String currentUserPersona;
private final Platform currentPlatform;

public ProductBL(String userPersona, Platform forPlatform) {
long threadId = Thread.currentThread().getId();
this.context = Runner.getTestExecutionContext(threadId);
softly = Runner.getSoftAssertion(threadId);
this.currentUserPersona = userPersona;
this.currentPlatform = forPlatform;
Runner.setCurrentDriverForUser(userPersona, forPlatform, context);
}

public ProductBL() {
long threadId = Thread.currentThread().getId();
this.context = Runner.getTestExecutionContext(threadId);
softly = Runner.getSoftAssertion(threadId);
this.currentUserPersona = SAMPLE_TEST_CONTEXT.ME;
this.currentPlatform = Runner.getPlatform();
}

public ProductBL selectTheFirstResultFromList() {
assertThat(SearchScreen.get()
.selectProduct()
.isProductDetailsLoaded())
.as("Product Details is not loaded")
.isTrue();
return this;
}

public ProductBL flickAndViewImages() {
String finalElementId = ProductScreen.get().flickImage().isElementIdChanged();
String initialElementId = (String) context.getTestState(SAMPLE_TEST_CONTEXT.INITIAL_ELEMENT_ID);
assertThat(initialElementId).as("Unable to perform flick action").isNotEqualTo(finalElementId);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public class SAMPLE_TEST_CONTEXT
public static final String MEETING_ID = "meetingId";
public static final String MEETING_PASSWORD = "meetingPassword";
public static final String INVITATION_LINK = "invitationLink";
public static final String INITIAL_ELEMENT_ID = "elementId";

}
4 changes: 4 additions & 0 deletions src/test/java/com/znsio/teswiz/screen/ajio/HomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ public static HomeScreen get() {
public abstract SearchScreen searchByImage();

public abstract HomeScreen attachFileToDevice(Map imageData);

public abstract HomeScreen goToMenu();

public abstract SearchScreen selectProductFromCategory(String product, String category, String gender);
}
7 changes: 7 additions & 0 deletions src/test/java/com/znsio/teswiz/screen/ajio/ProductScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public static ProductScreen get() {
public abstract CartScreen addProductToCart();

public abstract String getProductName();

public abstract boolean isProductDetailsLoaded();

public abstract ProductScreen flickImage();

public abstract String isElementIdChanged();

}
5 changes: 4 additions & 1 deletion src/test/java/com/znsio/teswiz/screen/ajio/SearchScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ public static SearchScreen get() {

public abstract int numberOfProductFound();

public abstract void selectProduct();
public abstract ProductScreen selectProduct();

public abstract boolean isProductListLoaded(String product);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class HomeScreenAndroid
"com.android.permissioncontroller:id/permission_message");
private static final By byAllowButtonId = By.id(
"com.android.permissioncontroller:id/permission_allow_button");
private static final By bySideMenuId = By.id("com.ril.ajio:id/fahIvMenu");
private static final String byFilterProductXpath = "//android.widget.TextView[@text='%s']";
private final Driver driver;
private final Visual visually;

Expand Down Expand Up @@ -62,4 +64,22 @@ public HomeScreen attachFileToDevice(Map imageData) {
return this;
}


@Override
public HomeScreen goToMenu() {
LOGGER.info("Opening Side Drawer Menu");
driver.waitTillElementIsVisible(bySideMenuId).click();
return this;
}

@Override
public SearchScreen selectProductFromCategory(String product, String category, String gender) {
LOGGER.info(String.format("Selecting %s for %s", product, gender));
driver.waitTillElementIsVisible(By.xpath(String.format(byFilterProductXpath, gender))).click();
driver.scrollVertically(20,60,50);
driver.waitTillElementIsVisible(By.xpath(String.format(byFilterProductXpath, category))).click();
driver.waitTillElementIsVisible(By.xpath(String.format(byFilterProductXpath, product))).click();
return SearchScreen.get();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.znsio.teswiz.screen.android.ajio;

import com.context.TestExecutionContext;
import com.znsio.teswiz.entities.SAMPLE_TEST_CONTEXT;
import com.znsio.teswiz.runner.Driver;
import com.znsio.teswiz.runner.Runner;
import com.znsio.teswiz.runner.Visual;
import com.znsio.teswiz.screen.ajio.CartScreen;
import com.znsio.teswiz.screen.ajio.ProductScreen;
Expand All @@ -17,12 +20,17 @@ public class ProductScreenAndroid
private static final By byViewBagButtonXpath = By.xpath(
"//android.widget.TextView[@text='View Bag']");
private static final By byBrandNameId = By.id("com.ril.ajio:id/product_name");
private static final By byProductImageId = By.id("com.ril.ajio:id/pdp_product_img");
private final TestExecutionContext context;

private final Driver driver;
private final Visual visually;

public ProductScreenAndroid(Driver driver, Visual visually) {
this.driver = driver;
this.visually = visually;
long threadId = Thread.currentThread().getId();
context = Runner.getTestExecutionContext(threadId);
}

@Override
Expand All @@ -47,4 +55,33 @@ public String getProductName() {
return productName;
}

@Override
public boolean isProductDetailsLoaded() {
LOGGER.info("Verifying if Product Details page is loaded");
boolean isProductedLoaded = false;
driver.tapOnMiddleOfScreen();
driver.waitTillElementIsPresent(byProductImageId);
driver.findElement(byProductImageId).click();
if (driver.isElementPresent(byProductImageId)) {
isProductedLoaded = true;
}
return isProductedLoaded;
}

@Override
public ProductScreen flickImage() {
LOGGER.info("Performing flick to view multiple product images");
driver.findElement(byProductImageId).click();
String initialElementId = driver.findElement(byProductImageId).getAttribute("bounds");
context.addTestState(SAMPLE_TEST_CONTEXT.INITIAL_ELEMENT_ID, initialElementId);
driver.flick();
return this;
}

@Override
public String isElementIdChanged() {
LOGGER.info("Verifying if flick happened");
visually.checkWindow(SCREEN_NAME, "Other images are visible");
return driver.findElement(byProductImageId).getAttribute("bounds");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.znsio.teswiz.runner.Driver;
import com.znsio.teswiz.runner.Visual;
import com.znsio.teswiz.screen.ajio.ProductScreen;
import com.znsio.teswiz.screen.ajio.SearchScreen;
import org.apache.log4j.Logger;
import org.openqa.selenium.By;
Expand All @@ -15,6 +16,8 @@ public class SearchScreenAndroid
private static final Logger LOGGER = Logger.getLogger(SCREEN_NAME);
private static final By byResultsId = By.id("com.ril.ajio:id/tv_count_plp_header_is");
private static final By byProductId = By.id("com.ril.ajio:id/plp_row_product_iv");
private static final By byProductListTitleId = By.id("com.ril.ajio:id/toolbar_title_tv");
public static final By byProductLayoutId = By.id("com.ril.ajio:id/layout_category_container");
Copy link
Contributor

Choose a reason for hiding this comment

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

public variable?
are you using this VAR in another class?

private final Driver driver;
private final Visual visually;

Expand All @@ -33,10 +36,23 @@ public int numberOfProductFound() {
}

@Override
public void selectProduct() {
LOGGER.info("selection of Product in the result page");
driver.waitTillElementIsPresent(By.id("com.ril.ajio:id/layout_category_container")).click();
public ProductScreen selectProduct() {
LOGGER.info("Selection of Product in the result page");
if (!(driver.isElementPresent(byProductLayoutId))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need extra braces in if condition?
if(!driver.isElementPresent(byProductLayoutId))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes - when we land on the AJIO app on the first time - few sections got highlighted - and web elements are present below these elements

driver.tapOnMiddleOfScreen();
}
List<WebElement> list = driver.waitTillPresenceOfAllElements(byProductId);
list.get(0).click();
return ProductScreen.get();
}

@Override
public boolean isProductListLoaded(String product) {
LOGGER.info(String.format("Verifying if %s list is loaded",product));
raghavgarg1996 marked this conversation as resolved.
Show resolved Hide resolved
if (!(driver.isElementPresent(byProductListTitleId)))
driver.tapOnMiddleOfScreen();
String productLoaded = driver.waitTillElementIsVisible(byProductListTitleId).getText().trim();
LOGGER.info("Loaded product: " +productLoaded);
return productLoaded.contains(product);
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/znsio/teswiz/steps/AjioSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.context.SessionContext;
import com.context.TestExecutionContext;
import com.znsio.teswiz.businessLayer.ajio.HomeBL;
import com.znsio.teswiz.businessLayer.ajio.ProductBL;
import com.znsio.teswiz.businessLayer.ajio.SearchBL;
import com.znsio.teswiz.runner.Runner;
import com.znsio.teswiz.runner.Drivers;
Expand Down Expand Up @@ -41,4 +43,21 @@ public void iShouldSeeTheProductInTheCart() {
SAMPLE_TEST_CONTEXT.ME));
new SearchBL().verifyCart();
}

@Given("I open {string} from {string} section for {string}")
public void iOpebShirtsSectionForMen(String product, String category, String gender) {
Drivers.createDriverFor(SAMPLE_TEST_CONTEXT.ME, Runner.getPlatform(), context);
new HomeBL().openProduct(product,category, gender);
}


@When("I select the first result")
public void iSelectTheFirstResult() {
new ProductBL().selectTheFirstResultFromList();
}

@Then("I should be able to perform flick and view images")
public void iShouldBeAbleToPerformFlickAndViewImages() {
new ProductBL().flickAndViewImages();
}
}
9 changes: 8 additions & 1 deletion src/test/resources/com/znsio/teswiz/features/ajio.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ Feature: Ajio tests
Scenario: As a guest user, I should be able to look for a product using image search and prepare a cart
Given I search for products using "image"
When I add the product to the cart
Then I should see the product in the cart
Then I should see the product in the cart

# CONFIG=./configs/ajio_local_config.properties TAG=@flick PLATFORM=android ./gradlew run
@android @flick
Scenario: As a guest user, I should be able to flick and see images in product details
Given I open "Jackets" from "Topwear" section for "Men"
When I select the first result
Then I should be able to perform flick and view images