Skip to content

Commit bfad2e9

Browse files
author
hebron
committed
[add] allure reporting and add screenshot in allure report
1 parent b567e15 commit bfad2e9

File tree

10 files changed

+97
-24
lines changed

10 files changed

+97
-24
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
build
66
/build
77
build/
8+
allure-results
9+
/allure-results
10+
allure-results/
11+
src/main
812
.env
9-
src/test/resources/text.txt
10-
src/test/java/testRunners/test.java
1113

build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath "io.qameta.allure.gradle.allure:allure-plugin:2.11.2"
7+
}
8+
}
9+
110
plugins {
211
id 'java'
12+
id "io.qameta.allure" version "2.11.2"
13+
}
14+
15+
allure {
16+
version = '2.20.1'
317
}
418

519
group 'org.example'
@@ -22,6 +36,8 @@ dependencies {
2236
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
2337
// https://mvnrepository.com/artifact/io.github.cdimascio/dotenv-java
2438
implementation group: 'io.github.cdimascio', name: 'dotenv-java', version: '2.3.2'
39+
// https://mvnrepository.com/artifact/io.qameta.allure/allure-testng
40+
implementation group: 'io.qameta.allure', name: 'allure-testng', version: '2.20.1'
2541

2642
}
2743

src/test/java/screens/TallyScreen.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,27 @@ public String addCustomerWithNameAndPhone(String customerName, String customerPh
141141
btnNischit.click();
142142
return textConfirmMessageAfterCreation.getText();
143143
}
144-
public String addCustomerFromContactBookWithAllInput(String purberBaki) {
144+
145+
public String addCustomerFromContactBookWithAllInput(String purberBaki) throws InterruptedException {
145146
tabTally.click();
146147
btnAddCustomer.click();
147148
btnPhoneBookThekeJogKori.click();
148149
objectSecondContact.click();
149150
inputPurberBaki.sendKeys(purberBaki);
150151
btnradioSendSMS.click();
152+
Thread.sleep(1000);
151153
btnOpenCamera.click();
154+
Thread.sleep(1000);
152155
btnClickPhoto.click();
156+
Thread.sleep(2000);
153157
btnAcceptClickedPhoto.click();
154158
btnDatePicker.click();
155159
btnPickDate.click();
156160
btnOkAfterDatePicking.click();
157161
btnNischit.click();
158162
return textConfirmMessageAfterCreation.getText();
159163
}
164+
160165
public String addSupplierWithNameAndPhone(String supplierName, String supplierPhoneNumber) {
161166
tabTally.click();
162167
btnAddCustomer.click();
@@ -166,6 +171,7 @@ public String addSupplierWithNameAndPhone(String supplierName, String supplierPh
166171
btnNischit.click();
167172
return textConfirmMessageAfterCreation.getText();
168173
}
174+
169175
public String addSupplierFromContactBookWithAllInput(String purberBaki) {
170176
tabTally.click();
171177
btnAddCustomer.click();
@@ -182,13 +188,15 @@ public String addSupplierFromContactBookWithAllInput(String purberBaki) {
182188
btnNischit.click();
183189
return textConfirmMessageAfterCreation.getText();
184190
}
191+
185192
public String editFirstCustomerPelam(String pelam) {
186193
objectCustomerDetailsContainer.get(0).click();
187194
inputPelam.sendKeys(pelam);
188195
btnradioSendSMS.click();
189196
btnNischitAfterEdit.click();
190197
return textConfirmMessageAfterEditPleam.getText();
191198
}
199+
192200
public String editFirstCustomerName(String customerUpdatedName) throws InterruptedException {
193201
objectCustomerDetailsContainer.get(0).click();
194202
btnReport.click();
@@ -199,6 +207,7 @@ public String editFirstCustomerName(String customerUpdatedName) throws Interrupt
199207
btnNischit.click();
200208
return textConfirmMessageAfterNameUpdate.getText();
201209
}
210+
202211
public String deleteLastCustomer() throws InterruptedException {
203212
btnBack.click();
204213
Thread.sleep(1000);
@@ -210,21 +219,24 @@ public String deleteLastCustomer() throws InterruptedException {
210219
btnNischit.click();
211220
return textConfirmMessageAfterDeleteCustomer.getText();
212221
}
222+
213223
public int searchLastAddedCustomer(String customerName) throws InterruptedException {
214224
inputSearchBox.sendKeys(customerName);
215225
Thread.sleep(500);
216226
return objectCustomerDetailsContainer.size();
217227
}
228+
218229
public String closeEyeButton() throws InterruptedException {
219230
inputSearchBox.clear();
220231
Thread.sleep(500);
221232
btnEye.click();
222233
Thread.sleep(1000);
223234
String totalPabo = textTotalpabo.getText();
224-
System.out.println("totalPabo "+ totalPabo);
235+
System.out.println("totalPabo " + totalPabo);
225236
System.out.println(totalPabo == "- - -");
226-
return totalPabo;
237+
return totalPabo;
227238
}
239+
228240
public int addFilter() throws InterruptedException {
229241
btnEye.click();
230242
Thread.sleep(1000);
@@ -233,18 +245,21 @@ public int addFilter() throws InterruptedException {
233245
btnNischit.click();
234246
return objectCustomerDetailsContainer.size();
235247
}
248+
236249
public String tagadaPathai() {
237250
btnTagadaPathai.click();
238251
objectTagadaPathaiDetailsContainer.get(0).click();
239252
btnSendTagadaSms.click();
240253
btnThikAche.click();
241-
return textTagadaMessageSentConfirmation.getText();
254+
return textTagadaMessageSentConfirmation.getText();
242255
}
256+
243257
public boolean isNischitButtonEnabledWhenCreatingCustomer(String invalidCustomerName) {
244258
btnAddCustomer.click();
245259
inputCustomerOrSupplierName.sendKeys(invalidCustomerName);
246260
return btnNischit.isEnabled();
247261
}
262+
248263
public boolean isPorobortiButtonEnabledWhenEditingCustomerInfo(String invalidCustomerName) {
249264
btnBack.click();
250265
objectCustomerDetailsContainer.get(0).click();

src/test/java/setup/Setup.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import io.appium.java_client.android.AndroidDriver;
44
import io.github.cdimascio.dotenv.Dotenv;
55
import org.openqa.selenium.remote.DesiredCapabilities;
6+
import org.testng.ITestResult;
7+
import org.testng.annotations.AfterMethod;
8+
import org.testng.annotations.AfterTest;
69
import org.testng.annotations.BeforeTest;
10+
import utils.Utils;
711

812
import java.net.MalformedURLException;
913
import java.net.URL;
@@ -32,8 +36,21 @@ public AndroidDriver setup() throws MalformedURLException {
3236
return driver;
3337
}
3438

35-
// @AfterTest
36-
// public void closeDriver() {
37-
// driver.quit();
38-
// }
39+
@AfterMethod
40+
public void isFailed(ITestResult result) {
41+
if (ITestResult.FAILURE == result.getStatus()) {
42+
try {
43+
Utils.saveScreenshot("Failed Screenshot", driver);
44+
} catch (Exception exception) {
45+
System.out.println(exception.toString());
46+
}
47+
48+
}
49+
50+
}
51+
52+
@AfterTest
53+
public void closeDriver() {
54+
driver.quit();
55+
}
3956
}

src/test/java/testRunners/RegistrationTestRunner.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,40 @@
1212
public class RegistrationTestRunner extends Setup {
1313
private final String phoneNumber = Utils.randomPhoneNumber();
1414
private final String shopName = Utils.randomShopName();
15+
1516
@Test(priority = 1, description = "Enter phone number")
1617
public void enterPhoneNumberAndClickButton() {
1718
RegistrationScreen rScreen = new RegistrationScreen(driver);
1819
boolean isButtonEnabled = rScreen.insertPhoneAndClickButton(phoneNumber);
20+
Utils.saveScreenshot("Screenshot", driver);
1921
Assert.assertTrue(isButtonEnabled);
2022
}
23+
2124
@Test(priority = 2, description = "Enter OTP")
2225
public void enterOtpAndClickButton() {
2326
RegistrationScreen rScreen = new RegistrationScreen(driver);
2427
boolean isButtonEnabled = rScreen.insertOtpAndClickButton(driver);
28+
Utils.saveScreenshot("Screenshot", driver);
2529
Assert.assertTrue(isButtonEnabled);
2630
}
31+
2732
@Test(priority = 3, description = "Enter shop name")
2833
public void enterShopNameAndClickButton() throws Exception {
2934
RegistrationScreen rScreen = new RegistrationScreen(driver);
3035
boolean isButtonEnabled = rScreen.insertShopNameAndClickButton(shopName);
36+
Utils.saveScreenshot("Screenshot", driver);
3137
if (isButtonEnabled) {
3238
Utils.saveJsonList(phoneNumber, shopName, "users");
3339
}
3440
Assert.assertTrue(isButtonEnabled);
3541
}
42+
3643
@Test(priority = 4, description = "Match shop title")
3744
public void matchShopTitle() throws IOException, ParseException {
3845
RegistrationScreen rScreen = new RegistrationScreen(driver);
3946
String expected_shop_title = Utils.getLastRegisteredUserShopName("users");
4047
String actual_shop_title = rScreen.textShopTitle.getText();
48+
Utils.saveScreenshot("Screenshot", driver);
4149
Assert.assertEquals(expected_shop_title, actual_shop_title);
4250
}
4351
}

src/test/java/testRunners/TallyTestRunner.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,100 +14,115 @@
1414

1515
public class TallyTestRunner extends Setup {
1616
Dotenv dotenv = Dotenv.load();
17+
1718
@BeforeTest
1819
public void register() {
1920
RegistrationScreen rScreen = new RegistrationScreen(driver);
2021
rScreen.insertPhoneAndClickButton(Utils.randomPhoneNumber());
2122
rScreen.insertOtpAndClickButton(driver);
2223
rScreen.insertShopNameAndClickButton(Utils.randomShopName());
2324
}
25+
2426
@Test(priority = 1, description = "Create Customer with only name and phone")
2527
public void addCustomerWithNameAndPhone() throws Exception {
2628
TallyScreen tScreen = new TallyScreen(driver);
2729
String customerName = Utils.randomCustomerName();
2830
// String customerPhoneNumber = Utils.randomPhoneNumber();
2931
String customerPhoneNumber = "01571761196";
3032
String confirmationMessage = tScreen.addCustomerWithNameAndPhone(customerName, customerPhoneNumber);
31-
Utils.saveJsonList(customerPhoneNumber, customerName,"customers");
33+
Utils.saveJsonList(customerPhoneNumber, customerName, "customers");
3234
System.out.println("add customer " + dotenv.get("PARTIAL_TEXT_AFTER_CREATING_CUSTOMER_OR_SUPPLIER"));
3335
Assert.assertTrue(confirmationMessage.contains(dotenv.get("PARTIAL_TEXT_AFTER_CREATING_CUSTOMER_OR_SUPPLIER")));
3436
}
37+
3538
@Test(priority = 2, description = "Create customer with all the input along with date and image")
36-
public void addCustomerFromContactBookWithAllInput() {
39+
public void addCustomerFromContactBookWithAllInput() throws InterruptedException {
3740
TallyScreen tScreen = new TallyScreen(driver);
3841
String confirmationMessage = tScreen.addCustomerFromContactBookWithAllInput("12");
3942
Assert.assertTrue(confirmationMessage.contains(dotenv.get("PARTIAL_TEXT_AFTER_CREATING_CUSTOMER_OR_SUPPLIER")));
4043
}
44+
4145
@Test(priority = 3, description = "Create supplier with only name and phone")
4246
public void addSupplierWithNameAndPhone() throws Exception {
4347
TallyScreen tScreen = new TallyScreen(driver);
4448
String supplierName = Utils.randomCustomerName();
4549
String supplierPhoneNumber = Utils.randomPhoneNumber();
4650
String confirmationMessage = tScreen.addSupplierWithNameAndPhone(supplierName, supplierPhoneNumber);
47-
Utils.saveJsonList(supplierPhoneNumber, supplierName,"customers");
51+
Utils.saveJsonList(supplierPhoneNumber, supplierName, "customers");
4852
Assert.assertTrue(confirmationMessage.contains(dotenv.get("PARTIAL_TEXT_AFTER_CREATING_CUSTOMER_OR_SUPPLIER")));
4953
}
54+
5055
@Test(priority = 4, description = "Create supplier with all the input along with date and image")
5156
public void addSupplierFromContactBookWithAllInput() {
5257
TallyScreen tScreen = new TallyScreen(driver);
5358
String confirmationMessage = tScreen.addSupplierFromContactBookWithAllInput("11");
5459
Assert.assertTrue(confirmationMessage.contains(dotenv.get("PARTIAL_TEXT_AFTER_CREATING_CUSTOMER_OR_SUPPLIER")));
5560
}
61+
5662
@Test(priority = 5, description = "Loop through customer list and print out length of data")
5763
public void loopThroughCustomerData() {
5864
TallyScreen tScreen = new TallyScreen(driver);
5965
int actualTotalCustomerLength = tScreen.objectCustomerDetailsContainer.size();
6066
System.out.println("Customer length " + actualTotalCustomerLength);
6167
Assert.assertEquals(actualTotalCustomerLength, 4);
6268
}
69+
6370
@Test(priority = 6, description = "Edit PELAM of first customer from the customer list")
6471
public void editFirstCustomerPelam() {
6572
TallyScreen tScreen = new TallyScreen(driver);
6673
String confirmationMessage = tScreen.editFirstCustomerPelam("12");
6774
Assert.assertTrue(confirmationMessage.contains(dotenv.get("TEXT_AFTER_UPDATING_PELAM_DILAM")));
6875
}
76+
6977
@Test(priority = 7, description = "Update first customer name from the customer list")
7078
public void editFirstCustomerName() throws InterruptedException {
7179
TallyScreen tScreen = new TallyScreen(driver);
7280
String confirmationMessage = tScreen.editFirstCustomerName(Utils.randomCustomerName());
7381
Assert.assertTrue(confirmationMessage.contains(dotenv.get("TEXT_AFTER_UPDATING_NAME_OR_MOBILE_OF_CUSTOMER_OR_SUPPLIER")));
7482
}
83+
7584
@Test(priority = 8, description = "Search for the last customer added in the customer list")
7685
public void searchForLastAddedCustomer() throws IOException, ParseException, InterruptedException {
7786
TallyScreen tScreen = new TallyScreen(driver);
7887
int customerFound = tScreen.searchLastAddedCustomer(Utils.getLastAddedCustomerName("customers"));
7988
Assert.assertEquals(customerFound, 1);
8089
}
90+
8191
@Test(priority = 9, description = "Close eye Button and check that all numbers ar hidden")
8292
public void closeEyeButton() throws InterruptedException {
8393
TallyScreen tScreen = new TallyScreen(driver);
8494
String totalPabo = tScreen.closeEyeButton();
8595
Assert.assertEquals(totalPabo, dotenv.get("TEXT_AFTER_CLOSING_EYE_BUTTON"));
8696
}
97+
8798
@Test(priority = 10, description = "Add filter for Showing only customer")
8899
public void addFilterOnlyCustomer() throws InterruptedException {
89100
TallyScreen tScreen = new TallyScreen(driver);
90101
int customerFound = tScreen.addFilter();
91102
Assert.assertEquals(customerFound, 2);
92103
}
104+
93105
@Test(priority = 11, description = "Tagada pathai to customers")
94106
public void tagadaPathai() {
95107
TallyScreen tScreen = new TallyScreen(driver);
96108
String confirmationMessage = tScreen.tagadaPathai();
97109
Assert.assertTrue(confirmationMessage.contains(dotenv.get("TEXT_AFTER_SENDING_TAGADA_MESSAGE")));
98110
}
111+
99112
@Test(priority = 12, description = "Delete Last customer from the list")
100113
public void deleteLastCustomer() throws InterruptedException {
101114
TallyScreen tScreen = new TallyScreen(driver);
102115
String confirmationMessage = tScreen.deleteLastCustomer();
103116
Assert.assertTrue(confirmationMessage.contains(dotenv.get("PARTIAL_TEXT_AFTER_DELETING_CUSTOMER_OR_SUPPLIER")));
104117
}
118+
105119
@Test(priority = 13, description = "If Nischit button enabled with sending invalid customer name when creating customers")
106120
public void isNischitButtonEnabledWhenCreatingCustomer() throws InterruptedException {
107121
TallyScreen tScreen = new TallyScreen(driver);
108122
boolean isBtnEnabled = tScreen.isNischitButtonEnabledWhenCreatingCustomer("hh");
109123
Assert.assertFalse(isBtnEnabled);
110124
}
125+
111126
@Test(priority = 14, description = "If Poroborti button enabled with sending invalid customer name when updating customers info")
112127
public void isPorobortiButtonEnabledWhenEditingCustomerInfo() throws InterruptedException {
113128
TallyScreen tScreen = new TallyScreen(driver);

src/test/java/utils/Utils.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package utils;
22

33
import com.github.javafaker.Faker;
4+
import io.appium.java_client.android.AndroidDriver;
45
import io.github.cdimascio.dotenv.Dotenv;
6+
import io.qameta.allure.Allure;
57
import org.json.simple.JSONArray;
68
import org.json.simple.JSONObject;
79
import org.json.simple.parser.JSONParser;
810
import org.json.simple.parser.ParseException;
11+
import org.openqa.selenium.OutputType;
12+
import org.openqa.selenium.TakesScreenshot;
913

10-
import java.io.FileReader;
11-
import java.io.FileWriter;
12-
import java.io.IOException;
13-
import java.time.LocalDate;
14-
import java.time.format.DateTimeFormatter;
14+
import java.io.*;
1515
import java.util.List;
1616
import java.util.Random;
1717

@@ -31,10 +31,9 @@ public static String randomCustomerName() {
3131
return faker.name().fullName();
3232
}
3333

34-
public static String generateDate() {
35-
LocalDate yesterday = LocalDate.now().minusDays(1);
36-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy");
37-
return yesterday.format(formatter);
34+
public static void saveScreenshot(String name, AndroidDriver driver) {
35+
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
36+
Allure.addAttachment(name, new ByteArrayInputStream(screenshot));
3837
}
3938

4039
public static String banglaToEnglish(String stringToConvert) {

0 commit comments

Comments
 (0)