Capybara/Poltergeist DOM loading issues - ruby-on-rails-4

I am writing a test suite using Capybara/Poltergeist combo for a website and I am coming across a situation where the DOM doesn't seem to be loading whatever I try to do.
I can see from the website snapshot that only the footer and the header are there, but not the main components of the page.
for example a page such as: https://www.udemy.com/courses/business/finance/all-courses/?lang=en&ordering=newest
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: false, debug: false, # change this to true to troubleshoot
window_size: [1300, 1000] # this can affect dynamic layout
)
end
browser=Capybara.current_session
browser.visit "https://www.udemy.com/courses/business/finance/all-courses/?lang=en&ordering=newest"
sleep 15 ##giving it time to load
browser.save_screenshot('app/file1.png', full: true)
only the header and footer show up.
I suppose it is due to the fact that some DOM elements are loaded asynchronously, and on my current website I have the same problem.
Stuck here for 2 days now, any suggestions as to how to get the page to load properly? Thanks

You most likely need to update phantomjs to 2.0+. PhantomJS 1.9.8 which I'm guessing you're using is roughly equivalent to Safari 5 iirc and doesn't appear to work with the udemy site.

Related

ember serve and browser reload results in "cannot GET /foo" with custom Ember.Location

TL;DR: Added custom location type to environment.js then ember serve -> open browser to route /foo -> cannot GET /foo
Followed the instructions at https://www.emberjs.com/api/classes/Ember.Location.html#toc_custom-implementation and copied the code exactly as it appeared into a file called app/locations/history-url-logging.js, added a line to config/environment.js that said:
ENV.locationType = 'history-url-logging';
For reference, the code given in the docs is simply:
import Ember from 'ember';
export default Ember.HistoryLocation.extend({
implementation: 'history-url-logging',
pushState: function (path) {
console.log(path);
this._super.apply(this, arguments);
}
});
I decided to restart the server, did the usual CTRL+C to ember s then did ember s again. I went back to my browser sitting on one of the routes, hit F5, and received the cryptic error:
Cannot GET /contacts
So, after MUCH Googling and trial and error (and posting a previous question here which I just edited with this text you're reading), I discovered that to FIX that error, all I had to do remove the config line ENV.locationType = 'history-url-logging';, restart the server (ember s), and suddenly the app worked fine!
What's even more odd is that if I start the app without that line in environment.js, then once the app is running (and the browser window reloads just fine, etc), then I re-add the line that says ENV.locationType = 'history-url-logging'; (which triggers a live reload), and the app still works fine! (E.g. hitting F5 to reload the page doesn't vie me the "Cannot GET /contacts" (or whatever the route is) error.) And, of course, the console gives me the "console.log" output as expected from the code above.
So, long and short of it, using a custom location totally seems to screw up ember serve - which is really sad and frustrating! Any ideas how to fix this?
Ember built-in server looks at the environment.js locationType property to figure out if it must serve routes after the rootURL path. By default, if the locationType is history it will do it. It uses string matching.
In your case you wrote your own location, inheriting from HistoryLocation therefor the locationType property in the environement.js is now history-url-logging. The built-in server doesn't recognize it as a history based form of location just by the name. It will default to hash location. It doesn't analyze your code.
For this scenario, we have to help the built-in server to understand that the locationType is equivalent to a history location.
You need to add historySupportMiddleware: true in your environment.js file right after the locationType property.

How to control the download of files with Selenium + Python bindings in Chrome

Where can I find the documentation that describes the options I can use with Selenium and Chrome web browser? I want to open a link in a web browser (to get credential) but not to download the corresponding file (.pdf or .tiff or .jpeg). I am using Python 2.7, selenium 3.0.1 and Chrome version 54.0.2840.99 (and chromedriver.exe) on Windows 7 Laptop.
# Chrome web browser.
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
#options.add_argument('--disable-download-notification') #doesn't seems to work
#options.add_experimental_option("prefs", {"download.default_directory","C:\Users\xxx\downloads\Test"}) # doesn't work
#options.add_experimental_option("prefs", {"download.prompt_for_download": False}) # doesn't seems to work
#options.add_experimental_option("prefs", {'profile.default_content_settings': {'images': 2}})# this will disable image loading in the browser
options.add_argument("user-agent="+user_agent_profile)
driver_main = webdriver.Chrome(chrome_options=options)
# Opening the web application portail.
driver_main.get("https://my_link")
I found many discussions on this topic but none of the solution works. For example:
add_experimental_option("prefs", {"download.default_directory","C:\Users\xxx\downloads\Test"})
doesn't work for me.
Same for:
add_experimental_option("prefs", {"download.prompt_for_download": False})
(I also try with "false").
While:
add_argument("user-agent="+user_agent_profile)
Seems to work!
I am not sure to understand what is wrong
The issue I got is that, it starts to download the file each time I open a link with name file(1) file(2) .... file(99) then starting at 100 it opens a popup window "Save As". So I would like to either don't download the file at all or be able to move it in a specific folder in the "Recycle Bin".
How do I find which options could be I used with add_argument and add_argument? I tried to look at Chrome://about/ but I couldn't see a direct correspondence.
Thanks a lot.
Cheers.
Fabien.
The path you declared for the default directory is invalid. Either escape the back slashes or provide a literal string.
options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {
"download.default_directory": r"C:\Users\xxx\downloads\Test",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
driver = webdriver.Chrome(chrome_options=options)
Here are the available preferences:
https://cs.chromium.org/chromium/src/chrome/common/pref_names.cc
It makes all the difference in the world to use the forward slash "/" when specifying the directory in which you want things to be downloaded.
I'm guessing this is because that directory will be exported to something like the Powershell, where the usual backslash "\" won't properly work.

Why is javascript not checking my checkbox?

I am trying to test a simple header checkbox checks all checkboxes in a table.
The test is below:
scenario 'select all enrolments', js: true do
check 'all_enrolment_presentations'
expect(page).to have_css('.enrolment-presentation-listing input[type="checkbox"]:checked', count: 1)
end
This fails, however if I change the scenario a bit to
scenario 'select all enrolments', js: true do
sleep 3
check 'all_enrolment_presentations'
expect(page).to have_css('.enrolment-presentation-listing input[type="checkbox"]:checked', count: 1)
end
It works.
I have tested a couple of other selectors and they all pretty much have the same affect. I do not want to have to add sleep statements to get stuff like this to pass. I must be doing something incorrect.
When I run the test without the sleep clause, it seems to find the control (it gets highlighted), but it isn't checked. See screenshot for what I mean.
My question is why is this happening and how can I fix my issue?
Note I am using rails 4.2.4 and capybara 2.5.0
After some further investigation the bug was actually caused by upgrading selenium-webdriver from version 2.45.0 to 2.48.1. I haven't had enough time to investigate the root cause within the gem.
You have to wait until capybara to perform click operation.
So,
1. Use sleep
example sleep 5 with wait for 5 seconds
2. Change default wait time in capybara using
`Capybara.default_wait_time = some_value`

Coldfusion 10 - Application specific classpaths

I am working with a CF10 application and trying to define application specific classpaths to load JARs using the this.javaSettings feature introduced in CF10.
From Application.cfc:
THIS.javaSettings = {
LoadPaths = [".\java_lib\",".\java\myjar.jar"],
loadColdFusionClassPath = true,
reloadOnChange = false
}
This is working great, and I can define JARs on an application basis. However, every time I reload the application (for example, if I call applicationStop()) then CF seems to hold on to all the loaded JARs/classes at the same time re-loading them all - which means after a number of reloads I inevitably get an out-of-memory Perm Gen error.
Has anyone experienced this? I have tried the usual things by updating GC strategies to enable permgen collection:
-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
Ok, this was not an issue with the CF feature - turns out that the memory leak was originating in the groovy code that had been compiled in to a jar (you can read groovy details here: https://stackoverflow.com/a/17952925/258813)
It appears as though the CF10 hot-reloading of jars is working ok!

magento Not valid template file /page/1column.phtml

I had my site running fine on the devp. server. After I migrated the app to my production server. Everything worked until I added an extension and enabled it. The site still works but the product view page doesn't show up. Everytime I click on the product view page, this error is appended to my log file...
CRIT (2): Not valid template file:frontend/base/default/template/page/1column.phtml
I have checked the file it is alright, just same as the one working on the development server. I've tried disabling the only plugin (custom menu) that I have and still the problem persists. I've tried increasing memory_limit but it doesn't help either.
Please help, I am stuck in the middle of nothing.
A common cause of this error is the use of symlinks without enabling this in the admin area…
System > configuration > developer > Template Settings
The error gets triggered in app\code\core\Mage\Core\Block\Template.php around line 243 ( see here ) - so if its not an issue with symlinks then this would be a good place to start debugging.
If you are not using xDebug then where the exception gets caught around line 250 you should either log or var_dump the values of:
$includeFilePath
and
$this->_viewDir
Then make sure they both exist (paying attention to the case)
Failing that you might want to look at permissions.
UPDATE core_config_data SET value = '1' WHERE path = 'dev/template/allow_symlink';
or
INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', 0, 'dev/template/allow_symlink', '1');