Last active
August 29, 2015 14:15
-
-
Save prashanth-sams/943a61a8a83e2f657d69 to your computer and use it in GitHub Desktop.
PhantomJS + Selenium2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pack; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.testng.annotations.AfterTest; | |
import org.testng.annotations.BeforeTest; | |
import org.testng.annotations.Test; | |
import org.openqa.selenium.phantomjs.PhantomJSDriver; | |
import org.openqa.selenium.phantomjs.PhantomJSDriverService; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
public class naukri { | |
private WebDriver driver; | |
private String baseUrl; | |
@BeforeTest | |
public void setUp() throws Exception { | |
// DesiredCapabilities caps = new DesiredCapabilities(); | |
// caps.setJavascriptEnabled(true); // not really needed: JS enabled by default | |
// caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Test\\phantomjs.exe"); | |
// driver = new PhantomJSDriver(caps); | |
System.setProperty("phantomjs.binary.path", "C:\\Test\\phantomjs.exe"); | |
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); | |
capabilities.setJavascriptEnabled(true); | |
driver = new PhantomJSDriver(capabilities); | |
baseUrl = "https://login.naukri.com"; | |
} | |
@Test | |
public void Login() throws InterruptedException { | |
driver.get(baseUrl + "/"); | |
System.out.println(driver.getTitle()); | |
driver.findElement(By.xpath("//form[@id='logFormI']//input[@id='emailTxt']")).sendKeys("[email protected]"); | |
System.out.println("username entered"); | |
driver.findElement(By.id("pwd1")).sendKeys("xxxxxx"); | |
System.out.println("password entered"); | |
driver.findElement(By.name("Login")).click(); | |
System.out.println("login done"); | |
System.out.println("My current title is " + driver.getTitle()); | |
} | |
@AfterTest | |
public void tearDown() throws Exception { | |
driver.close(); | |
driver.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment