Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Openshift/Ruby上的Selenium Webdriver和PhantomJS-错误:“找不到PhantomJS可执行文件”_Ruby_Selenium Webdriver_Phantomjs_Openshift_Watir - Fatal编程技术网

Openshift/Ruby上的Selenium Webdriver和PhantomJS-错误:“找不到PhantomJS可执行文件”

Openshift/Ruby上的Selenium Webdriver和PhantomJS-错误:“找不到PhantomJS可执行文件”,ruby,selenium-webdriver,phantomjs,openshift,watir,Ruby,Selenium Webdriver,Phantomjs,Openshift,Watir,我正在使用Selenium webdriver、watir、PhantomJS headless browser等在Openshift平台自由层上进行web测试项目,遇到了一个无法找到解决方案的错误 背景:我对Ruby、Linux、web应用程序测试等相当陌生。我曾致力于安装Openshift免费层RubyGear,并在这方面取得了成功。我可以通过Filezilla将SFTP转换成gear,可以通过Putty将SSH转换成应用程序,并且有一个在GIT上有OpenShift工具的Windows 1

我正在使用Selenium webdriver、watir、PhantomJS headless browser等在Openshift平台自由层上进行web测试项目,遇到了一个无法找到解决方案的错误

背景:我对Ruby、Linux、web应用程序测试等相当陌生。我曾致力于安装Openshift免费层RubyGear,并在这方面取得了成功。我可以通过Filezilla将SFTP转换成gear,可以通过Putty将SSH转换成应用程序,并且有一个在GIT上有OpenShift工具的Windows 10桌面,等等。我已经安装了Selenium Webdriver和PhantomJS

我正试图在Ruby指南中完成下面的Web应用程序测试,以便在Openshift平台上实现下面的代码

指南:

我试图实现的代码:

require "selenium-webdriver"
browser = Selenium::WebDriver.for :phantomjs
browser.get "http://google.com"
p browser.current_url
p browser.title
browser.find_element(name: "q").send_keys "watir"
browser.find_element(name: "q").clear
p browser.find_element(name: "q").attribute(:name)
p browser.find_element(name: "q").attribute(:class)
p browser.find_element(name: "q").attribute(:type)
p browser.find_element(name: "q").
attribute(:autocomplete)
browser.save_screenshot "phantomjs.png"
p browser.page_source
p browser.find_element(name: "q").
attribute(:outerHTML)
browser.quit
当我按照以下命令的指示运行此代码时: ruby headless_phantomjs.rb

我得到以下错误:

/var/lib/openshift/MYAPPID/.gem/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/phantomjs/service.rb:39:in `executable_path': Unable to find phantomjs executable. (Selenium::WebDriver::Error::WebDriverError)
    from /var/lib/openshift/55e5f36b89f5cf105a000102/.gem/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/phantomjs/service.rb:47:in `default_service'
    from /var/lib/openshift/55e5f36b89f5cf105a000102/.gem/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/phantomjs/bridge.rb:38:in `initialize'
    from /var/lib/openshift/55e5f36b89f5cf105a000102/.gem/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/common/driver.rb:64:in `new'
    from /var/lib/openshift/55e5f36b89f5cf105a000102/.gem/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/common/driver.rb:64:in `for'
    from /var/lib/openshift/55e5f36b89f5cf105a000102/.gem/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver.rb:86:in `for'
    from headless_phantomjs.rb:7:in `<main>'
在Ruby的IRB中,我可以使用Path命令查找路径: /opt/rh/ruby193/root/usr/bin/但无法访问或编辑它

我已验证phantomJS可执行文件位于我的应用程序下的以下目录中: /app root/data/phantomjs/bin

问:我如何克服这个错误,让SeleniumWebDriver看到PhantomJS的路径


感谢帮助….

当PhantomJS可执行文件不在您的路径中时,您将需要使用path=方法告诉Selenium WebDriver在何处查找:

require "selenium-webdriver"

Selenium::WebDriver::PhantomJS.path = '/app-root/data/phantomjs/bin/phantomjs.exe'

browser = Selenium::WebDriver.for :phantomjs

此问题是由于未能找到phantomjs造成的。 因此,您需要首先安装它并添加路径

例如,在Windows中,test.rb

require 'selenium-webdriver'
require 'phantomjs'

Selenium::WebDriver::PhantomJS.path = 'C:\\Users\\name\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe'
driver = Selenium::WebDriver.for :phantomjs
driver.navigate.to "http://google.com"
puts driver.title  
driver.quit

谢谢你的留言。我尝试了这一点,但得到了以下错误:`assert_file':不是一个文件:/approt/data/phantomjs/bin/phantomjs。我尝试了phantomjs和phantomjs.exe,但都没有成功。一定与Openshift平台有关?对不起,我没有Openshift的经验,所以我不知道他们的文件结构是如何工作的。您是否尝试提供文件的完整路径?