forked from ketanvj/firstgitproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserCommand.java
More file actions
155 lines (128 loc) · 4.93 KB
/
BrowserCommand.java
File metadata and controls
155 lines (128 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package log4j;
import org.testng.annotations.Test;
//import modularNDDT.log4j.LogTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
// new comment added
public class BrowserCommand {
WebDriver driver;
Logger log;//Log4j
@BeforeMethod
public void beforeMethod() {
System.setProperty("webdriver.gecko.driver", "test\\resources\\geckodriver64bit.exe");
System.setProperty("webdriver.chrome.driver", "test\\resources\\chromedriver.exe");
// driver = new FirefoxDriver();
driver = new ChromeDriver();
DOMConfigurator.configure("log4j-alternate.xml");
//DOMConfigurator.configure("test/resources/log4j/log4j-alternate.xml");
log = Logger.getLogger(BrowserCommand.class.getName());
}
@Test (description = "Browser Commands")
public void f() throws InterruptedException {
driver.get("http://selenium-examples.nichethyself.com");
log.info("Opening Url");
driver.manage().window().maximize();
log.trace("Maximized window");
driver.get("http://www.google.com");
log.debug("Going to google.com");
System.out.println("Current Url is - " + driver.getCurrentUrl());
driver.findElement(By.name("q")).sendKeys("Selenium");
try {
Thread.sleep(3000);
throw new InterruptedException();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.fatal("Code is in a place where it is not supposed to be.");
}
driver.navigate().refresh();
log.error("This is after refresh.");
Thread.sleep(3000);
driver.navigate().back();
log.fatal("This is after back.");
Thread.sleep(3000);
driver.navigate().forward();
Thread.sleep(3000);
driver.navigate().to("http://www.yahoomail.com");
// System.out.println(driver.getPageSource());
}
// @Test
public void loginToPortal() throws InterruptedException {
driver.get("http://selenium-examples.nichethyself.com");
driver.findElement(By.name("username")).sendKeys("stc123");
driver.findElement(By.name("password")).sendKeys("12345");
Thread.sleep(3000);
driver.findElement(By.name("username")).clear();
Thread.sleep(3000);
driver.findElement(By.name("username")).sendKeys("stc123");
// WebElement submitButton = driver.findElement(By.xpath("//form[@name='loginform']/button[text()='Submit']"));
System.out.println(driver.findElement(By.name("username")).getAttribute("value"));
System.out.println(driver.findElement(By.name("password")).getAttribute("value"));
driver.findElement(By.name("loginform")).findElement(By.tagName("button")).click();
//submitButton.click();
//driver.findElement(By.cssSelector("form[name='loginform']>button")).click();
}
// @Test
public void handleVariousElements() throws InterruptedException {
driver.get("http://the-internet.herokuapp.com");
driver.findElement(By.linkText("Checkboxes")).click();
WebElement secondCheckbox = driver.findElement(By.xpath("//form/input[2]"));
if (!secondCheckbox.isSelected())
secondCheckbox.click();
WebElement firstCheckbox = driver.findElement(By.xpath("//form/input[1]"));
if (!firstCheckbox.isSelected())
firstCheckbox.click();
if (secondCheckbox.isSelected())
secondCheckbox.click();
Thread.sleep(4000);
}
// @Test
public void learnRadioButton() throws InterruptedException {
driver.get("http://cookbook.seleniumacademy.com/Config.html");
driver.findElement(By.xpath("//input[@value='Petrol']")).click();
driver.findElement(By.xpath("//input[@value='Diesel']")).click();
Thread.sleep(3000);
WebElement ledHeadLamp = driver.findElement(By.name("ledheadlamp"));
if (ledHeadLamp.isEnabled()){
if (!ledHeadLamp.isSelected()){
ledHeadLamp.click();
}
} else
System.out.println("Checkbox LED is disabled.");
Thread.sleep(3000);
}
// @Test
public void testForVisibility() throws InterruptedException {
driver.get("http://the-internet.herokuapp.com/dynamic_loading/1");
// driver.findElement(By.linkText("Dynamic Loading")).click();
WebElement finish = driver.findElement(By.xpath("//div[@id='finish']/h4"));
if (finish.isDisplayed())
System.out.println(finish.getText());
else
System.out.println("Finish is not visible.");
driver.findElement(By.xpath("//div[@id='start']/button")).click();
Thread.sleep(6000);
if (finish.isDisplayed())
System.out.println(finish.getText());
else
System.out.println("Finish is not visible.");
}
@AfterMethod
public void afterMethod() {
}
@BeforeClass
public void beforeClass() {
}
@AfterClass
public void afterClass() {
}
}