forked from Zakaria/ZenProject
Compare commits
39 Commits
c11ffbe238
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 49af5e36d7 | |||
| af2bb3ca0e | |||
| d77499088f | |||
| 0e81fec560 | |||
| 1bc6cf564c | |||
| c03ae30e24 | |||
| d13a89e735 | |||
| 9cb8ca125e | |||
| 05e07626b1 | |||
| f146baa692 | |||
| 6add05fc69 | |||
| ed9847864a | |||
| 4a5405049c | |||
| 76acd5ae9e | |||
| 7ad5df5475 | |||
| 09c9801fc9 | |||
| 9777fa5e9a | |||
| 3c07bb12d6 | |||
| e8968b6243 | |||
| 8a5ab43be8 | |||
| 0ad5c13d36 | |||
| 9e4277a032 | |||
| d0fc65136e | |||
| 43936b1f15 | |||
| 6fe7a83a5a | |||
| c36e6e9336 | |||
| bc25347655 | |||
| a92c917c97 | |||
| d730a1357d | |||
| 54fbd3e326 | |||
| f0dfc063e1 | |||
| c72122fea2 | |||
| df67108c10 | |||
| 72f873c8d8 | |||
| 4592c1d74e | |||
| 1a722f3d61 | |||
| 2d83102cdc | |||
| f0ff453c46 | |||
| 587e7504c8 |
Generated
+1
-1
@@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
File diff suppressed because one or more lines are too long
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label "agent_locke"
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
// This runs the Maven test phase
|
||||
sh 'mvn test -P Regression'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,61 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>Regression</id>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>testng.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>Smoke</id>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>testCucumber.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.18.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
|
||||
<dependency>
|
||||
<groupId>io.github.bonigarcia</groupId>
|
||||
<artifactId>webdrivermanager</artifactId>
|
||||
<version>5.9.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aventstack</groupId>
|
||||
<artifactId>extentreports</artifactId>
|
||||
@@ -63,6 +117,22 @@
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.24.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>7.19.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-testng</artifactId>
|
||||
<version>7.19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>7.14.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Zen Test Case</title>
|
||||
<link rel="apple-touch-icon" href="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@b00a2d0486596e73dd7326beacf352c639623a0e/commons/img/logo.png">
|
||||
<link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@b00a2d0486596e73dd7326beacf352c639623a0e/commons/img/logo.png">
|
||||
<link href="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@ce8b10435bcbae260c334c0d0c6b61d2c19b6168/spark/css/spark-style.css" rel="stylesheet" />
|
||||
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@7cc78ce/spark/js/jsontree.js"></script>
|
||||
<style type="text/css"></style></head><body class="spa -report standard">
|
||||
<div class="app">
|
||||
<div class="layout">
|
||||
<div class="header navbar">
|
||||
<div class="vheader">
|
||||
<div class="nav-logo">
|
||||
<a href="#">
|
||||
<div class="logo" style="background-image: url('https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@b00a2d0486596e73dd7326beacf352c639623a0e/commons/img/logo.png')"></div>
|
||||
</a>
|
||||
</div>
|
||||
<ul class="nav-left">
|
||||
<li class="search-box">
|
||||
<a class="search-toggle" href="#">
|
||||
<i class="search-icon fa fa-search"></i>
|
||||
<i class="search-icon-close fa fa-close"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li class="search-input"><input id="search-tests" class="form-control" type="text" placeholder="Search..."></li>
|
||||
</ul>
|
||||
<ul class="nav-right">
|
||||
<li class="m-r-10">
|
||||
<a href="#"><span class="badge badge-primary">Zenful</span></a>
|
||||
</li>
|
||||
<li class="m-r-10">
|
||||
<a href="#"><span class="badge badge-primary">Oct 26, 2024 01:35:47 AM</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div><div class="side-nav">
|
||||
<div class="side-nav-inner">
|
||||
<ul class="side-nav-menu">
|
||||
<li class="nav-item dropdown" onclick="toggleView('test-view')">
|
||||
<a id="nav-test" class="dropdown-toggle" href="#">
|
||||
<span class="ico"><i class="fa fa-list"></i></span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown" onclick="toggleView('dashboard-view')">
|
||||
<a id="nav-dashboard" class="dropdown-toggle" href="#">
|
||||
<span class="ico"><i class="fa fa-bar-chart"></i></span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div> <div class="vcontainer">
|
||||
<div class="main-content">
|
||||
<div class="test-wrapper row view test-view">
|
||||
<div class="test-list">
|
||||
<div class="test-list-tools">
|
||||
<ul class="tools pull-left">
|
||||
<li><a href="#"><span class="font-size-14">Tests</span></a></li>
|
||||
</ul>
|
||||
<ul class="tools text-right">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-exclamation-circle"></i></a>
|
||||
<ul id="status-toggle" class="dropdown-menu dropdown-md p-v-0">
|
||||
<a class="dropdown-item" status="pass" href="#"><span>Pass</span><span class="status success"></span></a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a status="clear" class="dropdown-item" href="#"><span>Clear</span><span class="pull-right"><i class="fa fa-close"></i></span></a>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div> <div class="test-list-wrapper scrollable">
|
||||
<ul class="test-list-item">
|
||||
<li class="test-item" status="pass" test-id="1"
|
||||
author=""
|
||||
tag=""
|
||||
device="">
|
||||
<div class="test-detail">
|
||||
<p class="name">Test msg</p>
|
||||
<p class="text-sm">
|
||||
<span>1:35:55 AM</span> / <span>00:00:00:000</span>
|
||||
<span class="badge pass-bg log float-right">Pass</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="test-contents d-none">
|
||||
<div class="detail-head">
|
||||
<div class="p-v-10">
|
||||
<div class="info">
|
||||
<h5 class="test-status text-pass">Test msg</h5>
|
||||
<span class='badge badge-success'>10.26.2024 1:35:55 AM</span>
|
||||
<span class='badge badge-danger'>10.26.2024 1:35:55 AM</span>
|
||||
<span class='badge badge-default'>00:00:00:000</span>
|
||||
· <span class='uri-anchor badge badge-default'>#test-id=1</span>
|
||||
<span title='Skip to the next failed step' class='badge badge-danger pointer float-right ne ml-1'><i class="fa fa-fast-forward"></i></span>
|
||||
<span title='Collapse all nodes' class='badge badge-default pointer float-right ct ml-1'><i class="fa fa-compress"></i></span>
|
||||
<span title='Expand all nodes' class='badge badge-default pointer float-right et'><i class="fa fa-expand"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div> </div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="test-content scrollable">
|
||||
<div class="test-content-tools">
|
||||
<ul><li><a class="back-to-test" href="#"><i class="fa fa-arrow-left"></i></a></li></ul>
|
||||
</div>
|
||||
<div class="test-content-detail"><div class="detail-body"></div></div>
|
||||
</div></div>
|
||||
<div class="container-fluid p-4 view dashboard-view">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="card"><div class="card-body">
|
||||
<p class="m-b-0">Started</p>
|
||||
<h3>Oct 26, 2024 01:35:47 AM</h3>
|
||||
</div></div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card"><div class="card-body">
|
||||
<p class="m-b-0">Ended</p>
|
||||
<h3>Oct 26, 2024 01:35:56 AM</h3>
|
||||
</div></div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card"><div class="card-body">
|
||||
<p class="m-b-0 text-pass">Tests Passed</p>
|
||||
<h3>1</h3>
|
||||
</div></div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card"><div class="card-body">
|
||||
<p class="m-b-0 text-fail">Tests Failed</p>
|
||||
<h3>0</h3>
|
||||
</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h6 class="card-title">Tests</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="">
|
||||
<canvas id='parent-analysis' width='115' height='90'></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div><small data-tooltip='100%'>
|
||||
<b>1</b> tests passed
|
||||
</small>
|
||||
</div>
|
||||
<div>
|
||||
<small data-tooltip='0%'><b>0</b> tests failed,
|
||||
<b>0</b> skipped, <b data-tooltip='0%'>0</b> others
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row"><div class="col-md-12">
|
||||
<div class="card"><div class="card-header"><p>Timeline</p></div>
|
||||
<div class="card-body pt-0"><div>
|
||||
<canvas id="timeline" height="120"></canvas>
|
||||
</div></div>
|
||||
</div>
|
||||
</div></div>
|
||||
<script>
|
||||
var timeline = {
|
||||
"Test msg":0
|
||||
};
|
||||
</script>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 sysenv-container">
|
||||
<div class="card">
|
||||
<div class="card-header"><p>System/Environment</p></div>
|
||||
<div class="card-body pb-0 pt-0"><table class="table table-sm table-bordered">
|
||||
<thead><tr class="bg-gray"><th>Name</th><th>Value</th></tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Tester ID: </td>
|
||||
<td>Sami</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var statusGroup = {
|
||||
parentCount: 5,
|
||||
passParent: 1,
|
||||
failParent: 0,
|
||||
warningParent: 0,
|
||||
skipParent: 0,
|
||||
childCount: 5,
|
||||
passChild: 0,
|
||||
failChild: 0,
|
||||
warningChild: 0,
|
||||
skipChild: 0,
|
||||
infoChild: 0,
|
||||
grandChildCount: 5,
|
||||
passGrandChild: 0,
|
||||
failGrandChild: 0,
|
||||
warningGrandChild: 0,
|
||||
skipGrandChild: 0,
|
||||
infoGrandChild: 0,
|
||||
eventsCount: 5,
|
||||
passEvents: 0,
|
||||
failEvents: 0,
|
||||
warningEvents: 0,
|
||||
skipEvents: 0,
|
||||
infoEvents: 0
|
||||
};
|
||||
</script> </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@c05cd28cde1617b9d0c05a831daff6cb97fd9fd5/spark/js/spark-script.js"></script>
|
||||
<script type="text/javascript"></script></body>
|
||||
</html>
|
||||
@@ -0,0 +1,8 @@
|
||||
Feature: Home page of the application
|
||||
|
||||
@Smoke
|
||||
Scenario: Leave a comment into Zenful.cloud
|
||||
Given Initialize the remote webdriver Firefox
|
||||
And navigate to "https://zenful.cloud"
|
||||
When User type text into the text box and hit click
|
||||
Then Text is displayed "True"
|
||||
@@ -0,0 +1,35 @@
|
||||
package stepDefinition;
|
||||
|
||||
import io.cucumber.java.en.Given;
|
||||
import io.cucumber.java.en.Then;
|
||||
import io.cucumber.java.en.When;
|
||||
import zacksolutions.base.Initialization;
|
||||
import zacksolutions.pages.HomePage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class StepDefinition extends Initialization {
|
||||
|
||||
@Given("Initialize the remote webdriver Firefox")
|
||||
public void initializeTheRemoteWebdriverFirefox() {
|
||||
BrowserInit("firefox");
|
||||
}
|
||||
|
||||
@Given("navigate to {string}")
|
||||
public void navigate_to(String url) {
|
||||
// Write code here that turns the phrase above into concrete actions
|
||||
driver.get(url);
|
||||
}
|
||||
@When("User type text into the text box and hit click")
|
||||
public void user_type_text_into_the_text_box_and_hit_click() throws IOException, InterruptedException {
|
||||
// Write code here that turns the phrase above into concrete actions
|
||||
HomePage hp = new HomePage();
|
||||
hp.insertText();
|
||||
}
|
||||
@Then("Text is displayed {string}")
|
||||
public void text_is_displayed(String string) {
|
||||
// Write code here that turns the phrase above into concrete actions
|
||||
HomePage hp = new HomePage();
|
||||
hp.textConfirmation();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package testNGRunner;
|
||||
|
||||
import io.cucumber.testng.AbstractTestNGCucumberTests;
|
||||
import io.cucumber.testng.CucumberOptions;
|
||||
|
||||
@CucumberOptions(features = "src/main/java/features", glue = "stepDefinition", monochrome = false, plugin = { "pretty",
|
||||
"html:BDDrepo/bddReports" }, tags = "@Smoke")
|
||||
public class TestRunner extends AbstractTestNGCucumberTests {
|
||||
|
||||
}
|
||||
@@ -2,27 +2,35 @@ package zacksolutions.base;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
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.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
import org.testng.annotations.Parameters;
|
||||
|
||||
public class Initialization {
|
||||
// let's set up our variables
|
||||
|
||||
// private static ThreadLocal<WebDriver> driver = new ThreadLocal<>();
|
||||
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("/home/ilyes/SeleniumPractice/Zenful/src/main/java/zacksolutions/config/config.properties");
|
||||
FileInputStream fis = new FileInputStream(
|
||||
System.getProperty("user.dir") + "/src/main/java/zacksolutions/config/config.properties");
|
||||
prop.load(fis);
|
||||
|
||||
} catch (IOException e) {
|
||||
@@ -32,19 +40,64 @@ public class Initialization {
|
||||
|
||||
}
|
||||
|
||||
public void BrowserInit() {
|
||||
@Parameters("browser")
|
||||
public void BrowserInit(String browser) {
|
||||
// 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("Test Done By: ", "Sami");
|
||||
String browsername = prop.getProperty("browserF");
|
||||
if (browsername.equalsIgnoreCase("firefox")) {
|
||||
System.setProperty("web-driver.gecko.driver","/home/ilyes/SeleniumPractice/Zenful/drivers/geckodriver");
|
||||
driver = new FirefoxDriver();
|
||||
driver.get(prop.getProperty("url"));
|
||||
extent.setSystemInfo("Tester ID: ", "Sami");
|
||||
|
||||
if (browser.equalsIgnoreCase("chrome")) {
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
try {
|
||||
driver = new RemoteWebDriver(new URL("http://192.168.1.215:4444/wd/hub"), options);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
// TODO: handle exception
|
||||
}
|
||||
} else if (browser.equalsIgnoreCase("firefox")) {
|
||||
FirefoxOptions options = new FirefoxOptions();
|
||||
try {
|
||||
driver = new RemoteWebDriver(new URL("http://192.168.1.215:4444/wd/hub"), options);
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported browser: " + browser);
|
||||
}
|
||||
|
||||
//
|
||||
// // conditioning our WebDriver with an if statement
|
||||
// String browsername = prop.getProperty("browserF");
|
||||
//
|
||||
// // launching FireFox
|
||||
// if (browsername.equalsIgnoreCase("firefox")) {
|
||||
// // System.setProperty("web-driver.gecko.driver","user.dir" +
|
||||
// // "/drivers/geckodriver");
|
||||
// // driver = new FirefoxDriver();
|
||||
// FirefoxOptions options = new FirefoxOptions();
|
||||
// options.addArguments("--headless");
|
||||
// driver = new FirefoxDriver(options);
|
||||
// }
|
||||
//
|
||||
// // launching Chrome
|
||||
// if (browsername.equalsIgnoreCase("chrome")) {
|
||||
// // System.setProperty("web-driver.gecko.driver", "user.dir" +
|
||||
// // "/drivers/chromedriver");
|
||||
// // driver = new ChromeDriver();
|
||||
// ChromeOptions options = new ChromeOptions();
|
||||
// options.addArguments("--headless");
|
||||
// driver = new ChromeDriver(options);
|
||||
// }
|
||||
driver.get(prop.getProperty("url"));
|
||||
driver.manage().window().maximize();
|
||||
driver.manage().deleteAllCookies();
|
||||
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package zacksolutions.base;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* JokesAPI
|
||||
*/
|
||||
public class JokesAPI {
|
||||
|
||||
private String setup;
|
||||
private String punchline;
|
||||
|
||||
public void fetchJokes() throws IOException {
|
||||
|
||||
URL apiUrl = new URL("https://official-joke-api.appspot.com/jokes/random");
|
||||
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
|
||||
connection.setRequestProperty("accept", "application/json");
|
||||
InputStream responseStream = connection.getInputStream();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root = mapper.readTree(responseStream);
|
||||
this.setup = root.path("setup").asText();
|
||||
this.punchline = root.path("punchline").asText();
|
||||
}
|
||||
public String getSetup(){
|
||||
return setup;
|
||||
}
|
||||
public String getPunchline(){
|
||||
return punchline;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1 @@
|
||||
url=https://zenful.cloud/
|
||||
|
||||
browserC= chrome
|
||||
browserF= firefox
|
||||
|
||||
|
||||
@@ -3,31 +3,46 @@ package zacksolutions.pages;
|
||||
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 zacksolutions.base.Initialization;
|
||||
import zacksolutions.base.JokesAPI;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
|
||||
public class HomePage extends Initialization {
|
||||
@FindBy(id="message")
|
||||
WebElement message;
|
||||
// Using PageFactory Object Model we get our elemets
|
||||
@FindBy(id = "message")
|
||||
WebElement message;
|
||||
|
||||
@FindBy(css="button[type='submit']")
|
||||
WebElement button;
|
||||
@FindBy(css = "button[type='submit']")
|
||||
WebElement button;
|
||||
|
||||
@FindBy(css="tbody tr:nth-child(1) td:nth-child(1)")
|
||||
WebElement ConfirmText;
|
||||
@FindBy(xpath = "//tbody/tr[1]/td[1]")
|
||||
WebElement ConfirmText;
|
||||
|
||||
//Initialization
|
||||
public HomePage(){
|
||||
PageFactory.initElements(driver, this);
|
||||
}
|
||||
// Initialization
|
||||
public HomePage() {
|
||||
PageFactory.initElements(driver, this);
|
||||
}
|
||||
|
||||
//Actions
|
||||
public void insertText() throws InterruptedException {
|
||||
test = extent.createTest("Test msg");
|
||||
message.sendKeys("4 8 15 16 23 42");
|
||||
button.click();
|
||||
extent.flush();
|
||||
}
|
||||
public String textConfirmation(){
|
||||
return ConfirmText.getText();
|
||||
}
|
||||
// Actions
|
||||
public void insertText() throws InterruptedException, IOException {
|
||||
JokesAPI jokesAPI = new JokesAPI();
|
||||
jokesAPI.fetchJokes();
|
||||
String setup = jokesAPI.getSetup();
|
||||
String punchline = jokesAPI.getPunchline();
|
||||
test = extent.createTest("Test msg");
|
||||
message.sendKeys(setup + " ==> " + punchline);
|
||||
button.click();
|
||||
extent.flush();
|
||||
}
|
||||
|
||||
public void textConfirmation() {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15)); // Adjust the timeout as needed
|
||||
wait.until(ExpectedConditions.visibilityOf(ConfirmText));
|
||||
String joke = ConfirmText.getText();
|
||||
System.out.println(joke);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,42 @@
|
||||
package zacksolutions;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import zacksolutions.base.Initialization;
|
||||
import zacksolutions.pages.HomePage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HomePageTest extends Initialization {
|
||||
|
||||
HomePage homePage;
|
||||
public HomePageTest(){
|
||||
super();
|
||||
}
|
||||
@BeforeTest
|
||||
public void setUp(){
|
||||
BrowserInit();
|
||||
homePage = new HomePage();
|
||||
}
|
||||
@Test
|
||||
public void TextTest() throws InterruptedException {
|
||||
HomePage hp = new HomePage();
|
||||
hp.insertText();
|
||||
hp.textConfirmation();
|
||||
Assert.assertEquals(hp.textConfirmation(), "4 8 15 16 23 42");
|
||||
}
|
||||
@AfterTest
|
||||
public void tearDown(){
|
||||
driver.close();
|
||||
}
|
||||
HomePage homePage;
|
||||
|
||||
public HomePageTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Parameters("browser")
|
||||
@BeforeTest
|
||||
public void setUp(String browser) {
|
||||
BrowserInit(browser);
|
||||
homePage = new HomePage();
|
||||
System.out.println("Starting " + browser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TextTest() throws InterruptedException, IOException {
|
||||
HomePage hp = new HomePage();
|
||||
hp.insertText();
|
||||
/*
|
||||
hp.textConfirmation();
|
||||
*/
|
||||
System.out.println("Job is done, please check this link: " + prop.getProperty("url"));
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void tearDown() {
|
||||
driver.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
|
||||
<suite name="All Test Suite" thread-count="1" parallel="tests">
|
||||
<test name="CucumberTest">
|
||||
<classes>
|
||||
<class name="testNGRunner.TestRunner">
|
||||
</class>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
|
||||
<suite name="All Test Suite" thread-count="1" parallel="tests">
|
||||
<test name="FireFoxTest">
|
||||
<parameter name="browser" value="firefox"/>
|
||||
<classes>
|
||||
<class name="zacksolutions.HomePageTest">
|
||||
</class>
|
||||
</classes>
|
||||
</test>
|
||||
<test name="ChromeTest">
|
||||
<parameter name="browser" value="chrome"/>
|
||||
<classes>
|
||||
<class name="zacksolutions.HomePageTest">
|
||||
</class>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
||||
|
||||
Reference in New Issue
Block a user