undefined method `delete' for nil:NilClass (NoMethodError) capybara, selenium-webdriver and firefox in arch linux - selenium-webdriver

I am writing because I am having troubles running a test using cucumber and capybara. I am using capybara framework with selenium-driver. This is my env.rb
require 'capybara/cucumber'
Capybara.default_driver = :selenium
This is my steps.rb file
Given (/^I am on Youtube$/) do
visit "http://www.youtube.com"
end
When (/^I fill in "([^"]*)" with "([^"]*)"$/) do |field, value|
fill_in(field, :with => value)
end
When (/^I press "([^"]*)"$/) do |button|
click_button(button)
end
Then (/^I should see "([^"]*)"$/) do |text|
page.should have_content(text)
end
And this the output that i obtain. I tried to execute the same file with cucumber in a Mac system and it works. I am using Arch Linux (antergos) with kernel version 4.10.6-1-ARCH #1 SMP PREEMPT
Feature: YouTube has a search function.
Scenario: Search for a term # features/youtube_search.feature:3
Given I am on Youtube # features/step_definitions/youtube_search_steps.rb:1
undefined method `delete' for nil:NilClass (NoMethodError)
./features/step_definitions/youtube_search_steps.rb:2:in `/^I am on Youtube$/'
features/youtube_search.feature:4:in `Given I am on Youtube'
When I fill in "search_query" with "text adventure" # features/step_definitions/youtube_search_steps.rb:5
And I press "search-btn" # features/step_definitions/youtube_search_steps.rb:9
Then I should see "GET LAMP: The Text Adventure Documentary" # features/step_definitions/youtube_search_steps.rb:13
Failing Scenarios:
cucumber features/youtube_search.feature:3 # Scenario: Search for a term
1 scenario (1 failed)
4 steps (1 failed, 3 skipped)
0m1.898s
NOTE: When I run the cucumber command, a new firefox window is opened, but I see the error mentioned in the terminal and test not continue.
Thank you all in advance.

I had this problem. It happens when the selenium-webdriver and Firefox versions don't match. As Firefox gets updated fairly often you will get this error from time to time. If you update your selenium-web it should fix the problem. It did for me.

Related

Going Headless in Selenium with Chrome using Python Executing, But Throwing Errors

Based off the answer here I am trying to get Chrome to run headless in my script.
The snippet of code below is inside of a function called login() that logs into our ERP system:
if headless == True:
options = Options()
options.headless = True
#Load webdriver
driver = webdriver.Chrome(options=options, executable_path=r'C:/Users/d.kelly/Desktop/Python/chromedriver_win32/chromedriver.exe')
if headless == False:
driver = webdriver.Chrome('C:/Users/d.kelly/Desktop/Python/chromedriver_win32/chromedriver.exe')
window_before_login = driver.window_handles[0]
### Removed Code Block that fills out login form and clicks 'Login' button ###
# Switch to new window ERP (PLEX) launches and close original blank one no longer needed.
window_before_login = driver.window_handles[0]
window_title = driver.title
driver.switch_to.window(window_before_login)
driver.close()
driver.switch_to.window(driver.window_handles[0])
When I call my function like so:
login(headless=False)
It throws no errors and my entire script executes just fine.
When I call my function like this:
def login(headless=True)
I get the following errors:
DevTools listening on ws://127.0.0.1:57567/devtools/browser/69f9e357-dccf-4e38-8d6b-78030462379a
[0204/072436.206:INFO:CONSOLE(6)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://test.plexonline.com/modules/systemadministration/login/index.aspx? (6)
[0204/072437.699:INFO:CONSOLE(6)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://test.plexonline.com/Modules/SystemAdministration/Login/Index.aspx (6)
[0204/072437.722:INFO:CONSOLE(1)] "Scripts may close only the windows that were opened by it.", source: (1)
[0204/072441.162:INFO:CONSOLE(751)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.", source: https://test.plexonline.com/Modules/scripts/ajax.js (751)
I am using Chrome Version 79.0.3945.130 (Official Build) (64-bit), Selenium 3.141.0, and Python 3.7.4.
Any ideas what I am doing wrong? Thank you!

xmlrpc.client.Fault when calling TestRun.update()

Kiwi version 6.0, tcms-api 5.0.
Given that 82 is a valid test run_id and 7 is a valid build_id for the test run's product in the Kiwi instance, run this Python snippet:
from tcms_api import TCMS
kiwi = TCMS()
kiwi.exec.TestRun.update(82, {'build' : 7})
Expect:
The test run's product build is updated from 1 (unspecified) to 7.
Result:
Exception has occurred: xmlrpc.client.Fault
<Fault -32603: "Internal error: 'status'">
There's no other call stack information, so I'm at a loss to further debug. I've tried updating a couple of different fields (manager and status) with the same result. I also get the same result if the value I'm trying to update is unknown/invalid.
Additional information: the equivalent call to TestCaseRun.update() API works. I.e., I can update the build information on a TestCaseRun instance.
#s-manke. This is a genuine bug. I've implemented a hot-fix here: https://github.com/kiwitcms/Kiwi/pull/553
so you can at least continue to use the API.
I am in the process of cutting a new version anyway so this hot-fix will go in. However the API will not process status or stop_date fields at the moment.

"TypeError: can't dup NilClass" in Capybara + selenium driver

I tried following code
crawler = Capybara::Session.new(:selenium)
crawler.visit "https://twitter.com" # Error this line!
with
gem:
capybara (= 2.2.0)
selenium-webdriver (3.3.0)
WebBrowser:
FireFoex53.0
OS:
Mac OSX
then got following Error
TypeError: can't dup NilClass
[stack trace]
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_capabilities.rb:101:in `dup'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_capabilities.rb:101:in `json_create'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:116:in `create_session'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:76:in `initialize'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/firefox/w3c_bridge.rb:45:in `initialize'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:52:in `new'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:52:in `for'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver.rb:87:in `for'",
gems/capybara-2.2.0/lib/capybara/selenium/driver.rb:13:in `browser'",
gems/capybara-2.2.0/lib/capybara/selenium/driver.rb:45:in `visit'",
gems/capybara-2.2.0/lib/capybara/session.rb:197:in `visit'"
url "https://twitter.com" is working when I manualy visit on this FireFox browser.
but capybara's visit method is does't work..
I ran into this error (TypeError: can't dup NilClass) when trying to use the selenium-webdriver gem as instructed:
require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox
As suggested by Thomas, updating the selenium-webdriver gem number from 3.3.x to 3.4.x resolves the issue.

Failing lein uberjar when reading database from configuration

I am writing a Ring / Compojure app with Clojure that fetches content for pages from database. To be able to create tests for how the content is displayed, I created prod and dev environments and when using dev environment, a mock database is used instead of the production database. I achieve this by reading the database from another file and giving it as a parameter to my routes. Here's a simplified version:
(defn www-routes [db]
(defroutes www-routes
(GET "/" [] ...)))
(def config (delay (load-file (.getFile (resource "config.clj")))))
(defn db []
(if (= "dev" (:database #(force config)))
'kipsu.db-mock
'kipsu.database))
(def app (routes (www-routes (db)))
The setup is largely taken from the example here, with the addition of setting the database as a parameter.
This setup works great with running the tests with the mock database and displaying real content on prod environment. Things run fine when I start a lein server locally, run tests or any of the functions in lein repl. My problem comes when I'd like to create an uberjar for deploying the changes on my server.
This is where I get a NullPointerException when compiling, starting from (db) function call inside the def app. I've tried debugging with poor success and am not even 100% sure where the actual error is. All I know is the db function is never even called. Here's the stack trace:
Compiling kipsu.jdbc.json
Compiling kipsu.database
Compiling kipsu.api_converter
Compiling kipsu.web
java.lang.NullPointerException, compiling:(web.clj:124:29)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3628)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3622)
at clojure.lang.Compiler$BodyExpr.eval(Compiler.java:5879)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:439)
at clojure.lang.Compiler.compile1(Compiler.java:7323)
at clojure.lang.Compiler.compile(Compiler.java:7390)
at clojure.lang.RT.compile(RT.java:399)
at clojure.lang.RT.load(RT.java:444)
at clojure.lang.RT.load(RT.java:412)
at clojure.core$load$fn__5448.invoke(core.clj:5866)
at clojure.core$load.doInvoke(core.clj:5865)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5671)
at clojure.core$compile$fn__5453.invoke(core.clj:5877)
at clojure.core$compile.invoke(core.clj:5876)
at user$eval9$fn__16.invoke(form-init1768231915654429312.clj:1)
at user$eval9.invoke(form-init1768231915654429312.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6782)
at clojure.lang.Compiler.eval(Compiler.java:6772)
at clojure.lang.Compiler.load(Compiler.java:7227)
at clojure.lang.Compiler.loadFile(Compiler.java:7165)
at clojure.main$load_script.invoke(main.clj:275)
at clojure.main$init_opt.invoke(main.clj:280)
at clojure.main$initialize.invoke(main.clj:308)
at clojure.main$null_opt.invoke(main.clj:343)
at clojure.main$main.doInvoke(main.clj:421)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
at kipsu.web$fn__4568.invoke(web.clj:115)
at clojure.lang.Delay.deref(Delay.java:37)
at clojure.lang.Delay.force(Delay.java:27)
at clojure.core$force.invoke(core.clj:730)
at kipsu.web$db.invoke(web.clj:118)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3623)
... 30 more
Exception in thread "main" java.lang.NullPointerException, compiling (web.clj:124:29)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3628)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3622)
at clojure.lang.Compiler$BodyExpr.eval(Compiler.java:5879)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:439)
at clojure.lang.Compiler.compile1(Compiler.java:7323)
at clojure.lang.Compiler.compile(Compiler.java:7390)
at clojure.lang.RT.compile(RT.java:399)
at clojure.lang.RT.load(RT.java:444)
at clojure.lang.RT.load(RT.java:412)
at clojure.core$load$fn__5448.invoke(core.clj:5866)
at clojure.core$load.doInvoke(core.clj:5865)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5671)
at clojure.core$compile$fn__5453.invoke(core.clj:5877)
at clojure.core$compile.invoke(core.clj:5876)
at user$eval9$fn__16.invoke(form-init1768231915654429312.clj:1)
at user$eval9.invoke(form-init1768231915654429312.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6782)
at clojure.lang.Compiler.eval(Compiler.java:6772)
at clojure.lang.Compiler.load(Compiler.java:7227)
at clojure.lang.Compiler.loadFile(Compiler.java:7165)
at clojure.main$load_script.invoke(main.clj:275)
at clojure.main$init_opt.invoke(main.clj:280)
at clojure.main$initialize.invoke(main.clj:308)
at clojure.main$null_opt.invoke(main.clj:343)
at clojure.main$main.doInvoke(main.clj:421)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
at kipsu.web$fn__4568.invoke(web.clj:115)
at clojure.lang.Delay.deref(Delay.java:37)
at clojure.lang.Delay.force(Delay.java:27)
at clojure.core$force.invoke(core.clj:730)
at kipsu.web$db.invoke(web.clj:118)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3623)
... 30 more
Compilation failed: Subprocess failed
I'm not the most fluent with Clojure and am working with this app to learn more. Any help for steering me at the right direction from here is greatly appreciated!
I think your problem is because def will execute at compile time. You've done the right thing in (def config) and (defn db), but (def app) is going to cause compile time errors if it cannot find your file. To understand why let's look at def.
(def hello (println "hello"))
If you try to compile this code you'll see "hello" printed to your console at compile time and at runtime the var hello will have the value nil.
(def hello (delay (println "hello"))
(def world #hello)
The var hello now won't get evaluated at compile time, but by introducing the var world we get the exact same problem.
Now back to your specific problem. You don't want your configuration to get read at compile time, and you don't want your configuration to have to read a file from disk every single time you need it.
Not reading your configuration at compile time makes me think that maybe it should be a function. If it is then a function you can simply use memoize to ensure it doesn't read from disk every time you call that function.

Using PhantomJS through Selenium with Python - WebDriverException error

I am using the following code, as recommended here: Is there a way to use PhantomJS in Python?.
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.set_window_size(1024, 768) # optional
driver.get('https://google.com/')
driver.save_screenshot('screen.png') # save a screenshot to disk
sbtn = driver.find_element_by_css_selector('button.gbqfba')
sbtn.click()
When I try to run it I get the following error:
WebDriverException - "Unable to start phantomjs with ghostdriver."
Apparently, this error can be solved by replacing the 3rd line with:
driver = webdriver.PhantomJS(executable_path='/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs')
I'm using Windows7, and the path for me appears to be: "C:\Users\myname\AppData\Roaming\npm\node_modules\phantomjs\bin\phantomjs". I have tried using this and variations of it as the executable_path, but I still get the same error. I have also tried adding the folder location to the path. Nothing has worked. I suspect that I am missing something pretty obvious.
Aha!
It was a slightly different location. The line I was looking for was:
driver = webdriver.PhantomJS(executable_path=r'C:\Users\myname\AppData\Roaming\npm\node_modules\phantomjs\lib\phantom\phantomjs')

Resources