Tag: phantomjs

使用java运行ghostdriver会出错

我正在使用远程ubuntu机器来运行我的测试用例。 我有jenkins配置github。 我可以使用我的windows7机器使用putty.exe访问这台机器。 我想使用phantomjs运行无头测试用例(调度作业),即当我的Windows机器关闭时,测试将在远程ubuntu机器上运行,该机器始终打开。 现在的问题是,当我现在构建它会给出错误: Caused by org.openqa.selenium.HasInputDevices … … 我的setup()方法和pom看起来像: 建立() DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,”/usr/bin/phantomjs”); driver = new PhantomJSDriver(caps); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(Production); 的pom.xml com.github.detro.ghostdriver phantomjsdriver 1.0.3 编辑:已通过添加selenium 2.34.0 jar依赖项解决了HasInputDevices的问题 但是在运行上面测试时仍然会出错: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: […]

如何在Java程序中包含JavaScript文件

我有使用phantomjs创建的脚本文件 var webPage = require(‘webpage’); var page = webPage.create(); page.open(URL, function (status) { var content = page.content; console.log(‘Content: ‘ + content); phantom.exit(); }); 现在我想在Java程序中使用这个脚本,但我不能。 我在我的项目中这样做 ScriptEngineManager s = new ScriptEngineManager(); ScriptEngine se = s.getEngineByName(“JavaScript”); se.eval(new FileReader(“myScript.js”)); 但是这就是结果 Exception in thread “main” javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: “require” is not defined. (#1) in at line number 1 at […]

如何修复NoClassDefFoundError:CircularOutputStream错误?

我只是为Selenium WebDriver(又名Selenium 2)为无头测试创建了一个简单的maven项目。 我在pom.xml中添加了PhantomJS驱动程序依赖项和其他依赖项: com.github.detro phantomjsdriver 1.2.0 但它得到了错误: java.lang.NoClassDefFoundError: org/openqa/selenium/io/CircularOutputStream at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:60) at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:56) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120) at jp.co.skygate.home.HomePageLogin.setUp(HomePageLogin.java:108) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at 只是从pom.xml中删除PhantomJS依赖项解决了问题并且执行正常。 有人能帮我找到问题吗? 提前致谢。

Java PhantomJSDriver禁用控制台中的所有日志

我正在使用Selenium开发一个小型控制台应用程序,我需要关闭它的所有日志。 我试过了phantomJSDriver.setLogLevel(Level.OFF); 但它不起作用。 我需要帮助。 如何禁用使用Selenium和Phantomjs(GhostDriver)的控制台应用程序中的所有日志?

Selenium GhostDriver / PhantomJS:使用sendKeys()/ Javascript无法上传文件

我正在使用PhantomJSDriver / GhostDriver运行无头脚本,并尝试在编写电子邮件时上传gmail上的文件。 工具:Selenium与PhantomJS / GhostDriver。 html代码如下: Click the “Browse” button to select a file. Click “Done” when you’re finished. 1. 2. 3. 4. 到目前为止,我已经尝试了以下两种方法来上传文件,但它们都没有工作: 使用Javascript: wait.until(ExpectedConditions.presenceOfElementLocated(By.name(“file1”))); WebElement btnChoseFile = driver.findElement(By.name(“file1”)); System.out.println(btnChoseFile.isEnabled()); File file = new File(“attachments/Alan Morales.doc”); String script = “document.getElementsByName(\”file1\”)[0].value='” + file.getAbsolutePath() + “‘;”; jsexec.executeScript(script); System.out.println(“File attached…..”); 收到的例外情况: Exception in thread “main” org.openqa.selenium.ElementNotVisibleException: […]

PhantomJS截图为Spring MVC,Tomcat和iText使用的网站div

我已经了解了PhantomJS和CasperJS的强大function,以获取网站截图。 文章“ 使用Casper响应屏幕截图 ”非常有助于了解这两种技术的基础知识以及屏幕截图function。 接下来是如何使用此技术与Spring MVC应用程序集成。 到目前为止,我已尝试使用“ 使用PhantomJS,GhostDriver,Selenium Hub进行屏幕捕获 ”的代码,并将其与“ Junit中的Remote PhantomJS驱动程序 ”中提供的答案相结合。 发生的事情是,每次运行程序时,我都会遇到ClassNotFoundError并且我一直提供缺少的JAR文件。 我最终在Spring应用程序中下载并提供了九个新的JAR文件: phantomjsdriver-1.0.4.jar selenium-java-2.39.0.jar及其源文件 asm-all-3.3.1.jar cglib-3.1.jar commons-exec-1.2.jar guava-16.0.1.jar httpclient-4.3.2.jar httpcore-4.3.2.jar json-20140107.jar 直到下面的错误显示 SEVERE: Servlet.service() for servlet [spring] in context with path [/my_spring_app] threw exception [Handler processing failed; nested exception is java.lang.IncompatibleClassChangeError: class net.sf.cglib.core.DebuggingClassWriter has interface org.objectweb.asm.ClassVisitor as super class] with root cause […]

WebDriver PhantomJS无法找到元素,但可以在Firefox中正常工作

我已经把头撞到了墙上很长一段时间所以我想我会问“专家”为什么下面的代码不能用PhantomJS工作(输入密码),但用Firefox工作得很好。 最令人不安的是,一个字段条目(用户名)成功,但第二个条目根本不起作用。 页面加载很好,我已经包含测试代码,以validation其他组件加载得很好。 见下面的代码: import java.io.File; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.phantomjs.PhantomJSDriver; public class login { public static void main(String[] args) { WebDriver driver; Boolean verbose = false; //Change to true to test it with firefox String phantomPath = “../phantomjs-1.9.8-linux-i686/bin/phantomjs”; String url = “https://www.britishairways.com/travel/redeem/execclub/_gf/en_us”; if (verbose) { driver = new FirefoxDriver(); } else{ File file […]

在Selenium Grid中注册PhantomJS节点时出错

我有以下问题 我成功推出了Selenium Grid hub: java -jar selenium-server-standalone-2.53.0.jar -role hub 之后我尝试使用以下命令启动PhantomJS节点: phantomjs –webdriver=8090 –webdriver-selenium-grid-hub=http://localhost:4444 但得到了错误: [INFO – 2016-03-25T13:56:28.397Z] GhostDriver – Main – 在端口8090上运行[INFO – 2016-03-25T13:56:28.397Z] GhostDriver – Main – 注册到Selenium HUB’http :// localhost :4444 ‘版本:使用’127.0.0.1:8090’与org.openqa.grid.selenium.proxy.DefaultRemoteProxy作为远程代理。 [ERROR – 2016-03-25T13:56:28.400Z] GhostDriver – main.fail – {“line”:97,“sourceURL”:“phantomjs://platform/hub_register.js”,“stack”:“register @” phantomjs://platform/hub_register.js:97:79 \ nglobal code @ phantomjs://code/main.js:78:37“} phantomjs://platform/console++.js:263错误 标准节点工作正常,但PhantomJS错误。 我做错了什么?

PhantomJSDriver适用于HTTP,但不适用于HTTPS

public class FooTest { WebDriver driver; @Before public void beforeTest() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setJavascriptEnabled(true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); driver = new PhantomJSDriver(capabilities); driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); } @Test public void test() { driver.get(“http://www.example.com”); WebElement e = driver.findElement(By.tagName(“h1”)); System.out.println(“TEXT” + e.getAttribute(“innerHTML”)); assertNotNull(e); driver.quit(); } } 嗨,我只是想在www.example.com上尝试获取“示例域”的h1标签。 该代码适用于http://www.example.com,但不适用于https://www.exmaple.com 。 我该如何解决这个问题? 谢谢

使用GhostDriver时如何设置屏幕/窗口大小

我在基于Java的项目中使用GhostDriver作为WebDriver实现。 我想拍摄页面的快照。 默认页面大小有点笨拙,所以我想控制快照的页面大小。 但是,我找不到谷歌的任何例子。 那么,有人可以告诉我怎么样? 非常感谢你。