在phantomjs中编写代码之前,我们是否需要先学习javascript?

时间:2016-06-01 10:45:40

标签: javascript phantomjs

我将编写phantomjs脚本以在自动化测试中使用它。我需要先学习javascript吗?

来源:http://phantomjs.org/screen-capture.html

2 个答案:

答案 0 :(得分:0)

不,它不需要学习JavaScript;您可以在使用PhantomJS时继续使用Java进行编码。有关Java和PhantomJS的工作示例,请查看this

  1. 为了将PhantomJS与Seleniun一起使用,必须使用GhostDriver。 GhostDriver是用于PhantomJS的简单JS中的Webdriver Wire协议的实现。
  2. PhatomJS的最新版本集成了GhostDriver,无需单独安装。
  3. 安装:

    1. 您需要安装了Selenium的Eclipse
    2. 从这里下载http://phantomjs.org/download.html
    3. 将下载的文件夹解压缩到Program Files
    4. http://mvnrepository.com/artifact/com.github.detro.ghostdriver/phantomjsdriver/1.1.0下载PhantomJS驱动程序。
    5. 将jar添加到项目中。
    6. Java工作示例

      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();          
                 }    
      

答案 1 :(得分:0)

是的,您需要学习JavaScript才能编写PhantomJS 脚本。您还可以学习CoffeeScript以编写PhantomJS 1.x 脚本

如果您不想编写PhantomJS脚本,那么您可以使用阳光下的任何语言来指示PhantomJS通过Selenium和WebDriver线协议执行某些操作。

相关问题