Skip to content

Commit cbb685b

Browse files
author
hebron
committed
[add] search functionality and filter functionality
1 parent 48e406d commit cbb685b

File tree

7 files changed

+153
-36
lines changed

7 files changed

+153
-36
lines changed

src/test/java/screens/TallyScreen.java

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,48 @@
55
import org.openqa.selenium.WebElement;
66
import org.openqa.selenium.support.FindBy;
77
import org.openqa.selenium.support.PageFactory;
8+
import org.testng.Assert;
9+
10+
import java.util.List;
811

912
public class TallyScreen {
1013
public TallyScreen(AndroidDriver driver) {
1114
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
1215
}
16+
17+
// Main Menus(Tabs)
1318
@FindBy(id = "com.progoti.tallykhata:id/item_tally")
1419
WebElement tabTally;
20+
21+
// Tally Main page elements
1522
@FindBy(id = "com.progoti.tallykhata:id/add_customer")
1623
WebElement btnAddCustomer;
17-
@FindBy(id = "com.progoti.tallykhata:id/back_button")
18-
WebElement btnBack;
24+
@FindBy(id = "com.progoti.tallykhata:id/iv_view")
25+
WebElement btnEye;
26+
@FindBy(id = "com.progoti.tallykhata:id/iv_filter")
27+
WebElement btnFilter;
28+
@FindBy(id = "com.progoti.tallykhata:id/ivClearFilter")
29+
WebElement btnClearFilter;
30+
@FindBy(id = "com.progoti.tallykhata:id/lay_tagada_message")
31+
WebElement btnTagadaPathai;
32+
@FindBy(id = "com.progoti.tallykhata:id/tvTotalPabo")
33+
WebElement textTotalpabo;
34+
@FindBy(id = "com.progoti.tallykhata:id/tvListCustomer")
35+
WebElement textListOfSupplierAndCustomer;
36+
@FindBy(id = "com.progoti.tallykhata:id/layout")
37+
public List<WebElement> objectCustomerDetailsContainer;
38+
@FindBy(id = "com.progoti.tallykhata:id/layoutCustomerInfo")
39+
List<WebElement> objectCustomerInfoContainer;
40+
@FindBy(id = "com.progoti.tallykhata:id/etSearchHome")
41+
WebElement inputSearchBox;
42+
43+
// Tally Main page Modal elements
44+
@FindBy(id = "com.progoti.tallykhata:id/ivCheckCustomer")
45+
WebElement inputCheckBoxCustomer;
46+
@FindBy(id = "com.progoti.tallykhata:id/ivCheckSupplier")
47+
WebElement inputCheckBoxSupplier;
48+
49+
// Tally Customer add page elements
1950
@FindBy(id = "com.progoti.tallykhata:id/btnCustomer")
2051
WebElement tabCustomer;
2152
@FindBy(id = "com.progoti.tallykhata:id/btnSupplier")
@@ -26,6 +57,10 @@ public TallyScreen(AndroidDriver driver) {
2657
WebElement inputCustomerOrSupplierMobileNumber;
2758
@FindBy(id = "com.progoti.tallykhata:id/etCreditInput")
2859
WebElement inputPurberBaki;
60+
@FindBy(id = "com.progoti.tallykhata:id/layoutSmsEnabled")
61+
WebElement btnradioSendSMS;
62+
@FindBy(id = "com.progoti.tallykhata:id/back_button")
63+
WebElement btnBack;
2964
@FindBy(id = "com.progoti.tallykhata:id/btnConfirm")
3065
WebElement btnNischit;
3166
@FindBy(id = "com.progoti.tallykhata:id/layoutContact")
@@ -56,11 +91,18 @@ public TallyScreen(AndroidDriver driver) {
5691
WebElement btnPickDate;
5792
@FindBy(id = "android:id/button1")
5893
WebElement btnOkAfterDatePicking;
59-
@FindBy(id = "com.progoti.tallykhata:id/layoutSmsEnabled")
60-
WebElement btnradioSendSMS;
61-
@FindBy(id = "com.progoti.tallykhata:id/tvListCustomer")
62-
WebElement textListOfSupplierAndCustomer;
6394

95+
// Tally Tagada pathai page elements
96+
@FindBy(id = "com.progoti.tallykhata:id/layout")
97+
public List<WebElement> objectTagadaPathaiDetailsContainer;
98+
@FindBy(id = "com.progoti.tallykhata:id/layoutSendSms")
99+
public WebElement btnSendTagadaSms;
100+
@FindBy(id = "com.progoti.tallykhata:id/button")
101+
public WebElement btnThikAche;
102+
@FindBy(id = "com.progoti.tallykhata:id/tv_cancel")
103+
public WebElement btnBatil;
104+
@FindBy(id = "com.progoti.tallykhata:id/tv_status_message")
105+
public WebElement textTagadaMessageSentConfirmation;
64106

65107
public String addCustomerWithNameAndPhone(String customerName, String customerPhoneNumber) {
66108
tabTally.click();
@@ -76,6 +118,7 @@ public String addCustomerFromContactBookWithAllInput() {
76118
btnPhoneBookThekeJogKori.click();
77119
objectSecondContact.click();
78120
// inputPurberBaki.sendKeys(purberBaki);
121+
// btnradioSendSMS.click();
79122
btnOpenCamera.click();
80123
btnClickPhoto.click();
81124
btnAcceptClickedPhoto.click();
@@ -101,6 +144,7 @@ public String addSupplierFromContactBookWithAllInput() {
101144
btnPhoneBookThekeJogKori.click();
102145
objectSixthContact.click();
103146
// inputPurberBaki.sendKeys(purberBaki);
147+
// btnradioSendSMS.click();
104148
btnOpenCamera.click();
105149
btnClickPhoto.click();
106150
btnAcceptClickedPhoto.click();
@@ -110,4 +154,29 @@ public String addSupplierFromContactBookWithAllInput() {
110154
btnNischit.click();
111155
return textConfirmMessageAfterCreation.getText();
112156
}
157+
158+
public int searchLastAddedCustomer(String customerName) throws InterruptedException {
159+
inputSearchBox.sendKeys(customerName);
160+
Thread.sleep(500);
161+
return objectCustomerDetailsContainer.size();
162+
}
163+
public String closeEyeButton() throws InterruptedException {
164+
inputSearchBox.clear();
165+
Thread.sleep(500);
166+
btnEye.click();
167+
Thread.sleep(1000);
168+
String totalPabo = textTotalpabo.getText();
169+
System.out.println("totalPabo "+ totalPabo);
170+
System.out.println(totalPabo == "- - -");
171+
return totalPabo;
172+
}
173+
174+
public int addFilter() throws InterruptedException {
175+
btnEye.click();
176+
Thread.sleep(1000);
177+
btnFilter.click();
178+
inputCheckBoxCustomer.click();
179+
btnNischit.click();
180+
return objectCustomerDetailsContainer.size();
181+
}
113182
}

src/test/java/testRunners/RegistrationTestRunner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ public void enterOtpAndClickButton() {
2525
Assert.assertTrue(isButtonEnabled);
2626
}
2727
@Test(priority = 3, description = "Enter shop name")
28-
public void enterShopNameAndClickButton() throws IOException, ParseException {
28+
public void enterShopNameAndClickButton() throws Exception {
2929
RegistrationScreen rScreen = new RegistrationScreen(driver);
3030
boolean isButtonEnabled = rScreen.insertShopNameAndClickButton(shopName);
3131
if (isButtonEnabled) {
32-
Utils.saveJsonList(phoneNumber, shopName);
32+
Utils.saveJsonList(phoneNumber, shopName, "users");
3333
}
3434
Assert.assertTrue(isButtonEnabled);
3535
}
3636
@Test(priority = 4, description = "Match shop title")
3737
public void matchShopTitle() throws IOException, ParseException {
3838
RegistrationScreen rScreen = new RegistrationScreen(driver);
39-
String expected_shop_title = Utils.getLastRegisteredUserShop();
39+
String expected_shop_title = Utils.getLastRegisteredUserShopName("users");
4040
String actual_shop_title = rScreen.textShopTitle.getText();
4141
Assert.assertEquals(expected_shop_title, actual_shop_title);
4242
}
Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package testRunners;
22

3+
import jdk.jshell.execution.Util;
4+
import org.json.simple.parser.ParseException;
5+
import org.openqa.selenium.By;
36
import org.testng.Assert;
47
import org.testng.annotations.BeforeTest;
58
import org.testng.annotations.Test;
@@ -8,9 +11,9 @@
811
import setup.Setup;
912
import utils.Utils;
1013

14+
import java.io.IOException;
15+
1116
public class TallyTestRunner extends Setup {
12-
public String customerName = Utils.randomCustomerName();
13-
public String supplierName = Utils.randomCustomerName();
1417
@BeforeTest
1518
public void register() {
1619
RegistrationScreen rScreen = new RegistrationScreen(driver);
@@ -19,38 +22,70 @@ public void register() {
1922
rScreen.insertShopNameAndClickButton(Utils.randomShopName());
2023
}
2124
@Test(priority = 1, description = "Create Customer with only name and phone")
22-
public void addCustomerWithNameAndPhone() {
25+
public void addCustomerWithNameAndPhone() throws Exception {
2326
TallyScreen tScreen = new TallyScreen(driver);
24-
String confirmationMessage = tScreen.addCustomerWithNameAndPhone(customerName ,Utils.randomPhoneNumber());
27+
String customerName = Utils.randomCustomerName();
28+
String customerPhoneNumber = Utils.randomPhoneNumber();
29+
String confirmationMessage = tScreen.addCustomerWithNameAndPhone(customerName, customerPhoneNumber);
2530
String[] arrOfStr = confirmationMessage.split("-");
2631
String[] bangla = new String[]{"কে টালিতে যোগ করা হয়েছে।"};
2732
// String bangla1 = "কে টালিতে যোগ করা হয়েছে।";
2833
// String rawString = "Entwickeln Sie mit Vergnügen";
2934
// ByteBuffer buffer = StandardCharsets.UTF_8.encode(rawString);
3035

3136
// String utf8EncodedString = StandardCharsets.UTF_8.decode(buffer).toString();
32-
System.out.println("actual "+confirmationMessage);
37+
// System.out.println("actual "+confirmationMessage);
3338
// String expected = "\"" + name + "\"- " + " কে টালিতে যোগ করা হয়েছে।";
34-
System.out.println("after splitting "+ arrOfStr[1]);
35-
System.out.println("bangla "+ bangla[0].getClass().getName());
36-
Assert.assertTrue(confirmationMessage.contains(arrOfStr[1]));
39+
// System.out.println("after splitting "+ arrOfStr[1]);
40+
// System.out.println("bangla "+ bangla[0].getClass().getName());
41+
Utils.saveJsonList(customerPhoneNumber, customerName,"customers");
42+
// Assert.assertTrue(confirmationMessage.contains(arrOfStr[1]));
3743
}
38-
@Test(priority = 2, description = "Create customer with all the input along with date and image")
44+
@Test(priority = 2, enabled = false, description = "Create customer with all the input along with date and image")
3945
public void addCustomerFromContactBookWithAllInput() {
4046
TallyScreen tScreen = new TallyScreen(driver);
4147
String confirmationMessage = tScreen.addCustomerFromContactBookWithAllInput();
4248
System.out.println(confirmationMessage);
4349
}
4450
@Test(priority = 3, description = "Create supplier with only name and phone")
45-
public void addSupplierWithNameAndPhone() {
51+
public void addSupplierWithNameAndPhone() throws Exception {
4652
TallyScreen tScreen = new TallyScreen(driver);
47-
String confirmationMessage = tScreen.addSupplierWithNameAndPhone(supplierName, Utils.randomPhoneNumber());
53+
String supplierName = Utils.randomCustomerName();
54+
String supplierPhoneNumber = Utils.randomPhoneNumber();
55+
String confirmationMessage = tScreen.addSupplierWithNameAndPhone(supplierName, supplierPhoneNumber);
56+
Utils.saveJsonList(supplierPhoneNumber, supplierName,"customers");
4857
System.out.println(confirmationMessage);
4958
}
50-
@Test(priority = 4, description = "Create supplier with all the input along with date and image")
59+
@Test(priority = 4, enabled = false, description = "Create supplier with all the input along with date and image")
5160
public void addSupplierFromContactBookWithAllInput() {
5261
TallyScreen tScreen = new TallyScreen(driver);
5362
String confirmationMessage = tScreen.addSupplierFromContactBookWithAllInput();
5463
System.out.println(confirmationMessage);
5564
}
65+
@Test(priority = 5, description = "Loop through customer list and print out length of data")
66+
public void loopThroughCustomerData() {
67+
TallyScreen tScreen = new TallyScreen(driver);
68+
int actualTotalCustomerLength = tScreen.objectCustomerDetailsContainer.size();
69+
System.out.println("Customer length " + actualTotalCustomerLength);
70+
// Assert.assertEquals(actualTotalCustomerLength, 2);
71+
}
72+
@Test(priority = 6, description = "Search for the last customer")
73+
public void searchForLastCustomer() throws IOException, ParseException, InterruptedException {
74+
TallyScreen tScreen = new TallyScreen(driver);
75+
int customerFound = tScreen.searchLastAddedCustomer(Utils.getLastAddedCustomerName("customers"));
76+
System.out.println("Customer found " + customerFound);
77+
// Assert.assertEquals(customerFound, 1);
78+
}
79+
@Test(priority = 7, description = "Close eye Button and check that all numbers ar hidden")
80+
public void closeEyeButton() throws IOException, ParseException, InterruptedException {
81+
TallyScreen tScreen = new TallyScreen(driver);
82+
String totalPabo = tScreen.closeEyeButton();
83+
Assert.assertEquals(totalPabo, "- - -");
84+
}
85+
@Test(priority = 8, description = "Add filter for Showing only customer")
86+
public void addFilterOnlyCustomer() throws IOException, ParseException, InterruptedException {
87+
TallyScreen tScreen = new TallyScreen(driver);
88+
int customerFound = tScreen.addFilter();
89+
System.out.println("Customer found " + customerFound);
90+
}
5691
}

src/test/java/utils/Utils.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ public static String randomCustomerName() {
2626
Faker faker = new Faker();
2727
return faker.name().fullName();
2828
}
29-
public static void saveJsonList(String phoneNumber, String shopName) throws IOException, ParseException {
30-
String fileName="./src/test/resources/Users.json";
29+
public static void saveJsonList(String phoneNumber, String name, String fileToSave) throws Exception {
30+
String fileName="./src/test/resources/"+ fileToSave +".json";
3131
JSONParser parser=new JSONParser();
3232
Object obj= parser.parse(new FileReader(fileName));
3333
JSONArray jsonArray= (JSONArray) obj;
3434

3535
JSONObject userObject=new JSONObject();
36-
userObject.put("phone",phoneNumber);
37-
userObject.put("shop",shopName);
36+
if (fileToSave == "users") {
37+
userObject.put("phone",phoneNumber);
38+
userObject.put("shop",name);
39+
} else if (fileToSave == "customers") {
40+
userObject.put("phone",phoneNumber);
41+
userObject.put("name",name);
42+
} else {
43+
throw new Exception("file not found");
44+
}
3845
jsonArray.add(userObject);
3946

4047
FileWriter file=new FileWriter(fileName);
@@ -43,24 +50,29 @@ public static void saveJsonList(String phoneNumber, String shopName) throws IOEx
4350
file.close();
4451
}
4552

46-
public static JSONArray readJSONList() throws IOException, ParseException {
47-
String fileName="./src/test/resources/Users.json";
53+
public static JSONArray readJSONList(String fileToRead) throws IOException, ParseException {
54+
String fileName="./src/test/resources/"+ fileToRead +".json";
4855
JSONParser parser=new JSONParser();
4956
Object object= parser.parse(new FileReader(fileName));
5057
return (JSONArray) object;
5158

5259
}
53-
// public static String getLastRegisteredUserPhone() throws IOException, ParseException {
54-
// List usersList = readJSONList();
55-
// JSONObject userObj= (JSONObject) usersList.get(usersList.size()-1);
56-
// String phoneNumber = (String) userObj.get("phone");
57-
// return phoneNumber;
58-
// }
59-
public static String getLastRegisteredUserShop() throws IOException, ParseException {
60-
List usersList = readJSONList();
60+
public static String getLastRegisteredUserPhone(String fileToRead) throws IOException, ParseException {
61+
List usersList = readJSONList(fileToRead);
62+
JSONObject userObj= (JSONObject) usersList.get(usersList.size()-1);
63+
String phoneNumber = (String) userObj.get("phone");
64+
return phoneNumber;
65+
}
66+
public static String getLastRegisteredUserShopName(String fileToRead) throws IOException, ParseException {
67+
List usersList = readJSONList(fileToRead);
6168
JSONObject userObj= (JSONObject) usersList.get(usersList.size()-1);
6269
return (String) userObj.get("shop");
6370
}
71+
public static String getLastAddedCustomerName(String fileToRead) throws IOException, ParseException {
72+
List usersList = readJSONList(fileToRead);
73+
JSONObject userObj= (JSONObject) usersList.get(usersList.size()-1);
74+
return (String) userObj.get("name");
75+
}
6476

6577
public static void main(String[] args) {
6678
// String myText = "\"Mr. Raymundo Torp\"- কে টালিতে যোগ করা হয়েছে।";

src/test/resources/Users.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/resources/customers.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"phone":"01953471262","name":"Hamim"},{"phone":"01996246658","name":"Nguyet Sawayn"},{"phone":"01999557841","name":"Patricia Rohan"},{"phone":"01999751569","name":"Willis Kunze MD"},{"phone":"01981480878","name":"Adolfo Kerluke"},{"phone":"01999304241","name":"Becki Mann DDS"},{"phone":"01990033837","name":"Ms. Gregory Gerlach"},{"phone":"01951338367","name":"Joyce O'Hara"},{"phone":"01951646872","name":"Merilyn Orn"},{"phone":"01968833874","name":"Angelina Vandervort"},{"phone":"01972138932","name":"Loyd Stracke"}]

src/test/resources/users.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"shop":"Hamim Enterprize","phone":"01953471262"},{"shop":"Bob Inc","phone":"01980061846"},{"shop":"Hettie LLC","phone":"01973677493"}]

0 commit comments

Comments
 (0)