Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 290b3b4

Browse files
committed
Stubs: fetch source code
1 parent b408c4f commit 290b3b4

File tree

6 files changed

+110
-21
lines changed

6 files changed

+110
-21
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33

44
# Ignore Gradle build output directory
55
build
6+
7+
*.log
8+
.vscode/
9+
bin/
10+
data/

app/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ dependencies {
2121

2222
// This dependency is used by the application.
2323
implementation libs.guava
24+
25+
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
26+
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.20.0'
2427
}
2528

2629
// Apply a specific Java toolchain to ease working on different environments.
+14-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
/*
2-
* This Java source file was generated by the Gradle 'init' task.
3-
*/
41
package xgooglecalendar;
52

63
public class App {
7-
public String getGreeting() {
8-
return "Hello World!";
4+
public void getGreeting() throws InterruptedException {
5+
// Removes unnecessary warnings from console
6+
System.setProperty("java.util.logging.config.file", "logging.properties");
7+
8+
TestCases tests = new TestCases(); // Initialize your test class
9+
10+
// TODO: call your test case functions one after other here
11+
// START Tests
12+
tests.testCase01();
13+
14+
// END Tests
15+
tests.endTest(); // End your test by clearing connections and closing browser
916
}
1017

11-
public static void main(String[] args) {
12-
System.out.println(new App().getGreeting());
18+
public static void main(String[] args) throws InterruptedException {
19+
new App().getGreeting();
1320
}
1421
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package xgooglecalendar;
2+
3+
import java.io.File;
4+
import java.time.Duration;
5+
import java.util.logging.Level;
6+
7+
import org.openqa.selenium.WebDriver;
8+
import org.openqa.selenium.chrome.ChromeDriver;
9+
import org.openqa.selenium.chrome.ChromeDriverService;
10+
import org.openqa.selenium.chrome.ChromeOptions;
11+
import org.openqa.selenium.logging.LogType;
12+
import org.openqa.selenium.logging.LoggingPreferences;
13+
14+
public class TestCases {
15+
WebDriver driver;
16+
17+
public TestCases() {
18+
System.out.println("Constructor: TestCases");
19+
System.out.println("Start Tests: TestCases");
20+
21+
ChromeOptions options = new ChromeOptions();
22+
LoggingPreferences logs = new LoggingPreferences();
23+
24+
// Set log level and type
25+
logs.enable(LogType.BROWSER, Level.ALL);
26+
logs.enable(LogType.DRIVER, Level.ALL);
27+
options.setCapability("goog:loggingPrefs", logs);
28+
options.addArguments("start-maximized");
29+
options.addArguments("--disable-blink-features=AutomationControlled");
30+
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222"); // Connect to the chrome-window running on debugging port
31+
32+
// Set path for log file
33+
File theDir = new File("logs");
34+
if (!theDir.exists()) {
35+
theDir.mkdirs();
36+
}
37+
System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "logs" + File.separator + "chromedriver.log");
38+
39+
driver = new ChromeDriver(options);
40+
41+
// Implicit wait
42+
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
43+
}
44+
45+
public void endTest() {
46+
System.out.println("End Tests: TestCases");
47+
driver.quit();
48+
}
49+
50+
public void testCase01() throws InterruptedException {
51+
System.out.println("\nTestCase01: START");
52+
driver.get("https://www.google.com");
53+
Thread.sleep(5000);
54+
System.out.println("TestCase01: END\n");
55+
}
56+
}

app/src/test/java/xgooglecalendar/AppTest.java

-14
This file was deleted.

chrome_run.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
6+
def open_chrome_with_user_data():
7+
# Check the operating system
8+
if os.name == 'nt': # Windows
9+
# Paths for Chrome in regular and x86 (32-bit) directories
10+
chrome_path = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
11+
chrome_path_x86 = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
12+
13+
# Check if Chrome is in the regular directory
14+
if os.path.isfile(chrome_path):
15+
subprocess.run([chrome_path, "--remote-debugging-port=9222"])
16+
# Check if Chrome is in the x86 directory
17+
elif os.path.isfile(chrome_path_x86):
18+
subprocess.run([chrome_path_x86, "--remote-debugging-port=9222"])
19+
else:
20+
print("Chrome executable not found in standard locations.")
21+
sys.exit(1)
22+
elif sys.platform == "darwin": # Macos
23+
subprocess.run(["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--remote-debugging-port=9222"])
24+
else:
25+
subprocess.run(['google-chrome', "--remote-debugging-port=9222"])
26+
27+
# Close the script
28+
sys.exit()
29+
30+
31+
if __name__ == "__main__":
32+
open_chrome_with_user_data()

0 commit comments

Comments
 (0)