Skip to content

Commit fcb75fe

Browse files
added new calsses
1 parent fc9251d commit fcb75fe

16 files changed

+450
-4
lines changed

seleniumWebdriver/src/test/java/advanced/MyClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Created by dell on 11/5/17.
55
*/
6-
public class MyClass {
6+
public class MyClass{
77
public static void main(String[] args) {
88
WebDriver driver;
99
driver = new FirefoxDriver();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package basepkg;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.testng.annotations.BeforeClass;
5+
import org.testng.annotations.BeforeMethod;
6+
import org.testng.annotations.BeforeSuite;
7+
import utilities.Util;
8+
9+
/**
10+
* Created by jitendra on 29/5/17.
11+
*/
12+
public class BaseClass {
13+
14+
public WebDriver driver;
15+
private Util utils;
16+
17+
@BeforeSuite
18+
public void initUtils(){
19+
this.utils = new Util();
20+
}
21+
22+
@BeforeClass
23+
public void init() {
24+
driver = utils.getDriver(utils.getBrowser());
25+
}
26+
27+
@BeforeMethod
28+
public void maximize(){driver.manage().window().maximize();}
29+
30+
/*@AfterClass
31+
public void tearDown(){driver.close();driver.quit();}*/
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.JavascriptExecutor;
6+
import org.openqa.selenium.WebElement;
7+
import org.testng.annotations.Test;
8+
9+
/**
10+
* Created by dell on 4/6/17.
11+
*/
12+
public class AdvancedXpath extends BaseClass {
13+
14+
@Test
15+
public void advancedXpath() throws InterruptedException {
16+
driver.get("https://dhtmlx.com/docs/products/dhtmlxGrid/");
17+
WebElement element = driver.findElement(By.id("layoutObj"));
18+
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();",element);
19+
Thread.sleep(2000);
20+
driver.findElement(By.xpath("//td[text()='Alia Hilpert']//preceding-sibling::td/img"));
21+
System.out.println(driver.findElement(By.xpath("//td[text()='Alia Hilpert']//preceding-sibling::td/img")).isSelected()) ;
22+
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.testng.annotations.Test;
5+
6+
/**
7+
* Created by dell on 4/6/17.
8+
*/
9+
public class BasicActions extends BaseClass {
10+
11+
@Test
12+
public void basicActions() throws InterruptedException {
13+
driver.get("https://www.google.co.in/");
14+
System.out.println("Title : "+driver.getTitle());
15+
System.out.println("Current url :"+driver.getCurrentUrl());
16+
Thread.sleep(2000);
17+
driver.navigate().to("https://mail.google.com");
18+
System.out.println("Title : "+driver.getTitle());
19+
System.out.println("Current url :"+driver.getCurrentUrl());
20+
Thread.sleep(2000);
21+
driver.navigate().back();
22+
System.out.println("Title : "+driver.getTitle());
23+
System.out.println("Current url :"+driver.getCurrentUrl());
24+
Thread.sleep(2000);
25+
driver.navigate().forward();
26+
System.out.println("Title : "+driver.getTitle());
27+
System.out.println("Current url :"+driver.getCurrentUrl());
28+
Thread.sleep(2000);
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.testng.annotations.AfterClass;
5+
import org.testng.annotations.BeforeMethod;
6+
import org.testng.annotations.Test;
7+
8+
import java.util.concurrent.TimeUnit;
9+
10+
/**
11+
* Created by jitendra on 9/5/17.
12+
*/
13+
public class ChromeDriverDemo extends BaseClass {
14+
15+
@BeforeMethod
16+
public void before() {
17+
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
18+
}
19+
20+
@Test
21+
public void chrome(){
22+
driver.get("http://www.google.co.in");
23+
}
24+
25+
@AfterClass
26+
public void close(){
27+
driver.quit();
28+
}
29+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package basics;
2+
3+
import org.testng.annotations.BeforeMethod;
4+
import org.testng.annotations.BeforeTest;
5+
import org.testng.annotations.Test;
6+
7+
/**
8+
* Created by dell on 11/5/17.
9+
*/
10+
public class Demo {
11+
12+
@BeforeTest
13+
public void beforeTest(){
14+
System.out.println("before test");
15+
}
16+
17+
@BeforeMethod
18+
public void beforeMethod(){
19+
System.out.println("before method");
20+
}
21+
22+
@Test
23+
public void a(){
24+
System.out.println("in a()");
25+
}
26+
27+
@Test
28+
public void b(){
29+
System.out.println("in b()");
30+
}
31+
32+
@Test
33+
public void c(){
34+
System.out.println("in c()");
35+
}
36+
37+
@Test
38+
public void d(){
39+
System.out.println("in d()");
40+
}
41+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package basics;
2+
3+
import org.openqa.selenium.Platform;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.firefox.FirefoxDriver;
6+
import org.openqa.selenium.ie.InternetExplorerDriver;
7+
import org.openqa.selenium.remote.DesiredCapabilities;
8+
import org.testng.annotations.AfterClass;
9+
import org.testng.annotations.BeforeClass;
10+
import org.testng.annotations.Test;
11+
12+
/**
13+
* Created by jitendra on 9/5/17.
14+
*/
15+
public class DesiredCapabilitiesDemo {
16+
17+
WebDriver driver;
18+
DesiredCapabilities caps = null;
19+
20+
@BeforeClass
21+
public void init(){
22+
/*System.setProperty("webdriver.gecko.driver","/home/jitendra/Documents/webdriver/geckodriver");
23+
caps = DesiredCapabilities.firefox();
24+
caps.setBrowserName("firefox");
25+
caps.setPlatform(Platform.LINUX);
26+
caps.setVersion("47");
27+
driver = new FirefoxDriver(caps);*/
28+
29+
DesiredCapabilities cp = new DesiredCapabilities();
30+
cp.setCapability(InternetExplorerDriver.NATIVE_EVENTS,false);
31+
32+
}
33+
34+
@Test
35+
public void firefox(){
36+
driver.get("http://www.google.com");
37+
}
38+
39+
@AfterClass
40+
public void close(){
41+
driver.quit();
42+
}
43+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.WebElement;
6+
import org.openqa.selenium.support.ui.Select;
7+
import org.testng.annotations.Test;
8+
9+
import java.util.List;
10+
11+
/**
12+
* Created by dell on 4/6/17.
13+
*/
14+
public class DropDownSelect extends BaseClass {
15+
16+
@Test
17+
public void dropDownSelect() throws InterruptedException {
18+
driver.get("https://www.expedia.co.in/");
19+
WebElement select = driver.findElement(By.id("hotel-rooms"));
20+
Select sel = new Select(select);
21+
22+
List<WebElement> options = sel.getOptions();
23+
24+
for (int i=0;i<options.size();i++){
25+
System.out.println(options.get(i).getAttribute("value"));
26+
Thread.sleep(2000);
27+
}
28+
}
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.WebElement;
6+
import org.testng.annotations.Test;
7+
8+
/**
9+
* Created by dell on 4/6/17.
10+
*/
11+
public class ElementState extends BaseClass{
12+
13+
@Test
14+
public void elementState() throws InterruptedException {
15+
driver.get("https://www.google.co.in/");
16+
//WebElement element = driver.findElement(By.id("gs_htif0"));
17+
/***
18+
* Below line will throw an Exception :
19+
* org.openqa.selenium.InvalidElementStateException: invalid element state
20+
* It means either the element is disabled. If you see this element in the DOM you will find "disable="" "
21+
* attribute. It means this element is not available for interaction or disabled.Hence getting above EXCEPTION
22+
*/
23+
WebElement element = driver.findElement(By.id("lst-ib"));
24+
//element.sendKeys("letskodeit");
25+
System.out.println("element enabled ?? --> "+element.isEnabled());
26+
27+
WebElement element1 = driver.findElement(By.id("gs_htif0"));
28+
System.out.println("element1 enabled ?? --> "+element1.isEnabled());
29+
30+
WebElement element2 = driver.findElement(By.id("gs_sc0"));
31+
System.out.println("element2 enabled ?? --> "+element2.isEnabled());
32+
33+
}
34+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.testng.annotations.Test;
6+
7+
/**
8+
* Created by dell on 3/6/17.
9+
*/
10+
public class FindByCssSelector extends BaseClass {
11+
12+
@Test
13+
public void cssSelector(){
14+
driver.get("https://letskodeit.teachable.com/p/practice");
15+
System.out.println(driver.findElement(By.cssSelector("fieldset>.table-display")).getAttribute("class"));
16+
}
17+
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.firefox.FirefoxDriver;
6+
import org.testng.annotations.BeforeMethod;
7+
import org.testng.annotations.Test;
8+
9+
/**
10+
* Created by dell on 12/5/17.
11+
*/
12+
public class FindByLinkText extends BaseClass {
13+
14+
@BeforeMethod
15+
public void before(){
16+
driver = new FirefoxDriver();
17+
driver.manage().window().maximize();
18+
}
19+
20+
/* @Test
21+
public void idXpath(){
22+
driver.get("https://www.google.co.in/");
23+
driver.findElement(By.linkText("Gmail")).click();
24+
}*/
25+
26+
@Test void findByPartialLinkText(){
27+
driver.get("https://www.facebook.com/");
28+
driver.findElement(By.partialLinkText("account?")).click();
29+
}
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package basics;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.WebElement;
6+
import org.openqa.selenium.firefox.FirefoxDriver;
7+
import org.testng.annotations.BeforeClass;
8+
import org.testng.annotations.Test;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
/**
14+
* Created by dell on 12/5/17.
15+
*/
16+
public class FindByTagName {
17+
18+
WebDriver driver;
19+
20+
@BeforeClass
21+
public void init(){
22+
System.setProperty("webdriver.gecko.driver","src/test/drivers/geckodriver");
23+
driver = new FirefoxDriver();
24+
driver.manage().window().maximize();
25+
}
26+
27+
@Test
28+
public void findByTagName(){
29+
driver.get("https://demostore.x-cart.com/");
30+
List<WebElement> lst = driver.findElements(By.tagName("li"));
31+
System.out.println("***********"+lst.size()+"********************** ");
32+
List<String> str = new ArrayList<String>();
33+
34+
for (WebElement element: lst
35+
) {
36+
str.add(element.findElement(By.tagName("a")).findElement(By.tagName("span")).getText());
37+
38+
}
39+
40+
System.out.println("list :" +str.toString());
41+
}
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.testng.annotations.AfterClass;
5+
import org.testng.annotations.Test;
6+
7+
/**
8+
* Created by jitendra on 9/5/17.
9+
*/
10+
public class FirefoxDriverDemo extends BaseClass {
11+
12+
@Test
13+
public void firefox(){
14+
driver.get("http://www.google.com");
15+
}
16+
17+
@AfterClass
18+
public void close(){
19+
driver.quit();
20+
}
21+
}

0 commit comments

Comments
 (0)