fix: 21 finally fix with getter methods
jenkins/ZenProject/pipeline/head This commit looks good

This commit is contained in:
2024-10-01 22:23:12 -04:00
parent 4a5405049c
commit ed9847864a
4 changed files with 28 additions and 17 deletions
+11 -6
View File
@@ -13,10 +13,10 @@ import java.net.URL;
*/
public class JokesAPI {
public static String setup;
public static String punchline;
private String setup;
private String punchline;
public static void main(String[] args) throws IOException {
public void fetchJokes() throws IOException {
URL apiUrl = new URL("https://official-joke-api.appspot.com/jokes/random");
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
@@ -24,8 +24,13 @@ public class JokesAPI {
InputStream responseStream = connection.getInputStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(responseStream);
setup = root.path("setup").asText();
punchline = root.path("punchline").asText();
System.out.println(setup + " --> " + punchline);
this.setup = root.path("setup").asText();
this.punchline = root.path("punchline").asText();
}
public String getSetup(){
return setup;
}
public String getPunchline(){
return punchline;
}
}
@@ -6,8 +6,7 @@ import org.openqa.selenium.support.PageFactory;
import zacksolutions.base.Initialization;
import zacksolutions.base.JokesAPI;
import static zacksolutions.base.JokesAPI.punchline;
import static zacksolutions.base.JokesAPI.setup;
import java.io.IOException;
public class HomePage extends Initialization {
// Using PageFactory Object Model we get our elemets
@@ -20,15 +19,20 @@ public class HomePage extends Initialization {
@FindBy(xpath = "//tbody/tr[1]/td[1]")
WebElement ConfirmText;
// Initialization
public HomePage() {
PageFactory.initElements(driver, this);
}
// Actions
public void insertText() throws InterruptedException {
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);
message.sendKeys(setup + " ==> " + punchline);
button.click();
extent.flush();
}
@@ -7,6 +7,8 @@ import org.testng.annotations.Test;
import zacksolutions.base.Initialization;
import zacksolutions.pages.HomePage;
import java.io.IOException;
public class HomePageTest extends Initialization {
HomePage homePage;
@@ -22,7 +24,7 @@ public class HomePageTest extends Initialization {
}
@Test
public void TextTest() throws InterruptedException {
public void TextTest() throws InterruptedException, IOException {
System.out.println(driver.getTitle());
HomePage hp = new HomePage();
hp.insertText();