Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49ba575cfd |
File diff suppressed because one or more lines are too long
3
Jenkinsfile
vendored
3
Jenkinsfile
vendored
@ -2,11 +2,12 @@ pipeline {
|
||||
agent {
|
||||
label "agent_locke"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
// This runs the Maven test phase
|
||||
sh 'mvn test -P Regression'
|
||||
sh 'mvn test'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
72
pom.xml
72
pom.xml
@ -14,61 +14,7 @@
|
||||
<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>
|
||||
@ -117,22 +63,6 @@
|
||||
<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>
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
<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>
|
||||
<a href="#"><span class="badge badge-primary">Sep 29, 2024 01:21:35 AM</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -81,7 +81,7 @@
|
||||
<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>1:21:37 AM</span> / <span>00:00:00:000</span>
|
||||
<span class="badge pass-bg log float-right">Pass</span>
|
||||
</p>
|
||||
</div>
|
||||
@ -90,8 +90,8 @@
|
||||
<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-success'>09.29.2024 1:21:37 AM</span>
|
||||
<span class='badge badge-danger'>09.29.2024 1:21:37 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>
|
||||
@ -115,13 +115,13 @@
|
||||
<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>
|
||||
<h3>Sep 29, 2024 01:21:35 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>
|
||||
<h3>Sep 29, 2024 01:21:37 AM</h3>
|
||||
</div></div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
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"
|
||||
@ -1,35 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
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,23 +2,19 @@ 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.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
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;
|
||||
@ -40,8 +36,7 @@ public class Initialization {
|
||||
|
||||
}
|
||||
|
||||
@Parameters("browser")
|
||||
public void BrowserInit(String browser) {
|
||||
public void BrowserInit() {
|
||||
// our EXTENTREPORTS SETUP!
|
||||
|
||||
String path = System.getProperty("user.dir") + "/reports/index.html";
|
||||
@ -52,50 +47,31 @@ public class Initialization {
|
||||
extent.attachReporter(spark);
|
||||
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("browserC");
|
||||
|
||||
// launching FireFox
|
||||
if (browsername.equalsIgnoreCase("firefox")) {
|
||||
// System.setProperty("web-driver.gecko.driver","user.dir" +
|
||||
// "/drivers/geckodriver");
|
||||
// driver = new FirefoxDriver();
|
||||
driver.get(prop.getProperty("url"));
|
||||
}
|
||||
|
||||
//
|
||||
// // 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"));
|
||||
// launching Chrome
|
||||
if (browsername.equalsIgnoreCase("chrome")) {
|
||||
// System.setProperty("web-driver.gecko.driver", "user.dir" +
|
||||
// "/drivers/chromedriver");
|
||||
// driver = new ChromeDriver();
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
driver = new ChromeDriver(options);
|
||||
options.addArguments("--no-sandbox");
|
||||
options.addArguments("--disable-dev-shm-usage");
|
||||
options.addArguments("--headless");
|
||||
options.addArguments("--remote-debugging-port=9222");
|
||||
options.setBinary("/usr/bin/google-chrome");
|
||||
driver.get(prop.getProperty("url"));
|
||||
}
|
||||
driver.manage().window().maximize();
|
||||
driver.manage().deleteAllCookies();
|
||||
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
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 +1,5 @@
|
||||
url=https://zenful.cloud/
|
||||
|
||||
browserC= chrome
|
||||
browserF= firefox
|
||||
|
||||
|
||||
@ -3,46 +3,32 @@ 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 {
|
||||
// Using PageFactory Object Model we get our elemets
|
||||
@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(xpath = "//tbody/tr[1]/td[1]")
|
||||
WebElement ConfirmText;
|
||||
@FindBy(css="tbody tr:nth-child(1) td:nth-child(1)")
|
||||
WebElement ConfirmText;
|
||||
|
||||
// Initialization
|
||||
public HomePage() {
|
||||
PageFactory.initElements(driver, this);
|
||||
}
|
||||
//Initialization
|
||||
public HomePage(){
|
||||
PageFactory.initElements(driver, this);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
//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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
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;
|
||||
@ -17,22 +15,18 @@ public class HomePageTest extends Initialization {
|
||||
super();
|
||||
}
|
||||
|
||||
@Parameters("browser")
|
||||
@BeforeTest
|
||||
public void setUp(String browser) {
|
||||
BrowserInit(browser);
|
||||
public void setUp() {
|
||||
BrowserInit();
|
||||
homePage = new HomePage();
|
||||
System.out.println("Starting " + browser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TextTest() throws InterruptedException, IOException {
|
||||
public void TextTest() throws InterruptedException {
|
||||
HomePage hp = new HomePage();
|
||||
hp.insertText();
|
||||
/*
|
||||
hp.textConfirmation();
|
||||
*/
|
||||
System.out.println("Job is done, please check this link: " + prop.getProperty("url"));
|
||||
Assert.assertEquals(hp.textConfirmation(), "4 8 15 16 23 42");
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
<?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>
|
||||
|
||||
15
testng.xml
15
testng.xml
@ -1,19 +1,12 @@
|
||||
<?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"/>
|
||||
<suite name="All Test Suite">
|
||||
<test verbose="2" preserve-order="true" name="/home/ilyes/SeleniumPractice/Zenful">
|
||||
<classes>
|
||||
<class name="zacksolutions.HomePageTest">
|
||||
<methods><include name="TextTest"/>
|
||||
</methods>
|
||||
</class>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user