Skip to content

Commit 997eb0d

Browse files
committed
updated
1 parent 1aed525 commit 997eb0d

File tree

14 files changed

+196
-74
lines changed

14 files changed

+196
-74
lines changed

cucumber-html-report.html

Lines changed: 48 additions & 0 deletions
Large diffs are not rendered by default.

json_output/cucumber.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"line":1,"elements":[{"start_timestamp":"2023-05-28T20:43:37.787Z","line":3,"name":"Validate login screen","description":"","id":"validate-successfull-login;validate-login-screen","type":"scenario","keyword":"Scenario","steps":[{"result":{"duration":2000400,"status":"passed"},"line":5,"name":"user is in the login screen","match":{"location":"stepDefinitions.Login_SD.user_is_in_the_login_screen()"},"keyword":"Given "},{"result":{"status":"passed"},"line":6,"name":"user enters username and password","match":{"location":"stepDefinitions.Login_SD.user_enters_username_and_password()"},"keyword":"When "},{"result":{"duration":1000200,"status":"passed"},"line":7,"name":"user clicks on login button","match":{"location":"stepDefinitions.Login_SD.user_clicks_on_login_button()"},"keyword":"And "},{"result":{"status":"passed"},"line":8,"name":"user will be on the Homepage screen","match":{"location":"stepDefinitions.Login_SD.user_will_be_on_the_homepage_screen()"},"keyword":"Then "}]}],"name":"Validate successfull Login","description":"","id":"validate-successfull-login","keyword":"Feature","uri":"file:src/test/java/features/login.feature","tags":[]}]
1+
[{"line":1,"elements":[{"start_timestamp":"2023-05-29T02:30:23.361Z","before":[{"result":{"duration":3296946500,"status":"passed"},"match":{"location":"hooks.hooks.setup()"}}],"line":2,"name":"Validate login screen","description":"","id":"validate-successfull-login;validate-login-screen","after":[{"result":{"duration":220058600,"status":"passed"},"match":{"location":"hooks.hooks.teardown()"}}],"type":"scenario","keyword":"Scenario","steps":[{"result":{"duration":7529700,"status":"passed"},"line":4,"name":"user is in the login screen","match":{"location":"stepDefinitions.Login_SD.user_is_in_the_login_screen()"},"keyword":"Given "},{"result":{"duration":272634500,"status":"passed"},"line":5,"name":"user enters username and password","match":{"location":"stepDefinitions.Login_SD.user_enters_username_and_password()"},"keyword":"When "},{"result":{"duration":366416800,"status":"passed"},"line":6,"name":"user clicks on login button","match":{"location":"stepDefinitions.Login_SD.user_clicks_on_login_button()"},"keyword":"And "},{"result":{"duration":978791200,"status":"passed"},"line":7,"name":"user will be on the Homepage screen","match":{"location":"stepDefinitions.Login_SD.user_will_be_on_the_homepage_screen()"},"keyword":"Then "}]}],"name":"Validate successfull Login","description":"","id":"validate-successfull-login","keyword":"Feature","uri":"file:src/test/java/features/login.feature","tags":[]}]

junit_xml/cucumber.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<testsuite name="Cucumber" time="0.187" tests="1" skipped="0" failures="0" errors="0">
3-
<testcase classname="Validate successfull Login" name="Validate login screen" time="0.023">
2+
<testsuite name="Cucumber" time="5.266" tests="1" skipped="0" failures="0" errors="0">
3+
<testcase classname="Validate successfull Login" name="Validate login screen" time="5.155">
44
<system-out><![CDATA[
55
Given user is in the login screen...........................................passed
66
When user enters username and password......................................passed

src/main/java/com/app/pages/BasePage.java

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,18 @@
1616

1717
public class BasePage {
1818

19-
public static WebDriver driver;
20-
public static Properties prop;
2119
public static WebDriverWait wait;
22-
public BasePage() {
23-
try {
24-
prop = new Properties();
25-
FileInputStream ip = new FileInputStream(System.getProperty("user.dir") + "\\src\\main\\java\\com\\app\\config\\config.properties");
26-
prop.load(ip);
27-
} catch (FileNotFoundException e) {
28-
e.printStackTrace();
29-
} catch (IOException e) {
30-
e.printStackTrace();
31-
}
32-
}
3320

34-
public static void init() {
35-
String browser = prop.getProperty("browser");
36-
if (browser.equals("chrome")) {
37-
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Andrew\\OneDrive\\Documents\\codes\\webdrivers\\chromedriver.exe");
38-
driver = new ChromeDriver();
39-
}
40-
else {
41-
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Andrew\\OneDrive\\Documents\\codes\\webdrivers\\geckodriver.exe");
42-
driver = new FirefoxDriver();
43-
}
44-
driver.manage().window().maximize();
45-
driver.manage().deleteAllCookies();
46-
driver.manage().timeouts().pageLoadTimeout(Long.parseLong(prop.getProperty("PAGE_TIMEOUT")), TimeUnit.SECONDS);
47-
driver.manage().timeouts().implicitlyWait(Long.parseLong(prop.getProperty("IMPLICIT_WAIT")), TimeUnit.SECONDS);
48-
driver.get(prop.getProperty("url"));
21+
public static void clickElement(WebDriver driver, WebElement element) {
22+
waitforElementVisibility(driver, element);
23+
element.click();
4924
}
50-
51-
public void waitforElementVisibility(WebElement el) {
25+
public static void waitforElementVisibility(WebDriver driver, WebElement element) {
5226
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
53-
wait.until(ExpectedConditions.elementToBeClickable(el));
27+
wait.until(ExpectedConditions.elementToBeClickable(element));
28+
}
29+
public static void sendKeys(WebDriver driver, WebElement element, String input) {
30+
waitforElementVisibility(driver, element);
31+
element.sendKeys(input);
5432
}
5533
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
package com.app.pages;
22

3+
import org.openqa.selenium.WebDriver;
34
import org.openqa.selenium.WebElement;
45
import org.openqa.selenium.devtools.v85.page.Page;
56
import org.openqa.selenium.support.FindBy;
67
import org.openqa.selenium.support.PageFactory;
78

89
public class HomePage extends BasePage {
9-
// Object Repopsitories
1010

11+
WebDriver driver;
12+
// Object Repopsitories
1113
@FindBy(xpath="/html/body/div[3]/div[1]/div[1]/h1")
1214
WebElement dashboard;
1315

14-
public HomePage() {
16+
public HomePage(WebDriver ldriver) {
17+
driver = ldriver;
1518
PageFactory.initElements(driver, this);
1619
}
20+
21+
public boolean validateDashboard() {
22+
waitforElementVisibility(driver, dashboard);
23+
return dashboard.isDisplayed();
24+
}
1725
}
1826

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package com.app.pages;
22

33
import org.openqa.selenium.JavascriptExecutor;
4+
import org.openqa.selenium.WebDriver;
45
import org.openqa.selenium.WebElement;
56
import org.openqa.selenium.support.FindBy;
67
import org.openqa.selenium.support.PageFactory;
78

8-
public class LoginPage extends BasePage{
9+
import static com.app.pages.BasePage.*;
10+
11+
public class LoginPage {
12+
WebDriver driver;
13+
public LoginPage(WebDriver ldriver) {
14+
driver = ldriver;
15+
PageFactory.initElements(driver, this);
16+
}
17+
918
// Object Repositories
1019

1120
@FindBy(id="Email")
@@ -18,25 +27,24 @@ public class LoginPage extends BasePage{
1827
WebElement login_button;
1928

2029
//initialize the objects
21-
public LoginPage() {
22-
PageFactory.initElements(driver, this);
23-
}
2430

25-
public void login(String un, String pwd) {
26-
waitforElementVisibility(username);
31+
public void enterUserName(String un) {
32+
waitforElementVisibility(driver, username);
2733
username.clear();
28-
username.sendKeys(prop.getProperty("user"));
29-
waitforElementVisibility(password);
30-
password.clear();
31-
password.sendKeys(prop.getProperty("password"));
32-
waitforElementVisibility(login_button);
33-
JavascriptExecutor js = (JavascriptExecutor)driver;
34-
js.executeScript("arguments[0].click();", login_button);
34+
sendKeys(driver, username, un);
3535
}
3636

37-
public String verifyLoginTitle() {
38-
String title = driver.getTitle();
39-
return title;
37+
public void enterPassword(String pwd) {
38+
waitforElementVisibility(driver, password);
39+
password.clear();
40+
sendKeys(driver, password, pwd);
4041
}
4142

43+
public void clickLoginButton() {
44+
waitforElementVisibility(driver, login_button);
45+
// clickElement(driver, login_button);
46+
JavascriptExecutor js = (JavascriptExecutor)driver;
47+
js.executeScript("arguments[0].click();", login_button);
48+
49+
}
4250
}
File renamed without changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package factory;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.chrome.ChromeDriver;
5+
import org.openqa.selenium.edge.EdgeDriver;
6+
import org.openqa.selenium.firefox.FirefoxDriver;
7+
8+
import java.io.FileInputStream;
9+
import java.io.FileNotFoundException;
10+
import java.io.IOException;
11+
import java.util.Properties;
12+
13+
public class DriverFactory {
14+
static WebDriver driver;
15+
static Properties prop;
16+
public static void initializeBrowser(String browser) {
17+
if (browser.equals("chrome")) {
18+
driver = new ChromeDriver();
19+
} else if (browser.equals("firefox")) {
20+
driver = new FirefoxDriver();
21+
} else {
22+
driver = new EdgeDriver();
23+
}
24+
}
25+
26+
public static WebDriver getDriver() {
27+
return driver;
28+
}
29+
public static Properties getProp() {
30+
// get config.property values
31+
try {
32+
prop = new Properties();
33+
FileInputStream ip = new FileInputStream(System.getProperty("user.dir") + "\\src\\test\\config.properties");
34+
prop.load(ip);
35+
} catch (FileNotFoundException e) {
36+
e.printStackTrace();
37+
} catch (IOException e) {
38+
e.printStackTrace();
39+
}
40+
return prop;
41+
}
42+
}

src/test/java/features/login.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Feature: Validate successfull Login
2-
32
Scenario: Validate login screen
43

54
Given user is in the login screen

src/test/java/hooks/hooks.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package hooks;
2+
3+
import factory.DriverFactory;
4+
import io.cucumber.java.After;
5+
import io.cucumber.java.Before;
6+
import org.openqa.selenium.WebDriver;
7+
8+
import java.time.Duration;
9+
import java.util.Properties;
10+
11+
public class hooks {
12+
public WebDriver driver;
13+
public Properties prop = DriverFactory.getProp();
14+
@Before
15+
public void setup() {
16+
DriverFactory.initializeBrowser(prop.getProperty("browser"));
17+
driver = DriverFactory.getDriver();
18+
driver.manage().deleteAllCookies();
19+
driver.manage().window().maximize();
20+
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
21+
driver.get(prop.getProperty("url"));
22+
System.out.println("URL: " + prop.getProperty("url"));
23+
}
24+
25+
@After
26+
public void teardown() {
27+
driver.quit();
28+
}
29+
}

0 commit comments

Comments
 (0)