Skip to content

Commit 51714b2

Browse files
onlyfullstacksaurabhoza02
authored andcommitted
Adding back the selenium changes with extent report
1 parent 92d6cd7 commit 51714b2

File tree

18 files changed

+1110
-0
lines changed

18 files changed

+1110
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
.idea

pom.xml

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>selenium-tutorial</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.seleniumhq.selenium</groupId>
14+
<artifactId>selenium-java</artifactId>
15+
<version>3.141.59</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>org.testng</groupId>
19+
<artifactId>testng</artifactId>
20+
<version>7.1.0</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>com.relevantcodes</groupId>
24+
<artifactId>extentreports</artifactId>
25+
<version>2.41.2</version>
26+
</dependency>
27+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
28+
<dependency>
29+
<groupId>commons-io</groupId>
30+
<artifactId>commons-io</artifactId>
31+
<version>2.6</version>
32+
</dependency>
33+
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
34+
<dependency>
35+
<groupId>commons-codec</groupId>
36+
<artifactId>commons-codec</artifactId>
37+
<version>1.9</version>
38+
</dependency>
39+
40+
</dependencies>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<version>2.21.0</version>
48+
<configuration>
49+
<suiteXmlFiles>
50+
<suiteXmlFile>src/test/testng-suite.xml</suiteXmlFile>
51+
</suiteXmlFiles>
52+
<properties>
53+
<!--suppress UnresolvedMavenProperty -->
54+
<env-host>${env-host}</env-host>
55+
</properties>
56+
</configuration>
57+
</plugin>
58+
</plugins>
59+
60+
</build>
61+
<profiles>
62+
<profile>
63+
<id>local</id>
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-surefire-plugin</artifactId>
69+
<version>2.21.0</version>
70+
<configuration>
71+
<suiteXmlFiles>
72+
<suiteXmlFile>testng.xml</suiteXmlFile>
73+
</suiteXmlFiles>
74+
<properties>
75+
<!--suppress UnresolvedMavenProperty -->
76+
<env-host>https://onlyfullstack-e1.com</env-host>
77+
<env-db-url>https://onlyfullstack-e1.com</env-db-url>
78+
<env-db-username>onlyfullstack</env-db-username>
79+
<env-db-password>dbpassword</env-db-password>
80+
</properties>
81+
</configuration>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
</profile>
86+
<profile>
87+
<id>E1</id>
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-surefire-plugin</artifactId>
93+
<version>2.21.0</version>
94+
<configuration>
95+
<suiteXmlFiles>
96+
<suiteXmlFile>testng.xml</suiteXmlFile>
97+
</suiteXmlFiles>
98+
<properties>
99+
<!--suppress UnresolvedMavenProperty -->
100+
<env-host>https://onlyfullstack-e1.com</env-host>
101+
<env-db-url>https://onlyfullstack-e1.com</env-db-url>
102+
<env-db-username>onlyfullstack</env-db-username>
103+
<env-db-password>dbpassword</env-db-password>
104+
</properties>
105+
</configuration>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
</profile>
110+
<profile>
111+
<id>E2</id>
112+
<build>
113+
<plugins>
114+
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
116+
<artifactId>maven-surefire-plugin</artifactId>
117+
<version>2.21.0</version>
118+
<configuration>
119+
<suiteXmlFiles>
120+
<suiteXmlFile>testng.xml</suiteXmlFile>
121+
</suiteXmlFiles>
122+
<properties>
123+
<!--suppress UnresolvedMavenProperty -->
124+
<env-host>https://onlyfullstack-e1.com</env-host>
125+
<env-db-url>https://onlyfullstack-e1.com</env-db-url>
126+
<env-db-username>onlyfullstack</env-db-username>
127+
<env-db-password>dbpassword</env-db-password>
128+
</properties>
129+
</configuration>
130+
</plugin>
131+
</plugins>
132+
</build>
133+
</profile>
134+
</profiles>
135+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.onlyfullstack.selenium;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.chrome.ChromeDriver;
5+
import org.openqa.selenium.chrome.ChromeDriverService;
6+
7+
public class FirstTest {
8+
9+
public static void main(String[] args) throws InterruptedException {
10+
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "/Users/ssoza1/Documents/chrome-web-driver/chromedriver");
11+
WebDriver webDriver = new ChromeDriver();
12+
webDriver.get("https://onlyfullstack.blogspot.com/2020/03/best-demo-website-to-practice-selenium.html");
13+
14+
Thread.sleep(3000);
15+
16+
System.out.println("Page title - " + webDriver.getTitle());
17+
webDriver.close();
18+
System.exit(0);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.onlyfullstack.selenium;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.JavascriptExecutor;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.chrome.ChromeDriver;
8+
import org.openqa.selenium.chrome.ChromeDriverService;
9+
10+
public class Sample {
11+
12+
public static void main(String[] args) throws InterruptedException {
13+
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "/Users/ssoza1/Documents/chrome-web-driver/chromedriver");
14+
WebDriver webDriver = new ChromeDriver();
15+
webDriver.get("https://onlyfullstack.blogspot.com/2020/03/best-demo-website-to-practice-selenium.html");
16+
17+
webDriver.manage().window().maximize();
18+
JavascriptExecutor js = (JavascriptExecutor) webDriver;
19+
20+
js.executeScript("window.scrollBy(0,2200)");
21+
22+
23+
WebElement nameTextField = webDriver.findElement(By.id("name-text-field-id"));
24+
nameTextField.sendKeys("neha ");
25+
26+
webDriver.findElement(By.className("email-text-field-class")).sendKeys("j.nnehajoshi@gmail.com");
27+
webDriver.findElement(By.name("Zip")).sendKeys("12345");
28+
29+
webDriver.findElement(By.tagName("textarea")).sendKeys("saurabhj");
30+
webDriver.findElement(By.xpath("//*[@id=\"post-body-39246966950473039\"]/div/form/table/tbody/tr[4]/td[2]/input")).sendKeys("31/07/1991");
31+
32+
String lable2 =webDriver.findElement(By.xpath("//*[@id=\"post-body-39246966950473039\"]/div/form/table/tbody/tr[1]/td[1]")).getText();
33+
if(!lable2.equals("Email1")){
34+
System.out.println("email not working");
35+
}
36+
37+
validateLables(webDriver);
38+
39+
Thread.sleep(3000);
40+
41+
webDriver.close();
42+
System.exit(0);
43+
}
44+
45+
public static void validateLables(WebDriver webDriver) {
46+
47+
48+
String lable = webDriver.findElement(By.xpath("//*[@id=\"post-body-39246966950473039\"]/div/form/table/tbody/tr[1]/td[1]")).getText();
49+
if (!lable.equals("Name")) {
50+
51+
System.out.println("name not working");
52+
}
53+
}
54+
55+
}
56+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.onlyfullstack.selenium.alerts;
2+
3+
import org.openqa.selenium.Alert;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.chrome.ChromeDriver;
7+
import org.openqa.selenium.chrome.ChromeDriverService;
8+
9+
public class AlertOperations {
10+
11+
public static void main(String[] args) {
12+
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "/Users/ssoza1/Documents/chrome-web-driver/chromedriver");
13+
WebDriver webDriver = new ChromeDriver();
14+
webDriver.get("https://onlyfullstack.blogspot.com/2020/03/best-demo-website-to-practice-selenium.html#alert-tutorial");
15+
16+
webDriver.findElement(By.linkText("Simple Alert")).click();
17+
Alert alert = webDriver.switchTo().alert();
18+
String alertText = alert.getText();
19+
System.out.println("Alert text = " + alertText);
20+
alert.accept();
21+
22+
webDriver.findElement(By.xpath("//*[@id=\"alert-tutorial\"]/tbody/tr[3]/td/a")).click();
23+
Alert confirmAlert = webDriver.switchTo().alert();
24+
String confirmAlertText = confirmAlert.getText();
25+
System.out.println("Confirm Alert text = " + confirmAlertText);
26+
confirmAlert.dismiss();
27+
28+
webDriver.findElement(By.linkText("Prompt Alert")).click();
29+
Alert promptAlert = webDriver.switchTo().alert();
30+
String promptAlertText = promptAlert.getText();
31+
System.out.println("Prompt Alert text = " + promptAlertText);
32+
promptAlert.accept();
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.onlyfullstack.selenium.dropDown;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.JavascriptExecutor;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.chrome.ChromeDriver;
8+
import org.openqa.selenium.chrome.ChromeDriverService;
9+
import org.openqa.selenium.support.ui.Select;
10+
11+
import java.util.List;
12+
13+
public class DropDownOperations {
14+
public static void main(String[] args) throws InterruptedException {
15+
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "/Users/ssoza1/Documents/chrome-web-driver/chromedriver");
16+
WebDriver webDriver = new ChromeDriver();
17+
webDriver.get("https://onlyfullstack.blogspot.com/2020/03/best-demo-website-to-practice-selenium.html");
18+
19+
webDriver.manage().window().maximize();
20+
JavascriptExecutor js = (JavascriptExecutor) webDriver;
21+
js.executeScript("window.scrollBy(0,2200)");
22+
23+
//selectDropDownValue(webDriver);
24+
getAllDropDownValues(webDriver);
25+
webDriver.close();
26+
}
27+
28+
private static void getAllDropDownValues(WebDriver webDriver) throws InterruptedException {
29+
WebElement countryDropDownElement = webDriver.findElement(By.name("Country"));
30+
Select countryDropDown = new Select(countryDropDownElement);
31+
32+
List<WebElement> dropDownList = countryDropDown.getOptions();
33+
34+
System.out.println("DropDown values - ");
35+
for(WebElement dropDown : dropDownList) {
36+
System.out.println(dropDown.getText());
37+
}
38+
}
39+
40+
private static void selectDropDownValue(WebDriver webDriver) throws InterruptedException {
41+
WebElement countryDropDownElement = webDriver.findElement(By.name("Country"));
42+
Select countryDropDown = new Select(countryDropDownElement);
43+
44+
countryDropDown.selectByVisibleText("India");
45+
Thread.sleep(1000);
46+
47+
countryDropDown.selectByValue("2");
48+
Thread.sleep(1000);
49+
50+
countryDropDown.selectByIndex(3);
51+
Thread.sleep(1000);
52+
}
53+
}

0 commit comments

Comments
 (0)