Banking Guru 99
Banking Guru 99
Banking Guru 99
utilities;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
Properties pro;
public ReadConfig()
{
File src=new File("./Configuration/config.properties") ;
try {
FileInputStream fis= new FileInputStream(src);
pro=new Properties();
pro.load(fis);
}
catch(Exception e)
{
System.out.println("Exception is "+ e.getMessage());
}}
public String getAppl()
{
String url=pro.getProperty("baseURL");
return url;
}
public String getUser()
{
String user=pro.getProperty("username");
return user;
}
public String getpass()
{
String pass=pro.getProperty("password");
return pass;
}
public String getChromeUrl()
{
String Chrome=pro.getProperty("chromepath");
return Chrome;
}
public String getFirefoxUrl()
{
String Chrome=pro.getProperty("firefoxpath");
return Chrome;
}
}
___________________________________________________________________________________
___________________________________________________________________________________
package com.inetbankin.utilities;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;
// @BeforeTest
public void onStart(ITestContext testContext) {
try {
spark.loadXMLConfig("C:\\Users\\DemuduDonka\\eclipse-workspace\\
intBankingV1\\extent-config.xml");
} catch (IOException e) {
e.printStackTrace();
}
/*
* try { spark.loadXMLConfig(CONF); } catch (IOException e) {
*
* e.printStackTrace(); }
*/
extent = new ExtentReports();
extent.attachReporter(spark);
extent.setSystemInfo("Host name", "localhost");
extent.setSystemInfo("Evironment", "QA");
extent.setSystemInfo("user", "demudu");
spark.config().setTheme(Theme.DARK);
}
//@AfterMethod
public void onTestSuccess(ITestResult result) {
log1 = extent.createTest(result.getName());
log1.log(Status.PASS, MarkupHelper.createLabel(result.getName() + "Test
Case Passed", ExtentColor.GREEN));
log1.pass(result.getThrowable());
// // System.out.println(result.getName());
String screenshotPath = "C:\\Users\\DemuduDonka\\eclipse-workspace\\
intBankingV1\\Screenshots\\"
+ result.getName() + ".png";
File f = new File(screenshotPath);
if (f.exists()) {
log1.pass("Screenshot is below:" +
log1.addScreenCaptureFromPath(screenshotPath));
}
//@AfterMethod
public void onTestFailure(ITestResult result) {
log1 = extent.createTest(result.getName());
log1.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + "Test
Case Failed", ExtentColor.RED));
String screenshotPath = "C:\\Users\\DemuduDonka\\eclipse-workspace\\
intBankingV1\\Screenshots\\"
+ result.getName() + ".png";
File f = new File(screenshotPath);
if (f.exists()) {
log1.fail("Screenshot is below:" +
log1.addScreenCaptureFromPath(screenshotPath));
}
}
//@AfterMethod
public void onTestSkipped(ITestResult result) {
log1 = extent.createTest(result.getName());
log1.log(Status.PASS, MarkupHelper.createLabel(result.getName() + "Test
Case Skipped", ExtentColor.BROWN));
}
//@AfterTest
public void onFinish(ITestContext testContext) {
extent.flush();
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________________________________________
package com.inetbankin.utilities;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
fi = new FileInputStream(xlfile);
wb = new XSSFWorkbook(fi);
ws = wb.getSheet(xlsheet);
int rowcount = ws.getLastRowNum();
wb.close();
fi.close();
return rowcount;
}
fi = new FileInputStream(xlfile);
wb = new XSSFWorkbook(fi);
ws = wb.getSheet(xlsheet);
row = ws.getRow(rownum);
int cellcount = row.getLastCellNum();
wb.close();
fi.close();
return cellcount;
}
public static void setCellData(String xlfile, String xlsheet, int rownum, int
colnum, String data)
throws IOException {
fi = new FileInputStream(xlfile);
wb = new XSSFWorkbook(fi);
ws = wb.getSheet(xlsheet);
row = ws.getRow(rownum);
cell = row.getCell(colnum);
cell.setCellValue(data);
fo = new FileOutputStream(xlfile);
wb.write(fo);
wb.close();
fi.close();
fo.close();
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________________________________________________________
package com.inetbanking.pageObjects;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
@FindBy(name = "uid")
WebElement txtUsername;
@FindBy(name = "password")
WebElement txtPassword;
@FindBy(name = "btnLogin")
WebElement login;
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________________________________________________________
package com.inetbanking.Testcases;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
//import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
//import org.apache.log4j.Logger;
//import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import com.inetbankin.utilities.ReadConfig;
import io.github.bonigarcia.wdm.WebDriverManager;
@Parameters("browser")
@BeforeClass
public void setup(String br) throws InterruptedException {
logger = Logger.getLogger("initBankingV1");
PropertyConfigurator.configure("Log4j.properties");
if (br.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", chromepath);
// WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
} else if (br.equals("firefox")) {
System.setProperty("webdriver.gecko.driver", firefoxpath);
// WebDriverManager.chromedriver().setup();
driver = new FirefoxDriver();
driver.manage().window().maximize();
}
// driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
driver.get(baseURL);
}
@AfterClass
public void teardown() {
driver.quit();
}
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________
package com.inetbanking.Testcases;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.inetbanking.pageObjects.LoginPage;
@Test
public void LoginTest() throws InterruptedException, IOException {
logger.info("base url opened");
LoginPage lp = new LoginPage(driver);
lp.setusername(username);
logger.info("entered username");
lp.setpassword(password);
logger.info("entered password");
lp.clickSubmit();
Thread.sleep(5000);
driver.getTitle();
System.out.println(driver.getTitle());
if (driver.getTitle().equals("Guru99 Bank Manager HomePage")) {
captureScreen(driver, "LoginTest1");
Assert.assertTrue(true);
logger.info("login test passed");
} else {
// captureScreen(driver ,"LoginTest") ;
Assert.assertTrue(false);
logger.info("login test failed");
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________________________________________________________
package com.inetbanking.Testcases;
import java.io.IOException;
import org.openqa.selenium.NoAlertPresentException;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.inetbankin.utilities.XLUtils;
import com.inetbanking.pageObjects.LoginPage;
if (isAlertPresent() == true) {
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
Assert.assertTrue(false);
logger.warn("login failed");
} else {
Assert.assertTrue(true);
logger.info("login passed");
lo.logoutMethod();
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
}
}
@DataProvider(name = "LoginData")
String[][] getData() throws IOException
{
String path = "C:\\Users\\DemuduDonka\\eclipse-workspace\\
intBankingV1\\src\\main\\java\\com\\inetbanking\\Testdata\\loginData1.xlsx";
int rownum = XLUtils.getRowCount(path, "Sheet1");
int colcount = XLUtils.getCellCount(path, "Sheet1", 1);
String logindata[][] = new String[rownum][colcount];
}
___________________________________________________________________________________
___________________________________________________________________________________
______________________________________________________________
config.properties:
baseURL=https://demo.guru99.com/V4/
username=mngr425620
password=zEtamAs
chromepath=./Drivers/chromedriver.exe
firefoxpath=./Drivers/geckodriver.exe
___________________________________________________________________________________
___________________________________________________________________________________
__________________________________________________
extent-config.xml:
});
]]>
</scripts>
]]>
</styles>
</configuration>
</extentreports>
___________________________________________________________________________________
___________________________________________________________________________________
____________________________________________________________
Log4j.properties:
log4j.rootLogger=INFO,CONSOLE,R,HTML,TTCC
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.TTCC=org.apache.log4j.RollingFileAppender
log4j.appender.HTML=org.apache.log4j.FileAppender
log4j.appender.R.File=./log/testlog.log
log4j.appender.TTCC.File=./log/testlog1.log
log4j.appender.HTML.File=./log/application.html
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern= %5p [%t] (%F:%L)- %m%n
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d - %c -%p - %m%n
log4j.appender.TTCC.layout=org.apache.log4j.TTCCLayout
log4j.appender.TTCC.layout.DateFormat=ISO8601
log4j.appender.HTML.layout=org.apache.log4j.HTMLLayout
log4j.appender.HTML.layout.Title=Application log
log4j.appender.HTML.layout.LocationInfo=true
___________________________________________________________________________________
___________________________________________________________________________________
____________________________________________________________
POM.XML:
<groupId>intBankingV1</groupId>
<artifactId>intBankingV1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>intBankingV1</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>5.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults
(may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-
bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
___________________________________________________________________________________
___________________________________________________________________________________
_______________________________________________________________
testng.xml:
<listeners>
<listener class-name="com.inetbankin.utilities.Reporting"/>
</listeners>