Ad

Do We Need To Learn Javascript First Before Writing Code In Phantomjs?

- 1 answer

I'm going to write phantomjs script to use it in automation testing. Do I need to learn javascript first?

source: http://phantomjs.org/screen-capture.html

Ad

Answer

No, it's not required to learn JavaScript; you can continue coding in Java while using PhantomJS. For a working example with Java and PhantomJS, please have a look at this.

  1. In order to use PhantomJS with Seleniun, one has to use GhostDriver. GhostDriver is a implementation of Webdriver Wire protocol in simple JS for PhantomJS.
  2. The latest release of PhatomJS has integrated GhostDriver and there is no need to separately install it.

Installation:

  1. You need Eclipse with Selenium installed
  2. Download from here http://phantomjs.org/download.html
  3. Extract the downloaded folder to Program Files
  4. Download the PhantomJS Driver from http://mvnrepository.com/artifact/com.github.detro.ghostdriver/phantomjsdriver/1.1.0.
  5. Add the jar to your project.

A Java working example

public static void main(String[] args) {
File file = new File("C:/Program Files/phantomjs-2.0.0-windows/bin/phantomjs.exe");             
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());        
WebDriver driver = new PhantomJSDriver();   
driver.get("http://www.google.com");         
WebElement element = driver.findElement(By.name("q"));  
element.sendKeys("Guru99");                 
element.submit();                   
System.out.println("Page title is: " + driver.getTitle());      
driver.quit();          
           }    
Ad
source: stackoverflow.com
Ad