diff --git a/src/test/java/BaseScreen/ScreenBase.java b/src/test/java/BaseScreen/ScreenBase.java new file mode 100644 index 00000000..aa2d4de7 --- /dev/null +++ b/src/test/java/BaseScreen/ScreenBase.java @@ -0,0 +1,55 @@ +package BaseScreen; + +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import io.appium.java_client.MobileElement; +import io.appium.java_client.TouchAction; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; +import io.appium.java_client.touch.offset.PointOption; + +public class ScreenBase { + + + public static AndroidDriver driver; +// public static WebDriverWait wait; + + public ScreenBase(AndroidDriver driver){ + this.driver=driver; + //wait = new WebDriverWait(driver,30); + loadElements(); + + } + + + public void loadElements(){ + PageFactory.initElements(new AppiumFieldDecorator(driver), this); + + } + + public static void scroll() { + MobileElement el = (MobileElement) driver + .findElementByAndroidUIAutomator("new UiScrollable(" + + "new UiSelector().scrollable(true)).scrollIntoView(" + + "new UiSelector().textContains(\"Kiswahili\"));"); + } + +// + public boolean isElementPresent(MobileElement elementName, int timeout){ + try{ + WebDriverWait wait = new WebDriverWait(driver, timeout); + wait.until(ExpectedConditions.visibilityOf(elementName)); + return true; + }catch(Exception e){ + return false; + } + } + public static void tap(int x, int y) { + TouchAction action=new TouchAction(driver); + action.tap(PointOption.point(x,y)).perform(); + + + } +} diff --git a/src/test/java/BaseTest/TestBase.java b/src/test/java/BaseTest/TestBase.java new file mode 100644 index 00000000..de982c43 --- /dev/null +++ b/src/test/java/BaseTest/TestBase.java @@ -0,0 +1,120 @@ +package BaseTest; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.Date; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.ExtentTest; +import com.aventstack.extentreports.Status; + + +import io.appium.java_client.MobileElement; +import io.appium.java_client.android.AndroidDriver; +import utili.ExcelReader; +import utili.ExtentManager; +import utili.main_util; + +public class TestBase { + + + public static AndroidDriver driver; + + public static Logger log=Logger.getLogger("devpinoyLogger"); + public static ExcelReader excel=new ExcelReader("./src/test/resources/data/TestdataTwo.xlsx"); + public static ExtentReports extentReport=ExtentManager.GetExtent(System.getProperty("user.dir")+"/src/test/resources/reports/extent.html"); + public static ThreadLocal classLevelLog = new ThreadLocal(); + public static ThreadLocal testLevelLog = new ThreadLocal(); + public static String screenshotPath; + public static String Error; + + @BeforeSuite + public void setUp() { + + if(driver==null){ + + try { + PropertyConfigurator.configure("./src/test/resources/properties/log4j.properties"); + + + + main_util.loadConfigProp("app.properties"); + + log.info("config file loaded"); + + } catch (IOException e) { + + e.printStackTrace(); + } + main_util.setCapabilities(); + log.info("capabilities loaded"); + try { + driver = main_util.getDriver(); + } catch (MalformedURLException e) { + + e.printStackTrace(); + } + } + + } + @BeforeClass + public void beforeClass() { + + ExtentTest classLevelTest =extentReport.createTest(getClass().getSimpleName()); + classLevelLog.set(classLevelTest); + + + } + + + + @AfterSuite + public void tearDown() throws InterruptedException{ + Thread.sleep(2000); + driver.quit(); + log.info("driver successfully exit"); + + } + public static String capture() throws IOException { + + + Date d = new Date(); + Error = d.toString().replace(":", "_").replace(" ", "_")+".jpg"; + screenshotPath =System.getProperty("user.dir")+"/src/test/resources/screenshots/"+Error; + System.out.println("enter the screen shot method...."); + File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); + + File destination = new File(screenshotPath); + + FileUtils.copyFile(screenshot,destination); + + + return screenshotPath; + + + + + } + + + +/* public static void clear(List ele) { + ele.clear(); + + }*/ + + +} diff --git a/src/test/java/listeners/CustomListeners.java b/src/test/java/listeners/CustomListeners.java new file mode 100644 index 00000000..6fb7a643 --- /dev/null +++ b/src/test/java/listeners/CustomListeners.java @@ -0,0 +1,93 @@ +package listeners; + + +import java.io.IOException; +import java.util.Arrays; + +import org.testng.ITestContext; +import org.testng.ITestListener; +import org.testng.ITestResult; + + +import com.aventstack.extentreports.ExtentTest; +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.markuputils.ExtentColor; +import com.aventstack.extentreports.markuputils.Markup; +import com.aventstack.extentreports.markuputils.MarkupHelper; + +import BaseTest.TestBase; +import utili.main_util; + + +public class CustomListeners extends TestBase implements ITestListener { + + public void onTestStart(ITestResult result) { + // TODO Auto-generated method stub + ExtentTest test = classLevelLog.get().createNode(result.getName()); + testLevelLog.set(test); + testLevelLog.get().info("Testcase:" + result.getName() + "test execution started"); + + } + + public void onTestSuccess(ITestResult result) { + testLevelLog.get().pass("This test case got passed"); + /* try { + testLevelLog.get().addScreenCaptureFromPath(TestBase.capture()); + } catch (IOException e) { + + e.printStackTrace(); + }*/ + extentReport.flush(); + + } + + public void onTestFailure(ITestResult result) { + // TODO Auto-generated method stub + String excepionMessage=Arrays.toString(result.getThrowable().getStackTrace()); + testLevelLog.get() + .fail("
" + "" + "" + "" + "Exception Occured:Click to see" + + "" + "" + "" + excepionMessage.replaceAll(",", "
") + "
" + + " \n"); + + String failureLogg = "This Test case got Failed"; + Markup m = MarkupHelper.createLabel(failureLogg, ExtentColor.RED); + testLevelLog.get().log(Status.FAIL, m); + + + try { + testLevelLog.get().addScreenCaptureFromPath(TestBase.capture()); + } catch (IOException e) { + + e.printStackTrace(); + } + extentReport.flush(); + } + + public void onTestSkipped(ITestResult result) { + + + } + + public void onTestFailedButWithinSuccessPercentage(ITestResult result) { + // TODO Auto-generated method stub + + } + + public void onStart(ITestContext context) { + // TODO Auto-generated method stub + + } + + public void onFinish(ITestContext context) { + // TODO Auto-generated method stub + + if (extentReport != null) { + + extentReport.flush(); + } + + } + + + +} diff --git a/src/test/java/listeners/TestdataProvider.java b/src/test/java/listeners/TestdataProvider.java new file mode 100644 index 00000000..157807d4 --- /dev/null +++ b/src/test/java/listeners/TestdataProvider.java @@ -0,0 +1,41 @@ +package listeners; + +import java.lang.reflect.Method; +import java.util.Hashtable; + +import org.testng.annotations.DataProvider; + +import BaseTest.TestBase; +import utili.main_util; + +public class TestdataProvider extends TestBase{ + + @DataProvider(name="dp") + public static Object[][] getData(Method m) { + + String sheetName = m.getName(); + System.out.println(sheetName); + + int rowNum = excel.getRowCount(sheetName); + int colNum = excel.getColumnCount(sheetName); + + + Object[][] data = new Object[rowNum - 1][colNum]; + + for (int rows = 2; rows <= rowNum; rows++) { + + for (int cols = 0; cols < colNum; cols++) { + + data[rows - 2][cols] = excel.getCellData(sheetName, cols, rows); + + } + + } + + return data; + + } + } + + + diff --git a/src/test/java/screens/DtLoginScreen.java b/src/test/java/screens/DtLoginScreen.java new file mode 100644 index 00000000..dd286512 --- /dev/null +++ b/src/test/java/screens/DtLoginScreen.java @@ -0,0 +1,163 @@ +package screens; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.support.FindAll; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + + + +import BaseScreen.ScreenBase; +import BaseTest.TestBase; +import io.appium.java_client.MobileElement; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.pagefactory.AndroidBy; +import io.appium.java_client.pagefactory.AndroidFindAll; +import io.appium.java_client.pagefactory.AndroidFindBy; +import io.appium.java_client.pagefactory.AndroidFindBys; + +public class DtLoginScreen extends ScreenBase { + + + + public DtLoginScreen(AndroidDriver driver) { + super(driver); + + } + + + @AndroidFindBy(className = "android.widget.EditText") + public static List input; + + @AndroidFindBy(className = "android.widget.TextView") + public List click; + + @AndroidFindBy(className = "android.widget.Spinner") + public MobileElement Spinner; + + @AndroidFindAll({ + + @AndroidBy(id = "tools.disciple.app:id/select_dialog_listview"), + @AndroidBy(id = "android:id/text1") + }) + + public List view; + + + @AndroidFindBy(className = "android.widget.TextView") + public static List Toast; + + @AndroidFindBy(className = "android.widget.EditText") + public static MobileElement box; + + + + /** + * URL + */ + public void url(String data) { + input.get(0).sendKeys(data); + + + + } + + /** + * USERNAME + */ + public void user(String data) { + input.get(1).sendKeys(data); + //dataLogs(data); + } + + /** + * PASSWORD + */ + public void pass(String data) { + input.get(2).sendKeys(data); + } + + /** + * HIDDEN EYE BUTTON + */ + + public void eyeButton() { + click.get(6).click(); + } + + /** + * LOGIN BUTTON + */ + public void logInButton() { + click.get(7).click(); + } + +// public void message() { +// System.out.println( click.get(9).getText()); +// } + + /** + * LOST PASSWORD LINK + */ + /* public void lostpass() { + click.get(8).click(); + }*/ + + /** + * VERSION TEXT + */ + + /* public void versionText() { + click.get(9).click(); + }*/ + + + /**Validate my login successful or not + * + * + */ + + public boolean isLogin() { + + if ( box.getText().equals("Search")) { + return true; + } + else { + return false; + } + } + + /** + * Click On settings By Tab Actions + * + */ + public void tab() { + tap(901,1945); + } + /** + * Click On signout By Tab Actions + * + */ + public void signOut() { + tap(732,1261); + } + + + public void clear() { + input.get(0).clear(); + input.get(1).clear(); + input.get(2).clear(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} + diff --git a/src/test/java/testcases/LoginTest.java b/src/test/java/testcases/LoginTest.java new file mode 100644 index 00000000..bcdb3d00 --- /dev/null +++ b/src/test/java/testcases/LoginTest.java @@ -0,0 +1,52 @@ +package testcases; + +import org.testng.Assert; +import org.testng.annotations.Test; + + +import BaseTest.TestBase; +import listeners.TestdataProvider; +import screens.DtLoginScreen; + +public class LoginTest extends TestBase{ + + + /** + * + * @param url + * @param username + * @param password + * + * DATA PROVIDER CLASS , AND THIS TESTCASE TAKE INVALID INPUTS + * DATA READ BY EXCELS + * @throws InterruptedException + */ + @Test(dataProviderClass=TestdataProvider.class,dataProvider="dp",priority = 1) + public void LoginInputs(String url,String username,String password) throws InterruptedException { + + DtLoginScreen dt=new DtLoginScreen(driver); + dt.url(url); + + dt.user(username); + dt.pass(password); + //dt.eyeButton(); + dt.logInButton(); + /** + * This page has a performance issues, it takes to much time too load, + * so delaying functions here + */ + Thread.sleep(8000); + + Assert.assertTrue(dt.isLogin(), "Login is NOT succcessful with valid parameters"); + Thread.sleep(1000); + dt.tab(); + Thread.sleep(1000); + dt.signOut(); + //Thread.sleep(3000); + +// dt.clear(); + + } + + } + diff --git a/src/test/java/utili/ExcelReader.java b/src/test/java/utili/ExcelReader.java new file mode 100644 index 00000000..c3b4f383 --- /dev/null +++ b/src/test/java/utili/ExcelReader.java @@ -0,0 +1,499 @@ +package utili; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Calendar; + +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFCreationHelper; +import org.apache.poi.xssf.usermodel.XSSFFont; +import org.apache.poi.xssf.usermodel.XSSFHyperlink; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +public class ExcelReader { + + + + public String path; + public FileInputStream fis = null; + public FileOutputStream fileOut =null; + private XSSFWorkbook workbook = null; + private XSSFSheet sheet = null; + private XSSFRow row =null; + private XSSFCell cell = null; + + public ExcelReader(String path) { + + this.path=path; + try { + fis = new FileInputStream(path); + workbook = new XSSFWorkbook(fis); + sheet = workbook.getSheetAt(0); + fis.close(); + } catch (Exception e) { + + e.printStackTrace(); + } + + } + + + // returns the row count in a sheet + public int getRowCount(String sheetName){ + int index = workbook.getSheetIndex(sheetName); + if(index==-1) + return 0; + else{ + sheet = workbook.getSheetAt(index); + int number=sheet.getLastRowNum()+1; + return number; + } + + } + + + + // returns the data from a cell + public String getCellData(String sheetName,String colName,int rowNum){ + try{ + if(rowNum <=0) + return ""; + + int index = workbook.getSheetIndex(sheetName); + int col_Num=-1; + if(index==-1) + return ""; + + sheet = workbook.getSheetAt(index); + row=sheet.getRow(0); + for(int i=0;i classLevelLog = new ThreadLocal(); +// public static ThreadLocal testLevelLog = new ThreadLocal(); +// public static String screenshotPath; +// public static String Error; + private static AndroidDriver driver; + + + public static void loadConfigProp(String propertyFileName) throws IOException + { + + FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"\\src\\test\\resources\\properties\\"+propertyFileName); + prop.load(fis); + + IMPLICIT_WAIT_TIME = Integer.parseInt(prop.getProperty("implicit.wait")); + EXPLICIT_WAIT_TIME = Integer.parseInt(prop.getProperty("explicit.wait")); + PLATFORM_NAME=prop.getProperty("platform.name"); + DEVICE_NAME=prop.getProperty("device.name"); + APPIUM_PORT = prop.getProperty("appium.server.port"); + AUTOMATION_INSTRUMENTATION=prop.getProperty("automation.instumentation"); +// NEW_COMMAND_TIMEOUT=prop.getProperty("new.command.timeout"); +// DEVICE_READY_TIMEOUT=prop.getProperty("device.ready.timeout"); + BASE_PKG = prop.getProperty("base.pkg"); + APP_ACTIVITY = prop.getProperty("application.activity"); + + + + } + +/* public static void loadIOSConfProp(String propertyFileName) { + + + } + + public static void setIOSCapabilities() { + + + + }*/ + + + public static void setCapabilities() { + + capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, + main_util.PLATFORM_NAME); + capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, + main_util.AUTOMATION_INSTRUMENTATION); + capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, main_util.APP_ACTIVITY); + capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,main_util.BASE_PKG); + } + + public static AndroidDriver getDriver() throws MalformedURLException { + serverUrl = new URL("http://localhost:" + APPIUM_PORT + "/wd/hub"); + driver = new AndroidDriver(serverUrl, capabilities); + driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME, TimeUnit.SECONDS); + return driver; + } + +/*public static AppiumDriver getIOSDriver() { + + + return driver; +}*/ + + +} diff --git a/src/test/resources/data/TestdataTwo.xlsx b/src/test/resources/data/TestdataTwo.xlsx new file mode 100644 index 00000000..86e89052 Binary files /dev/null and b/src/test/resources/data/TestdataTwo.xlsx differ diff --git a/src/test/resources/extentconfig/ReportsConfig.xml b/src/test/resources/extentconfig/ReportsConfig.xml new file mode 100644 index 00000000..a7869319 --- /dev/null +++ b/src/test/resources/extentconfig/ReportsConfig.xml @@ -0,0 +1,49 @@ + + + + + + standard + + + + UTF-8 + + + + https + + + Automation Reports + + + Automation Report for + + + Hybrid Framework + + + + yyyy-MM-dd + + + + HH:mm:ss + + + + + + + + + + + + \ No newline at end of file