Automation base setup done. To Automate Quest Creation

This commit is contained in:
Arul 2025-08-07 02:40:12 +05:30
commit fd224878d5
35 changed files with 556 additions and 0 deletions

0
README.md Normal file
View File

75
pom.xml Normal file
View File

@ -0,0 +1,75 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ghost.temple</groupId>
<artifactId>ghost-temple-automation</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ghost-temple-automation</name>
<dependencies>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- Cucumber -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.15.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.15.0</version>
<scope>test</scope>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.21.0</version>
</dependency>
<!-- WebDriverManager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.7.0</version>
</dependency>
<!-- Apache POI for Excel - MS Excel -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Compiler Plugin for Java 17 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,43 @@
package com.ghost.temple;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import java.io.*;
import java.util.Set;
public class CookieManager {
private static final String COOKIE_FILE = "cookies.ser";
// Save cookies to file
public static void saveCookies(WebDriver driver) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(COOKIE_FILE))) {
Set<Cookie> cookies = driver.manage().getCookies();
oos.writeObject(cookies);
System.out.println("Cookies saved 🍪✅");
} catch (IOException e) {
e.printStackTrace();
}
}
// Load cookies from file
@SuppressWarnings("unchecked")
public static void loadCookies(WebDriver driver, String url) {
File cookieFile = new File(COOKIE_FILE);
if (!cookieFile.exists()) return;
driver.get(url); // Need to open site before setting cookies
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(COOKIE_FILE))) {
Set<Cookie> cookies = (Set<Cookie>) ois.readObject();
for (Cookie cookie : cookies) {
driver.manage().addCookie(cookie);
}
driver.navigate().refresh(); // Apply cookies
System.out.println("Cookies loaded 🍪🔁");
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,27 @@
package com.ghost.temple;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
public class ExcelUtils {
public static Map<String, String> fetchData(String sheetName) {
Map<String, String> data = new HashMap<>();
try (FileInputStream fis = new FileInputStream("src/main/resources/testData.xlsx");
Workbook workbook = new XSSFWorkbook(fis)) {
Sheet sheet = workbook.getSheet(sheetName);
Row header = sheet.getRow(0);
Row values = sheet.getRow(1);
for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
data.put(header.getCell(i).getStringCellValue(), values.getCell(i).getStringCellValue());
}
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
}

View File

@ -0,0 +1,41 @@
package com.ghost.temple;
import org.openqa.selenium.*;
public class ReusableFunctions {
public static boolean checkWebElement(WebElement element) {
try {
return element.isDisplayed() && element.isEnabled();
} catch (Exception e) {
return false;
}
}
public static void click(WebElement element) {
if (checkWebElement(element)) {
element.click();
}
}
public static void fillInput(WebElement element, String value) {
if (checkWebElement(element)) {
element.clear();
element.sendKeys(value);
}
}
public static void scrollIntoView(WebDriver driver, WebElement element) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
}
// 🌐 NEW: Open a specific URL
public static void openUrl(WebDriver driver, String url) {
try {
driver.get(url);
} catch (Exception e) {
System.out.println("Error navigating to URL: " + url);
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,44 @@
package com.ghost.temple.driver;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import java.io.File;
public class DriverManager {
private static WebDriver driver;
public static void initDriver() {
if (driver == null) {
WebDriverManager.firefoxdriver().setup();
// 🌟 Point to your existing Firefox profile
String userProfile = System.getProperty("user.home") + "/.mozilla/firefox/";
File profilesDir = new File(userProfile);
File[] profiles = profilesDir.listFiles((dir, name) -> name.endsWith(".default-release"));
if (profiles == null || profiles.length == 0) {
throw new RuntimeException("No Firefox profile found 😭");
}
FirefoxOptions options = new FirefoxOptions();
options.setProfile(new org.openqa.selenium.firefox.FirefoxProfile(profiles[0]));
driver = new FirefoxDriver(options);
driver.manage().window().maximize();
System.out.println("Launched Firefox with real profile 😎");
}
}
public static WebDriver getDriver() {
return driver;
}
public static void quitDriver() {
if (driver != null) {
driver.quit();
driver = null;
}
}
}

View File

@ -0,0 +1,18 @@
package com.ghost.temple.hooks;
import com.ghost.temple.driver.DriverManager;
import io.cucumber.java.After;
import io.cucumber.java.Before;
public class Hooks {
@Before
public void setUp() {
DriverManager.initDriver();
}
@After
public void tearDown() {
DriverManager.quitDriver();
}
}

Binary file not shown.

View File

@ -0,0 +1,10 @@
package com.ghost.temple;
import org.junit.Test;
public class AppTest {
@Test
public void basicTest() {
System.out.println("Ghost Temple is alive 🔥");
}
}

View File

@ -0,0 +1,24 @@
package com.ghost.temple;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.junit.After;
import org.junit.Before;
public class BaseTest {
protected WebDriver driver;
@Before
public void setUp() {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}

View File

@ -0,0 +1,16 @@
package com.ghost.temple;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = {"com.ghost.temple.stepdefs", "com.ghost.temple.hooks"}, //including Hooks
plugin = { "pretty", "html:target/cucumber-report.html" },
monochrome = true
)
public class TestRunner {
}

View File

@ -0,0 +1,21 @@
package com.ghost.temple.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class QuestCreator {
WebDriver driver;
private By addQuestBtnLocator = By.xpath("//a[@href='/equipment']/button[contains(text(),'View All')]");
public QuestCreator(WebDriver driver) {
this.driver = driver;
}
public void clickAddQuest() {
WebElement addQuestBtn = driver.findElement(addQuestBtnLocator);
addQuestBtn.click();
}
}

View File

@ -0,0 +1,29 @@
package com.ghost.temple.stepdefs;
import com.ghost.temple.driver.DriverManager;
import com.ghost.temple.pages.QuestCreator;
import com.ghost.temple.ReusableFunctions;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import org.openqa.selenium.WebDriver;
public class QuestCreatorStepDefs {
WebDriver driver;
QuestCreator questPage;
public QuestCreatorStepDefs() {
this.driver = DriverManager.getDriver();
this.questPage = new QuestCreator(driver);
}
@Given("I open the solo level page")
public void i_open_the_solo_level_page() {
ReusableFunctions.openUrl(driver, "http://192.168.31.73:3000/");
}
@When("I click the Add Quest button")
public void i_click_the_add_quest_button() {
questPage.clickAddQuest();
}
}

View File

@ -0,0 +1,5 @@
Feature: Solo Leveling Quest Management
Scenario: Open Solo Leveling page and click Add Quest
Given I open the solo level page
When I click the Add Quest button

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
com/ghost/temple/ExcelUtils.class
com/ghost/temple/ReusableFunctions.class

View File

@ -0,0 +1,5 @@
/home/arul/ghost-temple-automation/ghost-temple-automation/src/main/java/com/ghost/temple/ReusableFunctions.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/main/java/com/ghost/temple/hooks/Hooks.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/main/java/com/ghost/temple/driver/DriverManager.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/main/java/com/ghost/temple/CookieManager.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/main/java/com/ghost/temple/ExcelUtils.java

View File

@ -0,0 +1,4 @@
com/ghost/temple/pages/QuestCreator.class
com/ghost/temple/TestRunner.class
com/ghost/temple/AppTest.class
com/ghost/temple/BaseTest.class

View File

@ -0,0 +1,5 @@
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/pages/QuestCreator.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/stepdefs/QuestCreatorStepDefs.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/AppTest.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/BaseTest.java
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/TestRunner.java

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="1" failures="0" name="com.ghost.temple.AppTest" time="0" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="17.0.15+6-Debian-1deb12u1"/>
<property name="sun.boot.library.path" value="/usr/lib/jvm/java-17-openjdk-amd64/lib"/>
<property name="maven.multiModuleProjectDirectory" value="/home/arul/ghost-temple-automation/ghost-temple-automation"/>
<property name="java.vm.vendor" value="Debian"/>
<property name="java.vendor.url" value="https://tracker.debian.org/openjdk-17"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="path.separator" value=":"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="user.country" value="IN"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/home/arul/ghost-temple-automation/ghost-temple-automation"/>
<property name="java.vm.compressedOopsMode" value="32-bit"/>
<property name="java.runtime.version" value="17.0.15+6-Debian-1deb12u1"/>
<property name="os.arch" value="amd64"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Linux"/>
<property name="classworlds.conf" value="/usr/share/maven/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib"/>
<property name="maven.conf" value="/usr/share/maven/conf"/>
<property name="jdk.debug" value="release"/>
<property name="java.class.version" value="61.0"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="6.1.0-37-amd64"/>
<property name="library.jansi.path" value="/usr/share/maven/lib/jansi-native"/>
<property name="user.home" value="/home/arul"/>
<property name="user.timezone" value="Asia/Kolkata"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="17"/>
<property name="user.name" value="arul"/>
<property name="java.class.path" value="/usr/share/maven/boot/plexus-classworlds-2.x.jar"/>
<property name="java.vm.specification.version" value="17"/>
<property name="sun.arch.data.model" value="64"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher test"/>
<property name="java.home" value="/usr/lib/jvm/java-17-openjdk-amd64"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="java.version" value="17.0.15"/>
<property name="native.encoding" value="UTF-8"/>
<property name="java.vendor" value="Debian"/>
<property name="sun.stderr.encoding" value="UTF-8"/>
<property name="java.specification.maintenance.version" value="1"/>
<property name="maven.home" value="/usr/share/maven"/>
<property name="file.separator" value="/"/>
<property name="java.version.date" value="2025-04-15"/>
<property name="java.vendor.url.bug" value="https://bugs.debian.org/openjdk-17"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="sun.cpu.endian" value="little"/>
<property name="sun.stdout.encoding" value="UTF-8"/>
</properties>
<testcase classname="com.ghost.temple.AppTest" name="basicTest" time="0"/>
</testsuite>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="1" failures="0" name="com.ghost.temple.TestRunner" time="11.29" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="17.0.15+6-Debian-1deb12u1"/>
<property name="sun.boot.library.path" value="/usr/lib/jvm/java-17-openjdk-amd64/lib"/>
<property name="maven.multiModuleProjectDirectory" value="/home/arul/ghost-temple-automation/ghost-temple-automation"/>
<property name="java.vm.vendor" value="Debian"/>
<property name="java.vendor.url" value="https://tracker.debian.org/openjdk-17"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="path.separator" value=":"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="user.country" value="IN"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/home/arul/ghost-temple-automation/ghost-temple-automation"/>
<property name="java.vm.compressedOopsMode" value="32-bit"/>
<property name="java.runtime.version" value="17.0.15+6-Debian-1deb12u1"/>
<property name="os.arch" value="amd64"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Linux"/>
<property name="classworlds.conf" value="/usr/share/maven/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib"/>
<property name="maven.conf" value="/usr/share/maven/conf"/>
<property name="jdk.debug" value="release"/>
<property name="java.class.version" value="61.0"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="6.1.0-37-amd64"/>
<property name="library.jansi.path" value="/usr/share/maven/lib/jansi-native"/>
<property name="user.home" value="/home/arul"/>
<property name="user.timezone" value="Asia/Kolkata"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="17"/>
<property name="user.name" value="arul"/>
<property name="java.class.path" value="/usr/share/maven/boot/plexus-classworlds-2.x.jar"/>
<property name="java.vm.specification.version" value="17"/>
<property name="sun.arch.data.model" value="64"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher test"/>
<property name="java.home" value="/usr/lib/jvm/java-17-openjdk-amd64"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="java.version" value="17.0.15"/>
<property name="native.encoding" value="UTF-8"/>
<property name="java.vendor" value="Debian"/>
<property name="sun.stderr.encoding" value="UTF-8"/>
<property name="java.specification.maintenance.version" value="1"/>
<property name="maven.home" value="/usr/share/maven"/>
<property name="file.separator" value="/"/>
<property name="java.version.date" value="2025-04-15"/>
<property name="java.vendor.url.bug" value="https://bugs.debian.org/openjdk-17"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="sun.cpu.endian" value="little"/>
<property name="sun.stdout.encoding" value="UTF-8"/>
</properties>
<testcase classname="Solo Leveling Quest Management" name="Open Solo Leveling page and click Add Quest" time="11.29"/>
</testsuite>

View File

@ -0,0 +1,4 @@
-------------------------------------------------------------------------------
Test set: com.ghost.temple.AppTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec

View File

@ -0,0 +1,4 @@
-------------------------------------------------------------------------------
Test set: com.ghost.temple.TestRunner
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.695 sec

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,5 @@
Feature: Solo Leveling Quest Management
Scenario: Open Solo Leveling page and click Add Quest
Given I open the solo level page
When I click the Add Quest button