Commit 1e5e29a0 authored by Arsam Ali's avatar Arsam Ali

POC Updated with all files

parent 2ff47552
......@@ -83,6 +83,41 @@
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>5.0.0-alpha.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.http-client/google-http-client -->
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.45.0</version>
</dependency>
<!-- 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>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
......
......@@ -13,8 +13,6 @@ import java.time.Duration;
public class NisumPage {
WebDriver driver;
// java.util.logging.Logger initialization
//private static final Logger log = Logger.getLogger(NisumPage.class.getName());
private static final Logger log = LogManager.getLogger(NisumPage.class);
......
package org.example.OpenAI;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class LogParser {
public List<String> extractErrors(String logFilePath) {
List<String> errorLogs = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(logFilePath))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains("ERROR")) {
errorLogs.add(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return errorLogs;
}
}
package org.example.OpenAI;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) {
String logFilePath = "/Users/arsamali/Documents/IdeaProjects/POC-Arsam/src/main/resources/log4j2.log";
LogParser logParser = new LogParser();
List<String> errorLogs = logParser.extractErrors(logFilePath);
OpenAISuggestions openAI = new OpenAISuggestions();
for (String errorLog : errorLogs) {
System.out.println("Error: " + errorLog);
try {
Map<String, Object> suggestions = openAI.getSuggestions(errorLog);
System.out.println("OpenAI Suggestions: " + suggestions.get("suggestion"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("-------------------------------");
}
}
}
package org.example.OpenAI;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class OpenAISuggestions {
private static final String API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=AIzaSyDwyMA69dj-7tejDr7iVlKzU0Y86OGMAZ0";
private final OkHttpClient client = new OkHttpClient();
private final ObjectMapper objectMapper = new ObjectMapper(); // Jackson object mapper for JSON
public Map<String, Object> getSuggestions(String errorLog) throws IOException {
Map<String, Object> jsonBody = new HashMap<>();
Map<String, Object> part = new HashMap<>();
part.put("text", errorLog);
Map<String, Object> content = new HashMap<>();
content.put("parts", List.of(part));
jsonBody.put("contents", List.of(content));
RequestBody body = RequestBody.create(
objectMapper.writeValueAsString(jsonBody),
MediaType.get("application/json; charset=utf-8")
);
Request request = new Request.Builder()
.url(API_URL)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unexpected response code: " + response);
}
String responseBody = response.body().string();
return parseResponse(responseBody); // Parse the response
}
}
private Map<String, Object> parseResponse(String responseBody) throws IOException {
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
List<Map<String, Object>> candidates = (List<Map<String, Object>>) responseMap.get("candidates");
Map<String, Object> result = new HashMap<>();
if (candidates != null && !candidates.isEmpty()) {
Map<String, Object> firstCandidate = candidates.get(0);
Map<String, Object> content = (Map<String, Object>) firstCandidate.get("content");
List<Map<String, Object>> parts = (List<Map<String, Object>>) content.get("parts");
if (parts != null && !parts.isEmpty()) {
Map<String, Object> firstPart = parts.get(0);
String suggestion = (String) firstPart.getOrDefault("text", "No suggestions found.");
result.put("suggestion", suggestion.trim());
} else {
result.put("suggestion", "No suggestions found.");
}
} else {
result.put("suggestion", "No suggestions found.");
}
return result;
}
}
17:45:30.253 [main] INFO - NisumPage object created with WebDriver instance.
17:45:30.259 [main] INFO - Attempting to search for the term: Nisum Technologies
17:45:30.445 [main] INFO - Search text 'Nisum Technologies' entered in search box.
17:45:30.672 [main] INFO - Search for 'Nisum Technologies' submitted.
17:45:30.673 [main] INFO - Attempting to click the first link for Nisum website.
17:45:36.936 [main] INFO - Clicked on the first Nisum website link.
17:45:36.936 [main] INFO - Attempting to hover over the Global Careers button.
17:45:37.129 [main] INFO - Hovered over the Global Careers button.
17:45:37.129 [main] INFO - Attempting to click on the Pakistan Careers button.
17:45:47.633 [main] ERROR - An unexpected error occurred while clicking Pakistan Careers.
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //li[@class='hs-menu-item hs-menu-depth-1 hs-item-has-children']//a[@role='menuitem'][normalize-space()='Pakistan'] (tried for 10 second(s) with 500 milliseconds interval)
Build info: version: '4.25.0', revision: '8a8aea2337'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '14.4', java.version: '18.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 129.0.6668.100, chrome: {chromedriverVersion: 129.0.6668.91 (b00bc8b76d60..., userDataDir: /var/folders/5j/_8d3sdx5099...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:63945}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: mac, proxy: Proxy(), se:cdp: ws://localhost:63945/devtoo..., se:cdpVersion: 129.0.6668.100, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 834e5df5b9058b633a2f058bc3cb87f7
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:84) ~[selenium-support-4.25.0.jar:?]
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228) ~[selenium-support-4.25.0.jar:?]
at org.example.NisumSearchPage.NisumPage.clickPakistanCareers(NisumPage.java:73) [classes/:?]
at org.example.NisumSearchSteps.NisumSteps.iClickOnThePakistanCareersButton(NisumSteps.java:45) [classes/:?]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:577) ~[?:?]
at io.cucumber.java.Invoker.doInvoke(Invoker.java:66) [cucumber-java-7.11.0.jar:7.11.0]
at io.cucumber.java.Invoker.invoke(Invoker.java:24) [cucumber-java-7.11.0.jar:7.11.0]
at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47) [cucumber-java-7.11.0.jar:7.11.0]
at io.cucumber.java.JavaStepDefinition.execute(JavaStepDefinition.java:29) [cucumber-java-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.CoreStepDefinition.execute(CoreStepDefinition.java:66) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:63) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:84) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.TestStep.run(TestStep.java:56) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.PickleStepTestStep.run(PickleStepTestStep.java:51) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.TestCase.run(TestCase.java:84) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runner.Runner.runPickle(Runner.java:75) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.Runtime.lambda$executePickle$6(Runtime.java:132) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:130) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:130) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.Runtime.lambda$executePickle$7(Runtime.java:132) [cucumber-core-7.11.0.jar:7.11.0]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:253) [cucumber-core-7.11.0.jar:7.11.0]
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123) [?:?]
at io.cucumber.core.runtime.Runtime.lambda$runFeatures$3(Runtime.java:114) [cucumber-core-7.11.0.jar:7.11.0]
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) [?:?]
at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:200) [?:?]
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602) [?:?]
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129) [?:?]
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527) [?:?]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513) [?:?]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) [?:?]
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) [?:?]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [?:?]
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) [?:?]
at io.cucumber.core.runtime.Runtime.runFeatures(Runtime.java:115) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.Runtime.lambda$run$0(Runtime.java:84) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.Runtime.execute(Runtime.java:99) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.runtime.Runtime.run(Runtime.java:82) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.cli.Main.run(Main.java:87) [cucumber-core-7.11.0.jar:7.11.0]
at io.cucumber.core.cli.Main.main(Main.java:30) [cucumber-core-7.11.0.jar:7.11.0]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment