chiwormjava 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.js +1 -1
  2. package/java.json +60 -4
  3. package/package.json +2 -1
  4. package/readme.md +318 -72
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const express = require('express');
3
3
  const open = require('open');
4
4
  const fs = require('fs');
package/java.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
- "linkedlist": {
3
- "title": "Linked List",
4
- "code": "class Outer{\\n\\tclass LinkedList{\\n\\t\\tclass Node{\\n\\t\\t\\tint data;\\n\\t\\t\\tNode next;\\n\\n\\t\\t\\tNode(int data){\\n\\t\\t\\t\\tthis.data = data;\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tNode head = null;\\n\\n\\t\\tvoid add(int data){\\n\\t\\t\\tNode n = new Node(data);\\n\\n\\t\\t\\tif(head == null){\\n\\t\\t\\t\\thead = n;\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\n\\t\\t\\tNode temp = head;\\n\\t\\t\\twhile(temp.next != null){\\n\\t\\t\\t\\ttemp = temp.next;\\n\\t\\t\\t}\\n\\n\\t\\t\\ttemp.next = n;\\n\\t\\t}\\n\\n\\t\\tvoid remove(int data){\\n\\t\\t\\tif(head == null) return;\\n\\n\\t\\t\\tif(head.data == data){\\n\\t\\t\\t\\thead = head.next;\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\n\\t\\t\\tNode temp = head;\\n\\t\\t\\twhile (temp.next != null){\\n\\t\\t\\t\\tif(temp.next.data == data){\\n\\t\\t\\t\\t\\ttemp.next = temp.next.next;\\n\\t\\t\\t\\t\\treturn;\\n\\t\\t\\t\\t}\\n\\t\\t\\t\\ttemp = temp.next;\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tvoid display(){\\n\\t\\t\\tNode temp = head;\\n\\t\\t\\twhile(temp != null){\\n\\t\\t\\t\\tSystem.out.println(temp.data + \\\" \\\" );\\n\\t\\t\\t\\ttemp = temp.next;\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String []args){\\n\\t\\tOuter o = new Outer();\\n\\t\\tLinkedList list = o.new LinkedList();\\n\\n\\t\\tlist.add(1);\\n\\t\\tlist.add(2);\\n\\t\\tlist.add(3);\\n\\n\\t\\tlist.display();\\n\\n\\t\\tlist.remove(2);\\n\\n\\t\\tlist.display();\\n\\t}\\n}"
2
+ "palindrome_user_input_java": {
3
+ "title": "Java Palindrome Number with User Input",
4
+ "code": "import java.util.Scanner;\\n\\npublic class Palindrome {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\n\\t\\tSystem.out.print(\\\"Enter a number: \\\" );\\n\\t\\tint num = sc.nextInt();\\n\\n\\t\\tint original = num;\\n\\t\\tint reverse = 0;\\n\\n\\t\\twhile (num > 0) {\\n\\t\\t\\tint digit = num % 10;\\n\\t\\t\\treverse = reverse * 10 + digit;\\n\\t\\t\\tnum = num / 10;\\n\\t\\t}\\n\\n\\t\\tif (original == reverse) {\\n\\t\\t\\tSystem.out.println(\\\"Palindrome Number\\\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\\\"Not a Palindrome\\\");\\n\\t\\t}\\n\\n\\t\\tsc.close();\\n\\t}\\n}"
5
+ },
6
+ "fibonacci_user_input_java": {
7
+ "title": "Java Fibonacci Series with User Input",
8
+ "code": "import java.util.Scanner;\\n\\npublic class Fibonacci {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\n\\t\\tSystem.out.print(\\\"Enter number of terms: \\\" );\\n\\t\\tint n = sc.nextInt();\\n\\n\\t\\tint a = 0, b = 1;\\n\\n\\t\\tSystem.out.println(\\\"Fibonacci Series:\\\");\\n\\n\\t\\tfor (int i = 1; i <= n; i++) {\\n\\t\\t\\tSystem.out.print(a + \\\" \\\" );\\n\\n\\t\\t\\tint next = a + b;\\n\\t\\t\\ta = b;\\n\\t\\t\\tb = next;\\n\\t\\t}\\n\\n\\t\\tsc.close();\\n\\t}\\n}"
9
+ },
10
+ "armstrong_user_input_java": {
11
+ "title": "Java Armstrong Number with User Input",
12
+ "code": "import java.util.Scanner;\\n\\npublic class Armstrong {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\n\\t\\tSystem.out.print(\\\"Enter a number: \\\" );\\n\\t\\tint num = sc.nextInt();\\n\\n\\t\\tint original = num;\\n\\t\\tint sum = 0;\\n\\t\\tint digits = 0;\\n\\n\\t\\tint temp = num;\\n\\t\\twhile (temp > 0) {\\n\\t\\t\\tdigits++;\\n\\t\\t\\ttemp = temp / 10;\\n\\t\\t}\\n\\n\\t\\ttemp = num;\\n\\t\\twhile (temp > 0) {\\n\\t\\t\\tint digit = temp % 10;\\n\\t\\t\\tsum += Math.pow(digit, digits);\\n\\t\\t\\ttemp = temp / 10;\\n\\t\\t}\\n\\n\\t\\tif (sum == original) {\\n\\t\\t\\tSystem.out.println(\\\"Armstrong Number\\\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\\\"Not an Armstrong Number\\\");\\n\\t\\t}\\n\\n\\t\\tsc.close();\\n\\t}\\n}"
13
+ },
14
+ "prime_user_input_java": {
15
+ "title": "Java Prime Number with User Input",
16
+ "code": "import java.util.Scanner;\\n\\npublic class Prime {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\n\\t\\tSystem.out.print(\\\"Enter a number: \\\" );\\n\\t\\tint num = sc.nextInt();\\n\\n\\t\\tboolean isPrime = true;\\n\\n\\t\\tif (num <= 1) {\\n\\t\\t\\tisPrime = false;\\n\\t\\t} else {\\n\\t\\t\\tfor (int i = 2; i <= num / 2; i++) {\\n\\t\\t\\t\\tif (num % i == 0) {\\n\\t\\t\\t\\t\\tisPrime = false;\\n\\t\\t\\t\\t\\tbreak;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tif (isPrime) {\\n\\t\\t\\tSystem.out.println(\\\"Prime Number\\\");\\n\\t\\t} else {\\n\\t\\t\\tSystem.out.println(\\\"Not a Prime Number\\\");\\n\\t\\t}\\n\\n\\t\\tsc.close();\\n\\t}\\n}"
17
+ },
18
+ "factorial_user_input_java": {
19
+ "title": "Java Factorial with User Input",
20
+ "code": "import java.util.Scanner;\\n\\npublic class Factorial {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\n\\t\\tSystem.out.print(\\\"Enter a number: \\\" );\\n\\t\\tint num = sc.nextInt();\\n\\n\\t\\tlong fact = 1;\\n\\n\\t\\tfor (int i = 1; i <= num; i++) {\\n\\t\\t\\tfact *= i;\\n\\t\\t}\\n\\n\\t\\tSystem.out.println(\\\"Factorial: \\\" + fact);\\n\\n\\t\\tsc.close();\\n\\t}\\n}"
21
+ },
22
+ "reverse_number_java": {
23
+ "title": "Java Reverse Number with User Input",
24
+ "code": "import java.util.Scanner;\\n\\npublic class ReverseNumber {\\n\\n\\tpublic static void main(String[] args) {\\n\\n\\t\\tScanner sc = new Scanner(System.in);\\n\\n\\t\\tSystem.out.print(\\\"Enter a number: \\\" );\\n\\t\\tint num = sc.nextInt();\\n\\n\\t\\tint reverse = 0;\\n\\n\\t\\twhile (num > 0) {\\n\\t\\t\\tint digit = num % 10;\\n\\t\\t\\treverse = reverse * 10 + digit;\\n\\t\\t\\tnum = num / 10;\\n\\t\\t}\\n\\n\\t\\tSystem.out.println(\\\"Reversed Number: \\\" + reverse);\\n\\n\\t\\tsc.close();\\n\\t}\\n}"
25
+ },
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ "junit_armstrong": {
38
+ "title": "JUnit Armstrong Number Test",
39
+ "code": "public class ArmstrongService {\\n\\n\\tpublic boolean isArmstrong(int num) {\\n\\t\\tint temp = num, sum = 0, rem;\\n\\n\\t\\twhile (num > 0) {\\n\\t\\t\\trem = num % 10;\\n\\t\\t\\tsum += rem * rem * rem;\\n\\t\\t\\tnum /= 10;\\n\\t\\t}\\n\\t\\treturn sum == temp;\\n\\t}\\n}\\n\\nimport org.junit.jupiter.api.Test;\\nimport static org.junit.jupiter.api.Assertions.*;\\n\\npublic class ArmstrongTest {\\n\\n\\t@Test\\n\\tvoid testArmstrong() {\\n\\t\\tArmstrongService s = new ArmstrongService();\\n\\t\\tassertTrue(s.isArmstrong(153));\\n\\t\\tassertFalse(s.isArmstrong(123));\\n\\t}\\n}"
40
+ },
41
+ "junit_volume": {
42
+ "title": "JUnit Volume Calculation Test",
43
+ "code": "public class VolumeService {\\n\\n\\tpublic double sphere(double r) {\\n\\t\\treturn (4.0 / 3.0) * Math.PI * r * r * r;\\n\\t}\\n\\n\\tpublic double cylinder(double r, double h) {\\n\\t\\treturn Math.PI * r * r * h;\\n\\t}\\n\\n\\tpublic double cube(double a) {\\n\\t\\treturn a * a * a;\\n\\t}\\n}\\n\\nimport org.junit.jupiter.api.Test;\\nimport static org.junit.jupiter.api.Assertions.*;\\n\\npublic class VolumeTest {\\n\\n\\tVolumeService s = new VolumeService();\\n\\n\\t@Test\\n\\tvoid testSphere() {\\n\\t\\tassertEquals(523.5, s.sphere(5), 0.1);\\n\\t}\\n\\n\\t@Test\\n\\tvoid testCylinder() {\\n\\t\\tassertEquals(314.1, s.cylinder(5, 4), 0.1);\\n\\t}\\n\\n\\t@Test\\n\\tvoid testCube() {\\n\\t\\tassertEquals(27, s.cube(3));\\n\\t}\\n}"
44
+ },
45
+ "junit_area": {
46
+ "title": "JUnit Area Calculation Test",
47
+ "code": "public class AreaService {\\n\\n\\tpublic double circle(double r) {\\n\\t\\treturn Math.PI * r * r;\\n\\t}\\n\\n\\tpublic double rectangle(double l, double b) {\\n\\t\\treturn l * b;\\n\\t}\\n\\n\\tpublic double triangle(double b, double h) {\\n\\t\\treturn 0.5 * b * h;\\n\\t}\\n}\\n\\nimport org.junit.jupiter.api.Test;\\nimport static org.junit.jupiter.api.Assertions.*;\\n\\npublic class AreaTest {\\n\\n\\tAreaService s = new AreaService();\\n\\n\\t@Test\\n\\tvoid testCircle() {\\n\\t\\tassertEquals(78.5, s.circle(5), 0.1);\\n\\t}\\n\\n\\t@Test\\n\\tvoid testRectangle() {\\n\\t\\tassertEquals(20, s.rectangle(5, 4));\\n\\t}\\n\\n\\t@Test\\n\\tvoid testTriangle() {\\n\\t\\tassertEquals(10, s.triangle(5, 4));\\n\\t}\\n}"
48
+ },
49
+ "testng_selenium_setup": {
50
+ "title": "Practical 5 TestNG and Selenium Setup Steps",
51
+ "code": "A) Setup TestNG in Maven Project\\n\\nStep 1: Create Maven Project\\nOpen Eclipse IDE\\nGo to File -> New -> Maven Project\\nSelect Create a simple project\\nClick Next\\n\\nEnter details:\\nGroupId: com.bca\\nArtifactId: PracticeTestNG\\nName: PracticeTestNG\\nClick Finish\\n\\nStep 2: Fix pom.xml Error\\nGo to Window -> Preferences -> Maven\\nEnable Update Maven Projects on Startup\\nClick Apply and Close\\n\\nStep 3: Add TestNG Dependency\\nOpen pom.xml and add:\\n<dependencies>\\n <dependency>\\n <groupId>org.testng</groupId>\\n <artifactId>testng</artifactId>\\n <version>7.12.0</version>\\n <scope>test</scope>\\n </dependency>\\n</dependencies>\\n\\nRight click project -> Maven -> Update Project\\n\\nStep 4: Install TestNG Plugin\\nGo to Help -> Eclipse Marketplace\\nSearch TestNG\\nInstall and restart Eclipse\\n\\nStep 5: Create Test Class\\nGo to src/test/java\\nRight click -> New -> Class\\nName: FirstTest\\n\\nStep 6: Simple Test Code\\nimport org.testng.annotations.Test;\\n\\npublic class FirstTest {\\n @Test\\n public void test1() {\\n System.out.println(\\\"TestNG is working\\\");\\n }\\n}\\n\\nRun using Run As -> TestNG Test\\n\\nB) Selenium + TestNG Setup\\n\\nStep 1: Add Dependencies\\nAdd in pom.xml:\\n<dependency>\\n <groupId>org.seleniumhq.selenium</groupId>\\n <artifactId>selenium-java</artifactId>\\n <version>4.21.0</version>\\n</dependency>\\n\\n<dependency>\\n <groupId>io.github.bonigarcia</groupId>\\n <artifactId>webdrivermanager</artifactId>\\n <version>5.8.0</version>\\n</dependency>\\n\\nRight click -> Maven -> Update Project\\n\\nStep 2: Final Working Code\\npackage mypack;\\n\\nimport org.openqa.selenium.By;\\nimport org.openqa.selenium.Keys;\\nimport org.openqa.selenium.WebDriver;\\nimport org.openqa.selenium.chrome.ChromeDriver;\\nimport org.testng.annotations.Test;\\nimport io.github.bonigarcia.wdm.WebDriverManager;\\n\\npublic class FirstTest {\\n\\n @Test\\n public void TestGoogle() throws Exception {\\n\\n WebDriverManager.chromedriver().setup();\\n\\n WebDriver driver = new ChromeDriver();\\n\\n driver.manage().window().maximize();\\n\\n driver.get(\\\"https://www.google.com/\\\");\\n\\n driver.findElement(By.name(\\\"q\\\"))\\n .sendKeys(\\\"skates\\\", Keys.ENTER);\\n\\n System.out.println(driver.getTitle());\\n\\n Thread.sleep(5000);\\n\\n driver.quit();\\n }\\n}\\n\\nImportant Notes\\n\\nIf Chrome does not open:\\nUpdate Chrome browser and WebDriverManager\\n\\nIf TestNG does not run:\\nUse Run As -> TestNG Test\\n\\nIf import errors occur:\\nEnsure import org.testng.annotations.Test is added"
52
+ },
53
+ "autoit_selenium_steps": {
54
+ "title": "AutoIt + Selenium File Upload Practical Steps",
55
+ "code": "Step 1: Download AutoIt from https://www.autoitscript.com/site/autoit/downloads/\\n\\nStep 2: Download SciTE Editor from https://www.autoitscript.com/site/autoit-script-editor/downloads/\\n\\nStep 3: Install AutoIt by extracting zip and running setup file\\n\\nStep 4: Install SciTE editor and complete setup\\n\\nStep 5: Open SciTE.exe and Au3Info_x64.exe (Finder Tool)\\n\\nStep 6: Open website https://the-internet.herokuapp.com/upload\\n\\nStep 7: Use Finder Tool to get details of file input and open button (Edit1, Button1)\\n\\nStep 8: Write AutoIt script:\\nControlFocus(\\\"Open\\\",\\\"\\\",\\\"Edit1\\\")\\nControlSetText(\\\"Open\\\",\\\"\\\",\\\"Edit1\\\",$CmdLine[1])\\nControlClick(\\\"Open\\\",\\\"\\\",\\\"Button1\\\")\\n\\nStep 9: Save as hello.au3 and compile using Tools -> Compile (X86 + X64)\\n\\nStep 10: Create Java Selenium project in Eclipse\\n\\nStep 11: Write Selenium code to open browser and click upload button\\n\\nStep 12: Use ProcessBuilder to run hello.exe with file path\\n\\nStep 13: Run Java application\\n\\nOutput: File upload is automated using AutoIt and Selenium"
56
+ },
57
+ "autoit_file_upload": {
58
+ "title": "AutoIt + Selenium File Upload Automation",
59
+ "code": "/* AutoIt Script */\\nControlFocus(\\\"Open\\\",\\\"\\\",\\\"Edit1\\\")\\nControlSetText(\\\"Open\\\",\\\"\\\",\\\"Edit1\\\",$CmdLine[1])\\nControlClick(\\\"Open\\\",\\\"\\\",\\\"Button1\\\")\\n\\n/* Java Selenium Code */\\npackage Auto;\\n\\nimport java.io.IOException;\\nimport org.openqa.selenium.By;\\nimport org.openqa.selenium.WebElement;\\nimport org.openqa.selenium.chrome.ChromeDriver;\\nimport org.openqa.selenium.interactions.Actions;\\n\\npublic class AutoITScirpt {\\n\\n\\tpublic static void main(String[] args) throws IOException, InterruptedException {\\n\\n\\t\\tChromeDriver driver = new ChromeDriver();\\n\\n\\t\\tdriver.get(\\\"https://the-internet.herokuapp.com/upload\\\");\\n\\n\\t\\tSystem.out.println(\\\"URL: \\\" + driver.getCurrentUrl());\\n\\t\\tSystem.out.println(\\\"Title: \\\" + driver.getTitle());\\n\\t\\tSystem.out.println(\\\"Source Length: \\\" + driver.getPageSource().length());\\n\\n\\t\\tWebElement buttonElement = driver.findElement(By.id(\\\"file-upload\\\"));\\n\\n\\t\\tActions act = new Actions(driver);\\n\\t\\tact.moveToElement(buttonElement).click().perform();\\n\\n\\t\\tThread.sleep(2000);\\n\\n\\t\\tProcessBuilder pBuilder = new ProcessBuilder(\\n\\t\\t\\t\\\"C:\\\\\\\\Users\\\\\\\\User\\\\\\\\OneDrive\\\\\\\\Desktop\\\\\\\\material\\\\\\\\STT\\\\\\\\hello.exe\\\",\\n\\t\\t\\t\\\"C:\\\\\\\\Users\\\\\\\\User\\\\\\\\Downloads\\\\\\\\chromedriver-win64\\\\\\\\hello.txt\\\"\\n\\t\\t);\\n\\n\\t\\tProcess process = pBuilder.start();\\n\\t\\tprocess.waitFor();\\n\\t}\\n}"
5
60
  }
6
- }
61
+ }
62
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chiwormjava",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -13,6 +13,7 @@
13
13
  "license": "ISC",
14
14
  "description": "",
15
15
  "dependencies": {
16
+ "chiwormjava": "^1.0.0",
16
17
  "express": "^5.2.1",
17
18
  "open": "^11.0.0"
18
19
  }
package/readme.md CHANGED
@@ -1,72 +1,318 @@
1
- class Outer{
2
- class LinkedList{
3
- class Node{
4
- int data;
5
- Node next;
6
-
7
- Node(int data){
8
- this.data = data;
9
- }
10
- }
11
-
12
- Node head = null;
13
-
14
- void add(int data){
15
- Node n = new Node(data);
16
-
17
- if(head == null){
18
- head = n;
19
- return;
20
- }
21
-
22
- Node temp = head;
23
- while(temp.next != null){
24
- temp = temp.next;
25
- }
26
-
27
- temp.next = n;
28
- }
29
-
30
- void remove(int data){
31
- if(head == null) return;
32
-
33
- if(head.data == data){
34
- head = head.next;
35
- return;
36
- }
37
-
38
- Node temp = head;
39
- while (temp.next != null){
40
- if(temp.next.data == data){
41
- temp.next = temp.next.next;
42
- return;
43
- }
44
- temp = temp.next;
45
- }
46
- }
47
-
48
- void display(){
49
- Node temp = head;
50
- while(temp != null){
51
- System.out.println(temp.data + \" \" );
52
- temp = temp.next;
53
- }
54
- System.out.println();
55
- }
56
- }
57
-
58
- public static void main(String []args){
59
- Outer o = new Outer();
60
- LinkedList list = o.new LinkedList();
61
-
62
- list.add(1);
63
- list.add(2);
64
- list.add(3);
65
-
66
- list.display();
67
-
68
- list.remove(2);
69
-
70
- list.display();
71
- }
72
- }
1
+ # 🚀 Java Code Watch
2
+
3
+ A simple CLI tool to **view and copy Java data structure code** (like LinkedList, Stack, etc.) directly in your browser.
4
+
5
+ ---
6
+
7
+ ## 📦 Installation
8
+
9
+ ### Option 1: Use without installing (recommended)
10
+
11
+ ```bash
12
+ npx javacodewatch
13
+ ```
14
+
15
+ ---
16
+
17
+ ### Option 2: Install locally
18
+
19
+ ```bash
20
+ npm install chiwormjava
21
+ ```
22
+
23
+ Run:
24
+
25
+ ```bash
26
+ npx javacodewatch
27
+ ```
28
+
29
+ ---
30
+
31
+ ### Option 3: Install globally (optional)
32
+
33
+ ```bash
34
+ npm install -g chiwormjava
35
+ ```
36
+
37
+ Run:
38
+
39
+ ```bash
40
+ javacodewatch
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 🧠 What it does
46
+
47
+ * Opens a local server
48
+ * Launches your browser
49
+ * Shows Java code snippets
50
+ * Click → View code
51
+ * Click Copy code
52
+
53
+ ---
54
+
55
+ ## 📸 Features
56
+
57
+ * 📚 Java DSA snippets (LinkedList, etc.)
58
+ * 🖱️ One-click code view
59
+ * 📋 Copy to clipboard
60
+ * 🌙 Clean dark UI
61
+
62
+ ---
63
+
64
+ ## ▶️ Usage
65
+
66
+ After running the command:
67
+
68
+ ```bash
69
+ javacodewatch
70
+ ```
71
+
72
+ 👉 Your browser will open automatically:
73
+
74
+ ```
75
+ http://localhost:3000
76
+ ```
77
+
78
+ ---
79
+
80
+ // RC
81
+ public void fillPhpForm() throws Exception {
82
+
83
+ WebDriverManager.chromedriver().setup();
84
+
85
+ WebDriver driver = new ChromeDriver();
86
+ driver.manage().window().maximize();
87
+
88
+
89
+ driver.get("http://localhost/form.php");
90
+
91
+
92
+ driver.findElement(By.name("username")).sendKeys("Shivam");
93
+ driver.findElement(By.name("email")).sendKeys("shivam@gmail.com");
94
+ driver.findElement(By.name("password")).sendKeys("123456");
95
+
96
+
97
+ driver.findElement(By.name("submit")).click();
98
+
99
+ Thread.sleep(5000);
100
+
101
+ System.out.println("URL: " + driver.getCurrentUrl());
102
+ System.out.println("Title: " + driver.getTitle());
103
+ System.out.println("Source: " + driver.getPageSource().length());
104
+
105
+ driver.quit();
106
+ }
107
+
108
+
109
+ ---
110
+
111
+ import org.openqa.selenium.By;
112
+ import org.openqa.selenium.WebDriver;
113
+ import org.openqa.selenium.chrome.ChromeDriver;
114
+
115
+ public class FormAutomation {
116
+
117
+ public static void main(String[] args) {
118
+
119
+ // Set path to ChromeDriver
120
+ System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
121
+
122
+ // Launch browser
123
+ WebDriver driver = new ChromeDriver();
124
+
125
+ // Maximize window
126
+ driver.manage().window().maximize();
127
+
128
+ // Open PHP form page
129
+ driver.get("http://localhost/form.php");
130
+
131
+ // Fill form
132
+ driver.findElement(By.name("username")).sendKeys("Shivam");
133
+ driver.findElement(By.name("email")).sendKeys("shivam@gmail.com");
134
+ driver.findElement(By.name("password")).sendKeys("123456");
135
+
136
+ // Submit form
137
+ driver.findElement(By.name("submit")).click();
138
+
139
+ // Wait
140
+ try {
141
+ Thread.sleep(5000);
142
+ } catch (Exception e) {
143
+ e.printStackTrace();
144
+ }
145
+
146
+ // Close browser
147
+ driver.quit();
148
+ }
149
+ }
150
+
151
+
152
+ ---
153
+
154
+ Volume Formulas
155
+
156
+ Sphere
157
+
158
+ (4.0 / 3.0) * Math.PI * r * r * r
159
+
160
+ Cylinder
161
+
162
+ Math.PI * r * r * h
163
+
164
+ Cube
165
+
166
+ a * a * a
167
+
168
+
169
+ ---
170
+
171
+ Area Formulas
172
+
173
+ Circle
174
+
175
+ Math.PI * r * r
176
+
177
+ Rectangle
178
+
179
+ l * b
180
+
181
+ Triangle
182
+
183
+ 0.5 * b * h
184
+
185
+
186
+ ---
187
+
188
+ public boolean isArmstrong(int num) {
189
+ int temp = num, sum = 0, rem;
190
+ while (num > 0) {
191
+ rem = num % 10;
192
+ sum += rem * rem * rem;
193
+ num /= 10;
194
+ }
195
+
196
+ return sum == temp;
197
+
198
+ }
199
+
200
+
201
+ ---
202
+
203
+
204
+ ControlFocus("Open","","Edit1")
205
+ ControlSetText("Open","","Edit1",$CmdLine[1])
206
+ ControlClick("Open","","Button1")
207
+
208
+
209
+ package Auto;
210
+
211
+ import java.io.IOException;
212
+
213
+ import org.openqa.selenium.By;
214
+ import org.openqa.selenium.WebElement;
215
+ import org.openqa.selenium.chrome.ChromeDriver;
216
+ import org.openqa.selenium.interactions.Actions;
217
+
218
+ public class AutoITScript {
219
+
220
+ public static void main(String[] args) throws IOException, InterruptedException {
221
+
222
+
223
+ ChromeDriver driver = new ChromeDriver();
224
+
225
+
226
+ driver.get("https://the-internet.herokuapp.com/upload");
227
+
228
+
229
+ System.out.println("URL: " + driver.getCurrentUrl());
230
+ System.out.println("Title: " + driver.getTitle());
231
+ System.out.println("Source Length: " + driver.getPageSource().length());
232
+
233
+
234
+ WebElement buttonElement = driver.findElement(By.id("file-upload"));
235
+
236
+ Actions act = new Actions(driver);
237
+ act.moveToElement(buttonElement).click().perform();
238
+
239
+
240
+ Thread.sleep(2000);
241
+
242
+
243
+ ProcessBuilder pBuilder = new ProcessBuilder(
244
+ "C:\\Users\\User\\Desktop\\upload.exe", // your exe path
245
+ "C:\\Users\\User\\Desktop\\file.txt" // file to upload
246
+ );
247
+
248
+ Process process = pBuilder.start();
249
+ process.waitFor();
250
+
251
+
252
+ Thread.sleep(3000);
253
+
254
+ driver.quit();
255
+ }
256
+ }
257
+
258
+ ---
259
+
260
+ package mypack;
261
+
262
+ import org.openqa.selenium.By;
263
+ import org.openqa.selenium.Keys;
264
+ import org.openqa.selenium.WebDriver;
265
+ import org.openqa.selenium.chrome.ChromeDriver;
266
+
267
+ import org.testng.annotations.Test;
268
+
269
+ import io.github.bonigarcia.wdm.WebDriverManager;
270
+
271
+ public class FirstTest {
272
+
273
+ @Test
274
+ public void TestGoogle() throws Exception {
275
+
276
+ WebDriverManager.chromedriver().setup();
277
+
278
+ WebDriver driver = new ChromeDriver();
279
+
280
+ driver.manage().window().maximize();
281
+
282
+ driver.get("https://www.google.com/");
283
+
284
+ driver.findElement(By.name("q"))
285
+ .sendKeys("skates", Keys.ENTER);
286
+
287
+ System.out.println(driver.getTitle());
288
+
289
+ Thread.sleep(5000);
290
+
291
+ driver.quit();
292
+ }
293
+ }
294
+
295
+
296
+
297
+ <dependencies>
298
+
299
+ <dependency>
300
+ <groupId>org.testng</groupId>
301
+ <artifactId>testng</artifactId>
302
+ <version>7.12.0</version>
303
+ <scope>test</scope>
304
+ </dependency>
305
+
306
+ <dependency>
307
+ <groupId>org.seleniumhq.selenium</groupId>
308
+ <artifactId>selenium-java</artifactId>
309
+ <version>4.21.0</version>
310
+ </dependency>
311
+
312
+ <dependency>
313
+ <groupId>io.github.bonigarcia</groupId>
314
+ <artifactId>webdrivermanager</artifactId>
315
+ <version>5.8.0</version>
316
+ </dependency>
317
+
318
+ </dependencies>