NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.S2B_Automation.staticUIHandler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.testng.collections.Lists;

import com.S2B_Automation.dataEngine.csvOperation;
import com.S2B_Automation.utility.constants;
import com.beust.testng.TestNG;
import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;
import com.sun.istack.internal.logging.Logger;

import android.view.Display;
import io.appium.java_client.AppiumDriver;



/**
* Servlet implementation class DynamicUIHandler
*/
public class staticUIHandler extends HttpServlet {

//private static final long serialVersionUID = 1L;
private static final long serialVersionUID =102831973239L;
private static String environment = null;
private static String application = null;
private static String citURL = null;
private String platform = null;
public static String os = "";
public static String browser = "";
public static String value = "";
// Path to testData and mappingSheet
public static String path;

final static Logger log = Logger.getLogger(staticUIHandler.class);
static Properties p = System.getProperties();
/**
* @see HttpServlet#HttpServlet()
*/
public staticUIHandler() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
System.out.println("Log4JInitServlet is initializing log4j");
String log4jLocation = config.getInitParameter("log4j-properties-location");

// ServletContext sc = config.getServletContext();
// String webAppPath = sc.getRealPath("/");
// String log4jProp = webAppPath + log4jLocation;
// PropertyConfigurator.configure(log4jProp);
// super.init(config);

}

/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);

}


protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
@SuppressWarnings("deprecation")
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

JFrame f=new JFrame("S2B Automation Framework");
JLabel jl = new JLabel("Click on cancel to stop execution", JLabel.CENTER);
JButton b=new JButton("Cancel");

b.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent e){
destroy();
}
});

b.setBounds(50,100,95,30);
f.add(b);
f.add(jl);
f.setSize(400,400);
f.setLayout(null);
f.pack();
f.setVisible(true);

// b.setDefaultCloseOperation(EXIT_ON_CLOSE);


log.info("Log4JInitServlet is initializing log4j");
log.info("inside post method");
response.setContentType("text/html");

platform = request.getParameter("enterPlatform");
environment = request.getParameter("enterEnvironment");
application = request.getParameter("enterApplication");
citURL = request.getParameter("enterCITurl");
log.info("Platform" +platform);
log.info("Environment" +environment);

log.info("application:" +application);



//Code to read the OS detail and the browser detail
String browserDetails = request.getHeader("User-Agent");
String userAgent = browserDetails;
String user = userAgent.toLowerCase();


//=================OS=======================
if (userAgent.toLowerCase().indexOf("windows") >= 0 )
{
os = "Windows";
} else if(userAgent.toLowerCase().indexOf("mac") >= 0)
{
os = "Mac";
} else if(userAgent.toLowerCase().indexOf("x11") >= 0)
{
os = "Unix";
} else if(userAgent.toLowerCase().indexOf("android") >= 0)
{
os = "Android";
} else if(userAgent.toLowerCase().indexOf("iphone") >= 0)
{
os = "IPhone";
}else{
os = "UnKnown, More-Info: "+userAgent;
}
//===============Browser===========================
if (user.contains("msie"))
{
String substring=userAgent.substring(userAgent.indexOf("MSIE")).split(";")[0];
browser=substring.split(" ")[0].replace("MSIE", "IE")+"-"+substring.split(" ")[1];
} else if(user.contains("rv:11.0"))
{
String substring=userAgent.substring(userAgent.indexOf("rv")).split("\)")[0];
browser=substring.split(":")[0].replace("rv", "IE")+"-"+substring.split(":")[1];

}else if (user.contains("safari") && user.contains("version"))
{
browser=(userAgent.substring(userAgent.indexOf("Safari")).split(" ")[0]).split("/")[0]+"-"+(userAgent.substring(userAgent.indexOf("Version")).split(" ")[0]).split("/")[1];
} else if ( user.contains("opr") || user.contains("opera"))
{
if(user.contains("opera"))
browser=(userAgent.substring(userAgent.indexOf("Opera")).split(" ")[0]).split("/")[0]+"-"+(userAgent.substring(userAgent.indexOf("Version")).split(" ")[0]).split("/")[1];
else if(user.contains("opr"))
browser=((userAgent.substring(userAgent.indexOf("OPR")).split(" ")[0]).replace("/", "-")).replace("OPR", "Opera");
} else if (user.contains("chrome"))
{
browser=(userAgent.substring(userAgent.indexOf("Chrome")).split(" ")[0]).replace("/", "-");
} else if ((user.indexOf("mozilla/7.0") > -1) || (user.indexOf("netscape6") != -1) || (user.indexOf("mozilla/4.7") != -1) || (user.indexOf("mozilla/4.78") != -1) || (user.indexOf("mozilla/4.08") != -1) || (user.indexOf("mozilla/3") != -1) )
{
//browser=(userAgent.substring(userAgent.indexOf("MSIE")).split(" ")[0]).replace("/", "-");
browser = "Netscape-?";

} else if (user.contains("firefox"))
{
browser=(userAgent.substring(userAgent.indexOf("Firefox")).split(" ")[0]).replace("/", "-");
} else if(user.contains("rv"))
{
browser="IE-" + user.substring(user.indexOf("rv") + 3, user.indexOf(")"));
} else
{
browser = "UnKnown, More-Info: "+userAgent;
}
log.info("Your Operating System="+os);
log.info("Your Browser Name="+browser);


if(os.equalsIgnoreCase("mac")){
value = getSystemName();
path=value+"/Documents";
log.info("MAC path :" +path);
}else if(os.equalsIgnoreCase("windows")){
path =value+"\Documents";
log.info("WIndows path :" +path);
}


setExtentReport();
//Read CSV files
csvOperation csv = new csvOperation();
csv.readTestData();
// destroy();

}

//Returns the path of mappingSheet
public static String getMappingSheet(){
String mappingSheetPath = "/s2bAutomation/TestData/mappingSheet.csv";
log.info("getMappingSHeet(): "+path+mappingSheetPath);
return path+mappingSheetPath;

}

//Returns the path of testDataSheet
public static String getTestDataSheet(){
String testdataSheetPath = "/s2bAutomation/TestData/testData.csv";
log.info("getTestDataSheet() :"+path+testdataSheetPath);
return path+testdataSheetPath;

}

//Returns System name
public static String getSystemName(){
String systemName="";
systemName= (String) p.get("user.home");
log.info("System Name:" +systemName);
return systemName;
}

//Returns platform
public String getPlatform() {
log.info("Servlet:getPlatform() method initiated: " + platform);
return platform;
}

//Returns Environment
public static String getEnvironment() {
log.info("Servlet:getEnvironment() method initiated: " + environment);
return environment;
}


public static String getCITUrl(){
log.info("getCITUrl() method initiated: " + environment);
return citURL;
}

//Common method to move and rename mapping sheet and test data sheet
public void fileRename(String oldFilePath, String newFilePath) {

File f = new File(oldFilePath);
File newF = new File(newFilePath);
System.out.println(newF);
if (f.renameTo(newF)) {
log.info("FIle Renamed");
} else {
log.info("File rename failed");
}

}

public void setExtentReport(){

System.out.println("Configuring Extent Report");

//False will not overwrite the files
constants.extentReporter = new ExtentReports(constants.pathOfReport +
(new SimpleDateFormat("yyyyMMddHHmm'.html'").format(new Date())),
true,
DisplayOrder.NEWEST_FIRST);

//Adding Environmental Variables
constants.extentReporter.addSystemInfo("Environment", constants.environment);
constants.extentReporter.addSystemInfo("Test Data","<a href="+constants.pathToTestData+"><span class='label info'>Test Data</span></a>" );
constants.extentReporter.addSystemInfo("Mapping Sheet ", "<a href="+constants.pathToMappingSheet+"><span class='label info'>Mapping Sheet</span></a>");

//Configuration done for extentReport of 2.0.1 version
// constants.extent.config().insertCustomStyles("/Users/v4/Documents/Atoms/extentrepotconfig.xml");

//Configuring the HTML report.
constants.extentReporter.loadConfig(new File(constants.extentReportConfigFile));

System.out.println("extentReportConfigFile" +constants.extentReportConfigFile);
}

public static String getRelPath(String fileName){
File directory = new File(fileName);
System.out.println(directory.getPath());
return directory.getPath();

}

/**
* @see Servlet#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
String oldMappingSheetPath = getMappingSheet();
String newMappingSheetPath = path + "/s2bAutomation/Archive/mappingSheetArchive.csv";

String oldTestDataPath = getTestDataSheet();
String newTestDataPath = path + "/s2bAutomation/Archive/testDataArchive.csv";

fileRename(oldMappingSheetPath, newMappingSheetPath);
fileRename(oldTestDataPath, newTestDataPath);

System.out.println("Servelt destroy");
constants.extentReporter.endTest(constants.extentTest);

//Closing report
constants.extentReporter.flush();
constants.extentReporter.close();

//Closing driver.
constants.driver.close();
constants.driver.quit();

//Close App
((AppiumDriver)constants.driver).closeApp();
//STop Appium Server
constants.appiumService.stop();

}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.