配置PhantomjsDriver以运行selenium测试用例

时间:2013-07-23 10:34:33

标签: java selenium selenium-webdriver phantomjs ghostdriver

对于selenium webdriver中的这个PhantomjsDriver的新手。我需要在没有GUI的情况下在服务器中运行我的selenium脚本。任何人都可以告诉我如何实现这一目标。我需要从头开始如何配置Phantomjs驱动程序,在服务器和rest中使用.Below是我运行GUI的selenium代码,现在我必须在没有GUI的服务器中运行这些情况。我必须做哪些修改才能完成上述任务。

  public static void main(String[] args) throws IOException{

        login =args[0];
        user = args[1];
        pwd = args[2];
        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG testng = new TestNG();
        testng.setOutputDirectory(args[3]);
        testng.setTestClasses(new Class[] {

            CreateMultiRecordTest.class, UpdateMultiRecordTest.class,
            DeleteMultiRecordTest.class

            });
        testng.addListener(tla);
        testng.run();

2 个答案:

答案 0 :(得分:1)

最后几周后,我找到了一个为我的框架配置PhantomJs的解决方案。这就是解决方案。

DesiredCapabilities cap = new DesiredCapabilities();
java.io.File f = new java.io.File("");
String path = f.getAbsolutePath()+"\\ghostdriver-master\\src\\main.js";
cap.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY,path);
driver = new PhantomJSDriver(cap); 

答案 1 :(得分:0)

这对我有用:

DesiredCapabilities dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability("takesScreenshot", false);
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"C:\\phantomjs-1.9.7-windows\\phantomjs.exe");
PhantomJSDriver driver = new PhantomJSDriver(dCaps);

...

相关问题