Refined code to fill Quest Title and Quest Description
This commit is contained in:
parent
993079bc6e
commit
fefd3af646
|
@ -2,26 +2,50 @@ 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;
|
||||
import java.util.*;
|
||||
|
||||
public class ExcelUtils {
|
||||
public static Map<String, String> fetchData(String sheetName) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
|
||||
private static final boolean DEBUG = true; // your debug flag
|
||||
|
||||
public static List<List<String>> fetchQuestDataByColumns(String sheetName) {
|
||||
|
||||
List<List<String>> questData = new ArrayList<>();
|
||||
|
||||
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());
|
||||
|
||||
for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) { // start from 0!
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
if (row == null) continue;
|
||||
|
||||
List<String> columns = new ArrayList<>();
|
||||
for (int colIndex = 0; colIndex < 2; colIndex++) { // Only Column A and B
|
||||
Cell cell = row.getCell(colIndex);
|
||||
columns.add(cell != null ? cell.toString().trim() : "");
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
System.out.println("📄 Row " + rowIndex + ": " + columns);
|
||||
}
|
||||
|
||||
questData.add(columns);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
|
||||
if (DEBUG) {
|
||||
System.out.println("📦 Total quests fetched: " + questData.size());
|
||||
}
|
||||
|
||||
return questData;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,19 @@
|
|||
package com.ghost.temple;
|
||||
|
||||
import java.util.Map;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
public class ReusableFunctions {
|
||||
|
||||
private static final boolean DEBUG = true; // debug flag
|
||||
|
||||
public static boolean checkWebElement(WebElement element) {
|
||||
try {
|
||||
return element.isDisplayed() && element.isEnabled();
|
||||
|
@ -18,18 +28,55 @@ public class ReusableFunctions {
|
|||
}
|
||||
}
|
||||
|
||||
public static void fillInput(WebElement element, String value) {
|
||||
if (checkWebElement(element)) {
|
||||
element.clear();
|
||||
element.sendKeys(value);
|
||||
}
|
||||
|
||||
public static void fillQuestInputs(WebElement titleElement, WebElement descElement, List<List<String>> questData) {
|
||||
if (questData == null || questData.isEmpty()) {
|
||||
System.out.println("No quests found to fill, sweetheart 😢");
|
||||
return;
|
||||
}
|
||||
|
||||
for (List<String> row : questData) {
|
||||
if (row.size() < 2) {
|
||||
System.out.println("⚠️ Skipping incomplete row: " + row);
|
||||
continue;
|
||||
}
|
||||
|
||||
String title = row.get(0); // Column A
|
||||
String description = row.get(1); // Column B
|
||||
|
||||
System.out.println("📝 Filling → Title: \"" + title + "\", Description: \"" + description + "\"");
|
||||
|
||||
fillInput(titleElement, title);
|
||||
fillInput(descElement, description);
|
||||
}
|
||||
}
|
||||
|
||||
// Assuming fillInput is something like this:
|
||||
public static void fillInput(WebElement element, String value) {
|
||||
if (value != null) {
|
||||
element.clear();
|
||||
element.sendKeys(value);
|
||||
} else if (DEBUG) {
|
||||
System.out.println("DEBUG: Tried to fill input with null value!");
|
||||
}
|
||||
}
|
||||
public static void scrollIntoView(WebDriver driver, WebElement element) {
|
||||
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
|
||||
}
|
||||
|
||||
// 🌐 NEW: Open a specific URL
|
||||
// Wait for Element to be clickable.
|
||||
public static WebElement waitForElementToBeClickable(WebDriver driver, WebElement element, int timeoutInSeconds) {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(timeoutInSeconds));
|
||||
return wait.until(ExpectedConditions.elementToBeClickable(element));
|
||||
}
|
||||
|
||||
// Wait for Element Visibility
|
||||
public static WebElement waitForElementToBeVisible(WebDriver driver, WebElement element, int timeoutInSeconds) {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(timeoutInSeconds));
|
||||
return wait.until(ExpectedConditions.visibilityOf(element));
|
||||
}
|
||||
|
||||
// 🌐 Open a specific URL
|
||||
public static void openUrl(WebDriver driver, String url) {
|
||||
try {
|
||||
driver.get(url);
|
||||
|
|
|
@ -20,6 +20,6 @@ public class Hooks {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DriverManager.quitDriver(); // Then quit driver
|
||||
//DriverManager.quitDriver(); // Then quit driver
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -11,12 +11,12 @@ import com.ghost.temple.ReusableFunctions;
|
|||
import java.time.Duration;
|
||||
|
||||
|
||||
public class QuestCreator {
|
||||
public class HomePage {
|
||||
|
||||
WebDriver driver;
|
||||
private By addQuestBtnLocator = By.xpath("//a[@href='/quests']/button[contains(text(),'View All')]");
|
||||
|
||||
public QuestCreator(WebDriver driver) {
|
||||
public HomePage(WebDriver driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
56
src/test/java/com/ghost/temple/pages/Quests.java
Normal file
56
src/test/java/com/ghost/temple/pages/Quests.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package com.ghost.temple.pages;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
import org.openqa.selenium.support.PageFactory;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import com.ghost.temple.ReusableFunctions;
|
||||
|
||||
import com.ghost.temple.ExcelUtils;
|
||||
import java.time.Duration;
|
||||
|
||||
public class Quests {
|
||||
|
||||
WebDriver driver;
|
||||
|
||||
@FindBy(xpath = "//div[@class='mb-6 flex justify-center']/button[contains(text(),'Create Custom Quest')]")
|
||||
WebElement createCustomQuest;
|
||||
|
||||
@FindBy(xpath = "//input[@id='title']")
|
||||
WebElement questTitle;
|
||||
|
||||
@FindBy(xpath = "//textarea[@id='description']")
|
||||
WebElement questDescription;
|
||||
|
||||
public Quests(WebDriver driver) {
|
||||
this.driver = driver;
|
||||
PageFactory.initElements(driver, this);
|
||||
}
|
||||
|
||||
public void clickcreateCustomQuest() {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||
|
||||
// Wait for the element to be clickable
|
||||
ReusableFunctions.waitForElementToBeClickable(driver, createCustomQuest, 5);
|
||||
|
||||
// Scroll into view using your reusable method
|
||||
ReusableFunctions.scrollIntoView(driver, createCustomQuest);
|
||||
|
||||
// Use your reusable click
|
||||
ReusableFunctions.click(createCustomQuest);
|
||||
}
|
||||
|
||||
|
||||
public void createQuests() {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||
|
||||
// Wait for the element to be clickable
|
||||
ReusableFunctions.waitForElementToBeVisible(driver, questTitle, 5);
|
||||
ReusableFunctions.fillQuestInputs(questTitle, questDescription, ExcelUtils.fetchQuestDataByColumns("Quests"));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
package com.ghost.temple.stepdefs;
|
||||
|
||||
import com.ghost.temple.driver.DriverManager;
|
||||
import com.ghost.temple.pages.QuestCreator;
|
||||
import com.ghost.temple.pages.HomePage;
|
||||
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 {
|
||||
public class HomePageStepDefs {
|
||||
|
||||
WebDriver driver;
|
||||
QuestCreator questPage;
|
||||
HomePage homePage;
|
||||
|
||||
public QuestCreatorStepDefs() {
|
||||
public HomePageStepDefs() {
|
||||
this.driver = DriverManager.getDriver();
|
||||
this.questPage = new QuestCreator(driver);
|
||||
this.homePage = new HomePage(driver);
|
||||
}
|
||||
|
||||
@Given("I open the solo level page")
|
||||
|
@ -24,6 +24,6 @@ public class QuestCreatorStepDefs {
|
|||
|
||||
@When("I click the Add Quest button")
|
||||
public void i_click_the_add_quest_button() {
|
||||
questPage.clickAddQuest();
|
||||
homePage.clickAddQuest();
|
||||
}
|
||||
}
|
28
src/test/java/com/ghost/temple/stepdefs/QuestsStepDefs.java
Normal file
28
src/test/java/com/ghost/temple/stepdefs/QuestsStepDefs.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package com.ghost.temple.stepdefs;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import com.ghost.temple.driver.DriverManager;
|
||||
import com.ghost.temple.pages.Quests;
|
||||
|
||||
import io.cucumber.java.en.When;
|
||||
|
||||
public class QuestsStepDefs {
|
||||
|
||||
|
||||
WebDriver driver;
|
||||
Quests questPage;
|
||||
|
||||
public QuestsStepDefs() {
|
||||
this.driver = DriverManager.getDriver();
|
||||
this.questPage = new Quests(driver);
|
||||
}
|
||||
|
||||
@When("I fill all the quests from Excel")
|
||||
public void i_fill_all_the_quests_from_excel() {
|
||||
// Create Quests
|
||||
questPage.clickcreateCustomQuest();
|
||||
questPage.createQuests();
|
||||
throw new io.cucumber.java.PendingException();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,3 +3,4 @@ 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
|
||||
When I fill all the quests from Excel
|
||||
|
|
Binary file not shown.
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
|
@ -1,4 +1,3 @@
|
|||
com/ghost/temple/pages/QuestCreator.class
|
||||
com/ghost/temple/BaseTest.class
|
||||
com/ghost/temple/TestRunner.class
|
||||
com/ghost/temple/AppTest.class
|
||||
com/ghost/temple/BaseTest.class
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/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/pages/Quests.java
|
||||
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/stepdefs/QuestsStepDefs.java
|
||||
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/stepdefs/HomePageStepDefs.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/pages/HomePage.java
|
||||
/home/arul/ghost-temple-automation/ghost-temple-automation/src/test/java/com/ghost/temple/TestRunner.java
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<testsuite tests="1" failures="0" name="com.ghost.temple.TestRunner" time="24.783" errors="0" skipped="0">
|
||||
<testsuite tests="1" failures="0" name="com.ghost.temple.TestRunner" time="50.662" errors="1" skipped="0">
|
||||
<properties>
|
||||
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
|
||||
<property name="java.vm.version" value="17.0.15+6-Debian-1deb12u1"/>
|
||||
|
@ -58,5 +58,37 @@
|
|||
<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="24.783"/>
|
||||
<testcase classname="Solo Leveling Quest Management" name="Open Solo Leveling page and click Add Quest" time="50.662">
|
||||
<error message="TODO: implement me" type="io.cucumber.java.PendingException">io.cucumber.java.PendingException: TODO: implement me
|
||||
at com.ghost.temple.stepdefs.QuestsStepDefs.i_fill_all_the_quests_from_excel(QuestsStepDefs.java:25)
|
||||
at ✽.I fill all the quests from Excel(file:///home/arul/ghost-temple-automation/ghost-temple-automation/src/test/resources/features/questCreator.feature:6)
|
||||
</error>
|
||||
<system-out>
|
||||
Scenario: Open Solo Leveling page and click Add Quest # src/test/resources/features/questCreator.feature:3
|
||||
Launched Firefox with real profile 😎
|
||||
Given I open the solo level page # com.ghost.temple.stepdefs.HomePageStepDefs.i_open_the_solo_level_page()
|
||||
When I click the Add Quest button # com.ghost.temple.stepdefs.HomePageStepDefs.i_click_the_add_quest_button()
|
||||
📄 Row 0: [Offgrid Hermit - Disconnect from Internet, ghostTemple system forces user by disabling internet by default in the computer to go offgrid. Equiped with self designed /etc/host based porn blocker. It still provides user option to enable the internet at boot. asking user to enter password. to make user realize that their decision is conscious.]
|
||||
📄 Row 1: [The Refiner - Appearance Leveling, Focusing on Skin health, Hair health, preventing Hair loss, Preventing Fat gain. Focused on Weight Loss and over all Hygiene the way we look. To Attract people and be charismatic.]
|
||||
📄 Row 2: [King of Deception - Leveling up Art of Attraction, Focused on building a solid character. that is strong.. Talented, Attract people and seductive at same time. Manipulative in good way. Positive Manipulation by doing a good job on something we do and gaining trust among other people.]
|
||||
📄 Row 3: [The Architect of Himself - Leveling up strength both physically and mentally, 1. Exercise everyday Morning 1 hr (Cardio + strength) 2. Gain Knowledge on New concept or Technology, Read books. 3. Train Martial arts - Armed or Unarmed combat styles. Focus on Leveling up your Intellect, your Strength, Your Martial arts skill and your Aesthetics eventually.]
|
||||
📄 Row 4: [The Phoenix - Rise from Ashes, Keep Moving Forward, No matter what. No matter how much pain you face. you can do take breaks to learn from failures. But never quit . Never Settle. Accept your Pain. see it as a part of life. both physical and Mental Pain. If you can cure it you can cure them. but if you can't never use them as an excuse to be Lower. Always improve from pain and be strong if possible. the Key idea is not to stop at any cost and keep moving forward. Not to embrace pain or romanticize it.]
|
||||
📦 Total quests fetched: 5
|
||||
📝 Filling → Title: "Offgrid Hermit - Disconnect from Internet", Description: "ghostTemple system forces user by disabling internet by default in the computer to go offgrid. Equiped with self designed /etc/host based porn blocker. It still provides user option to enable the internet at boot. asking user to enter password. to make user realize that their decision is conscious."
|
||||
📝 Filling → Title: "The Refiner - Appearance Leveling", Description: "Focusing on Skin health, Hair health, preventing Hair loss, Preventing Fat gain. Focused on Weight Loss and over all Hygiene the way we look. To Attract people and be charismatic."
|
||||
📝 Filling → Title: "King of Deception - Leveling up Art of Attraction", Description: "Focused on building a solid character. that is strong.. Talented, Attract people and seductive at same time. Manipulative in good way. Positive Manipulation by doing a good job on something we do and gaining trust among other people."
|
||||
📝 Filling → Title: "The Architect of Himself - Leveling up strength both physically and mentally", Description: "1. Exercise everyday Morning 1 hr (Cardio + strength) 2. Gain Knowledge on New concept or Technology, Read books. 3. Train Martial arts - Armed or Unarmed combat styles. Focus on Leveling up your Intellect, your Strength, Your Martial arts skill and your Aesthetics eventually."
|
||||
📝 Filling → Title: "The Phoenix - Rise from Ashes", Description: "Keep Moving Forward, No matter what. No matter how much pain you face. you can do take breaks to learn from failures. But never quit . Never Settle. Accept your Pain. see it as a part of life. both physical and Mental Pain. If you can cure it you can cure them. but if you can't never use them as an excuse to be Lower. Always improve from pain and be strong if possible. the Key idea is not to stop at any cost and keep moving forward. Not to embrace pain or romanticize it."
|
||||
When I fill all the quests from Excel # com.ghost.temple.stepdefs.QuestsStepDefs.i_fill_all_the_quests_from_excel()
|
||||
io.cucumber.java.PendingException: TODO: implement me
|
||||
at com.ghost.temple.stepdefs.QuestsStepDefs.i_fill_all_the_quests_from_excel(QuestsStepDefs.java:25)
|
||||
at ✽.I fill all the quests from Excel(file:///home/arul/ghost-temple-automation/ghost-temple-automation/src/test/resources/features/questCreator.feature:6)
|
||||
|
||||
</system-out>
|
||||
<system-err>SLF4J(W): No SLF4J providers were found.
|
||||
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
|
||||
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
|
||||
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
|
||||
</system-err>
|
||||
</testcase>
|
||||
</testsuite>
|
|
@ -1,4 +1,4 @@
|
|||
-------------------------------------------------------------------------------
|
||||
Test set: com.ghost.temple.AppTest
|
||||
-------------------------------------------------------------------------------
|
||||
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec
|
||||
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
-------------------------------------------------------------------------------
|
||||
Test set: com.ghost.temple.TestRunner
|
||||
-------------------------------------------------------------------------------
|
||||
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 25.292 sec
|
||||
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 51.097 sec <<< FAILURE!
|
||||
Open Solo Leveling page and click Add Quest(Solo Leveling Quest Management) Time elapsed: 50.662 sec <<< ERROR!
|
||||
io.cucumber.java.PendingException: TODO: implement me
|
||||
at com.ghost.temple.stepdefs.QuestsStepDefs.i_fill_all_the_quests_from_excel(QuestsStepDefs.java:25)
|
||||
at ✽.I fill all the quests from Excel(file:///home/arul/ghost-temple-automation/ghost-temple-automation/src/test/resources/features/questCreator.feature:6)
|
||||
|
||||
|
|
Binary file not shown.
BIN
target/test-classes/com/ghost/temple/pages/Quests.class
Normal file
BIN
target/test-classes/com/ghost/temple/pages/Quests.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,3 +3,4 @@ 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
|
||||
When I fill all the quests from Excel
|
||||
|
|
Loading…
Reference in New Issue
Block a user