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

问题描述 投票:-2回答:2

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

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

javascript phantomjs
2个回答
0
投票

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

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

安装:

  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添加到项目中。

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

0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.