How to check ascending and descending order with pagination?

 package Admin;


import java.util.ArrayList;

import java.util.Collections;

import java.util.List;


import org.openqa.selenium.By;

import org.openqa.selenium.WebElement;

import org.testng.Assert;

import org.testng.annotations.Test;


import BaseInit.BaseInit;

import MyMethods.MyLoginMethods;


public class Sorting extends BaseInit {


@Test

public static void sortingtest() throws InterruptedException {

// Login to Admin Panel

MyLoginMethods.AdminLogin(datap.getProperty("email"), datap.getProperty("Pass"));

driver.get(sitedata.getProperty("confiProURL"));

Thread.sleep(2000);


ArrayList<String> ActualList = new ArrayList<String>();

ArrayList<String> sortedList = new ArrayList<String>();


String[] pageItem = epresent("pageItem_className").getText().split(" ");

String TotalPage = pageItem[3].trim();

System.out.println("Items per Page is- " + TotalPage);

int PagePerItem = Integer.parseInt(TotalPage);


String page = epresent("pageSize_className").getText();

String[] split = page.split(" ");

String pageNo = split[4].trim();

System.out.println("Page num is- " + pageNo);

int tPage = Integer.parseInt(pageNo);


int TotalClick = (tPage / PagePerItem);

System.out.println(TotalClick);


int currentPage = 1;

for (int j = 0; j < TotalClick; j++) {

if (currentPage >= 10) {

epresent("NextPage_xpath").click();

Thread.sleep(2000);

}

WebElement headPath = epresent("table_tagName");

List<WebElement> rowPath = headPath.findElements(By.tagName("mat-row"));


for (int i = 0; i < rowPath.size(); i++) {

String rowdata = rowPath.get(i).findElement(By.className("cdk-column-product_name")).getText();

ActualList.add(rowdata);

}

System.out.println(ActualList);

Thread.sleep(2000);

if (j == 0) {

epresent("name_xpath").click();

Thread.sleep(2000);

}

WebElement headPath1 = epresent("table_tagName");

List<WebElement> rowPath1 = headPath1.findElements(By.tagName("mat-row"));

for (int i = 0; i < rowPath.size(); i++) {

String sortData = rowPath1.get(i).findElement(By.className("cdk-column-product_name")).getText();

sortedList.add(sortData);

currentPage++;

}

System.out.println(sortedList);

// Check sorting

Collections.sort(ActualList);

System.out.println("-------------------------------------------------");

Assert.assertTrue(sortedList.equals(ActualList));

ActualList.clear();

sortedList.clear();

}

}

}


Comments

Popular posts from this blog

For Get Dynamic data & USe it into Postman Body parameters

API Automation Testing Script to check Response

Login through Data Driven Testing in selenium

Which dependencies needed in pom.xml while doing automation through selenium?

Download Java(JDK) & Eclipse IDE for selenium

What is data driven testing?

How to extract all the links in selenium?