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

automation files #478

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
55 changes: 55 additions & 0 deletions src/test/java/BaseScreen/ScreenBase.java
Original file line number Diff line number Diff line change
@@ -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();


}
}
120 changes: 120 additions & 0 deletions src/test/java/BaseTest/TestBase.java
Original file line number Diff line number Diff line change
@@ -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<ExtentTest> classLevelLog = new ThreadLocal<ExtentTest>();
public static ThreadLocal<ExtentTest> testLevelLog = new ThreadLocal<ExtentTest>();
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<MobileElement> ele) {
ele.clear();

}*/


}
93 changes: 93 additions & 0 deletions src/test/java/listeners/CustomListeners.java
Original file line number Diff line number Diff line change
@@ -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("<details>" + "<summary>" + "<b>" + "<font color=" + "red>" + "Exception Occured:Click to see"
+ "</font>" + "</b >" + "</summary>" + excepionMessage.replaceAll(",", "<br>") + "</details>"
+ " \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();
}

}



}
41 changes: 41 additions & 0 deletions src/test/java/listeners/TestdataProvider.java
Original file line number Diff line number Diff line change
@@ -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;

}
}



Loading