ZenProject/src/main/java/zacksolutions/base/Initialization.java
Sami 6fe7a83a5a
Some checks failed
Zakaria/ZenProject/pipeline/head There was a failure building this commit
Zenful/ZenProject/pipeline/head There was a failure building this commit
fix: 9 - Updating Jenkinsfile
2024-09-29 01:22:17 -04:00

80 lines
2.6 KiB
Java

package zacksolutions.base;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.Properties;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.ExtentReports;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Initialization {
// let's set up our variables
public static WebDriver driver;
public static Properties prop;
public static ExtentReports extent;
public static ExtentTest test;
public Initialization() {
// let's use the config.properties file to set up our global variables...
try {
prop = new Properties();
FileInputStream fis = new FileInputStream(
System.getProperty("user.dir") + "/src/main/java/zacksolutions/config/config.properties");
prop.load(fis);
} catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
}
}
public void BrowserInit() {
// our EXTENTREPORTS SETUP!
String path = System.getProperty("user.dir") + "/reports/index.html";
ExtentSparkReporter spark = new ExtentSparkReporter(path);
spark.config().setDocumentTitle("Zen Test Case");
spark.config().setReportName("Zenful");
extent = new ExtentReports();
extent.attachReporter(spark);
extent.setSystemInfo("Tester ID: ", "Sami");
// conditioning our WebDriver with an if statement
String browsername = prop.getProperty("browserC");
// launching FireFox
if (browsername.equalsIgnoreCase("firefox")) {
// System.setProperty("web-driver.gecko.driver","user.dir" +
// "/drivers/geckodriver");
// driver = new FirefoxDriver();
driver.get(prop.getProperty("url"));
}
// launching Chrome
if (browsername.equalsIgnoreCase("chrome")) {
// System.setProperty("web-driver.gecko.driver", "user.dir" +
// "/drivers/chromedriver");
// driver = new ChromeDriver();
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(options);
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--headless");
options.addArguments("--remote-debugging-port=9222");
options.setBinary("/usr/bin/google-chrome");
driver.get(prop.getProperty("url"));
}
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
}
}