commit fd224878d54f34728e013594c2f13a78dd373433 Author: Arul Date: Thu Aug 7 02:40:12 2025 +0530 Automation base setup done. To Automate Quest Creation diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fb2495b --- /dev/null +++ b/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + com.ghost.temple + ghost-temple-automation + jar + 1.0-SNAPSHOT + ghost-temple-automation + + + + + junit + junit + 4.13.2 + test + + + + + io.cucumber + cucumber-java + 7.15.0 + + + io.cucumber + cucumber-junit + 7.15.0 + test + + + + + org.seleniumhq.selenium + selenium-java + 4.21.0 + + + + + io.github.bonigarcia + webdrivermanager + 5.7.0 + + + + + org.apache.poi + poi + 5.2.3 + + + org.apache.poi + poi-ooxml + 5.2.3 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 17 + 17 + + + + + diff --git a/src/main/java/com/ghost/temple/CookieManager.java b/src/main/java/com/ghost/temple/CookieManager.java new file mode 100644 index 0000000..20bf063 --- /dev/null +++ b/src/main/java/com/ghost/temple/CookieManager.java @@ -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 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 cookies = (Set) 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(); + } + } +} diff --git a/src/main/java/com/ghost/temple/ExcelUtils.java b/src/main/java/com/ghost/temple/ExcelUtils.java new file mode 100644 index 0000000..b006b2c --- /dev/null +++ b/src/main/java/com/ghost/temple/ExcelUtils.java @@ -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 fetchData(String sheetName) { + Map 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; + } +} \ No newline at end of file diff --git a/src/main/java/com/ghost/temple/ReusableFunctions.java b/src/main/java/com/ghost/temple/ReusableFunctions.java new file mode 100644 index 0000000..a202bde --- /dev/null +++ b/src/main/java/com/ghost/temple/ReusableFunctions.java @@ -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(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/ghost/temple/driver/DriverManager.java b/src/main/java/com/ghost/temple/driver/DriverManager.java new file mode 100644 index 0000000..04e14dc --- /dev/null +++ b/src/main/java/com/ghost/temple/driver/DriverManager.java @@ -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; + } + } +} diff --git a/src/main/java/com/ghost/temple/hooks/Hooks.java b/src/main/java/com/ghost/temple/hooks/Hooks.java new file mode 100644 index 0000000..10bd6da --- /dev/null +++ b/src/main/java/com/ghost/temple/hooks/Hooks.java @@ -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(); + } +} diff --git a/src/main/resources/testData.xlsx b/src/main/resources/testData.xlsx new file mode 100644 index 0000000..1e67f50 Binary files /dev/null and b/src/main/resources/testData.xlsx differ diff --git a/src/test/java/com/ghost/temple/AppTest.java b/src/test/java/com/ghost/temple/AppTest.java new file mode 100644 index 0000000..d93f23c --- /dev/null +++ b/src/test/java/com/ghost/temple/AppTest.java @@ -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 🔥"); + } +} \ No newline at end of file diff --git a/src/test/java/com/ghost/temple/BaseTest.java b/src/test/java/com/ghost/temple/BaseTest.java new file mode 100644 index 0000000..35f31cb --- /dev/null +++ b/src/test/java/com/ghost/temple/BaseTest.java @@ -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(); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/ghost/temple/TestRunner.java b/src/test/java/com/ghost/temple/TestRunner.java new file mode 100644 index 0000000..c998ef8 --- /dev/null +++ b/src/test/java/com/ghost/temple/TestRunner.java @@ -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 { +} diff --git a/src/test/java/com/ghost/temple/pages/QuestCreator.java b/src/test/java/com/ghost/temple/pages/QuestCreator.java new file mode 100644 index 0000000..2c2402e --- /dev/null +++ b/src/test/java/com/ghost/temple/pages/QuestCreator.java @@ -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(); + } + +} diff --git a/src/test/java/com/ghost/temple/stepdefs/QuestCreatorStepDefs.java b/src/test/java/com/ghost/temple/stepdefs/QuestCreatorStepDefs.java new file mode 100644 index 0000000..9f60940 --- /dev/null +++ b/src/test/java/com/ghost/temple/stepdefs/QuestCreatorStepDefs.java @@ -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(); + } +} diff --git a/src/test/resources/features/questCreator.feature b/src/test/resources/features/questCreator.feature new file mode 100644 index 0000000..6bf5f4e --- /dev/null +++ b/src/test/resources/features/questCreator.feature @@ -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 diff --git a/target/classes/com/ghost/temple/CookieManager.class b/target/classes/com/ghost/temple/CookieManager.class new file mode 100644 index 0000000..944f3b5 Binary files /dev/null and b/target/classes/com/ghost/temple/CookieManager.class differ diff --git a/target/classes/com/ghost/temple/ExcelUtils.class b/target/classes/com/ghost/temple/ExcelUtils.class new file mode 100644 index 0000000..cd81ef2 Binary files /dev/null and b/target/classes/com/ghost/temple/ExcelUtils.class differ diff --git a/target/classes/com/ghost/temple/ReusableFunctions.class b/target/classes/com/ghost/temple/ReusableFunctions.class new file mode 100644 index 0000000..3369b22 Binary files /dev/null and b/target/classes/com/ghost/temple/ReusableFunctions.class differ diff --git a/target/classes/com/ghost/temple/driver/DriverManager.class b/target/classes/com/ghost/temple/driver/DriverManager.class new file mode 100644 index 0000000..73ff128 Binary files /dev/null and b/target/classes/com/ghost/temple/driver/DriverManager.class differ diff --git a/target/classes/com/ghost/temple/hooks/Hooks.class b/target/classes/com/ghost/temple/hooks/Hooks.class new file mode 100644 index 0000000..d8d1fc9 Binary files /dev/null and b/target/classes/com/ghost/temple/hooks/Hooks.class differ diff --git a/target/classes/testData.xlsx b/target/classes/testData.xlsx new file mode 100644 index 0000000..1e67f50 Binary files /dev/null and b/target/classes/testData.xlsx differ diff --git a/target/cucumber-report.html b/target/cucumber-report.html new file mode 100644 index 0000000..7e27be3 --- /dev/null +++ b/target/cucumber-report.html @@ -0,0 +1,50 @@ + + + + Cucumber + + + + + + +
+
+ + + + diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..8c28125 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com/ghost/temple/ExcelUtils.class +com/ghost/temple/ReusableFunctions.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..62eb2de --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -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 diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..eebf0df --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -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 diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..db40b83 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -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 diff --git a/target/surefire-reports/TEST-com.ghost.temple.AppTest.xml b/target/surefire-reports/TEST-com.ghost.temple.AppTest.xml new file mode 100644 index 0000000..71d33c4 --- /dev/null +++ b/target/surefire-reports/TEST-com.ghost.temple.AppTest.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/TEST-com.ghost.temple.TestRunner.xml b/target/surefire-reports/TEST-com.ghost.temple.TestRunner.xml new file mode 100644 index 0000000..3adf6e5 --- /dev/null +++ b/target/surefire-reports/TEST-com.ghost.temple.TestRunner.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/com.ghost.temple.AppTest.txt b/target/surefire-reports/com.ghost.temple.AppTest.txt new file mode 100644 index 0000000..e7aa08b --- /dev/null +++ b/target/surefire-reports/com.ghost.temple.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.ghost.temple.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec diff --git a/target/surefire-reports/com.ghost.temple.TestRunner.txt b/target/surefire-reports/com.ghost.temple.TestRunner.txt new file mode 100644 index 0000000..f1bb658 --- /dev/null +++ b/target/surefire-reports/com.ghost.temple.TestRunner.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.ghost.temple.TestRunner +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.695 sec diff --git a/target/test-classes/com/ghost/temple/AppTest.class b/target/test-classes/com/ghost/temple/AppTest.class new file mode 100644 index 0000000..4ad0b0e Binary files /dev/null and b/target/test-classes/com/ghost/temple/AppTest.class differ diff --git a/target/test-classes/com/ghost/temple/BaseTest.class b/target/test-classes/com/ghost/temple/BaseTest.class new file mode 100644 index 0000000..22e97f4 Binary files /dev/null and b/target/test-classes/com/ghost/temple/BaseTest.class differ diff --git a/target/test-classes/com/ghost/temple/TestRunner.class b/target/test-classes/com/ghost/temple/TestRunner.class new file mode 100644 index 0000000..debbf9e Binary files /dev/null and b/target/test-classes/com/ghost/temple/TestRunner.class differ diff --git a/target/test-classes/com/ghost/temple/pages/QuestCreator.class b/target/test-classes/com/ghost/temple/pages/QuestCreator.class new file mode 100644 index 0000000..d094e8f Binary files /dev/null and b/target/test-classes/com/ghost/temple/pages/QuestCreator.class differ diff --git a/target/test-classes/com/ghost/temple/stepdefs/QuestCreatorStepDefs.class b/target/test-classes/com/ghost/temple/stepdefs/QuestCreatorStepDefs.class new file mode 100644 index 0000000..3271be5 Binary files /dev/null and b/target/test-classes/com/ghost/temple/stepdefs/QuestCreatorStepDefs.class differ diff --git a/target/test-classes/features/questCreator.feature b/target/test-classes/features/questCreator.feature new file mode 100644 index 0000000..6bf5f4e --- /dev/null +++ b/target/test-classes/features/questCreator.feature @@ -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