forked from CourseRepository/SeleniumWebdriverWithJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNg.java
More file actions
75 lines (57 loc) · 2.05 KB
/
TestNg.java
File metadata and controls
75 lines (57 loc) · 2.05 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
package testcase;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author - rahul.rathore
* @date - 16-Nov-2014
* @project - Webdriver
* @package - testcase
* @file name - TestNg.java
*/
public class TestNg {
private static WebDriver driver = null;
@BeforeClass
public static void startWebdriver() {
ProfilesIni prof = new ProfilesIni();
FirefoxProfile profile = prof.getProfile("default");
profile.setPreference("browser.startup.homepage", "mail.google.com");
profile.setPreference("browser.download.defaultFolder", "C:\\");
profile.setPreference("browser.download.panel.shown", true);
profile.setPreference("javascript.enabled", true);
//driver = new FirefoxDriver(profile);
driver = new HtmlUnitDriver();
// ChromeOptions opt = new ChromeOptions();
//driver = new ChromeDriver(opt);
/*System.setProperty("webdriver.chrome.driver", "C:\\Junit\\selenium-2.41.0\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();*/
}
@Test
public void testCase() {
driver.get("http://www.google.com");
System.out.println("Title : " + driver.getTitle());
System.out.println("Url : " + driver.getCurrentUrl());
Assert.assertEquals(driver.getTitle(), "Google1");
try {
Thread.sleep(3000);
} catch (Exception e) { }
driver.get("https://in.yahoo.com/");
System.out.println("Title : " + driver.getTitle());
System.out.println("Url : " + driver.getCurrentUrl());
Assert.assertEquals(driver.getTitle(), "Yahoo India");
}
@AfterClass(alwaysRun=true)
public static void stopWebdriver() {
// this will close all the browser and stop the wbedriver gracefully
if(driver != null){
driver.close(); //this will close the browser which is currently in focus
driver.quit();
driver = null;
}
}
}