Uploading a zip file from relative directory fails on Windows using Selenium WebDriver with Ruby. It works well in Mac - ruby

We are currently working on an web application testing using Selenium-Webdriver with Ruby. Originally we only test the OSX platform, until recently we realize that Windows platform should also be tested, (IE, Firefox, Chrome, Opera). But those following lines code that work well on OSX fails on Windows(7 & 8).
I want to upload a zip file from relative directory on Windows, like "./assets/application/www.zip"
#driver.execute_script("arguments[0].style.visibility = 'visible'; arguments[0].style.width = '1px';arguments[0].style.height = '1px';arguments[0].style.opacity = 1",upload_a_zip_btn)
upload_a_zip_btn.send_keys (File.expand_path("../../assets/application/www.zip",__FILE__)) # 1
upload_a_zip_btn.send_keys ("assets\/application\/www.zip") # 2
upload_a_zip_btn.send_keys "C:\\www.zip" # 3
I tried all the 3 conditions, but only the 3rd works.
The error appeared in Browser said some error like "no attached file"
Does anyone know how to deal with such situation? Thanks

Related

Is it possible to automate logging into roblox?

I have been playing roblox a lot lately, and I was wondering if there was a way to automate the login process since I play on different computers each time. I looked into Python's selenium, and derived the script:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.roblox.com/login")
usernameStr = '<redacted>'
passwordStr = '<redacted>'
username = driver.find_element_by_id('login-username')
username.send_keys(usernameStr)
password = driver.find_element_by_id('login-password')
password.send_keys(passwordStr)
signInButton = driver.find_element_by_id('login-button')
signInButton.click()
When I run it in VScode it works perfectly, but when I exported the python file and tried running it via interpreter, it gave many errors around version types. I installed selenium on the computer as well. My hypothesis is my local computer had some tools in the background that when I tried on other computers didn't. Is there something that I am missing when going to my other computer? I am using python3.8.
One thing you could is make a script, when executed runs by the python in your $PATH.
#!/usr/bin/env python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.roblox.com/login")
usernameStr = '<redacted>'
passwordStr = '<redacted>'
username = driver.find_element_by_id('login-username')
username.send_keys(usernameStr)
password = driver.find_element_by_id('login-password')
password.send_keys(passwordStr)
signInButton = driver.find_element_by_id('login-button')
signInButton.click()
If you save this file in your terminal and run chmod +x <filename> to give it executable permissions, it will be a executable, which you can move from machines. Make sure to have all other selenium dependencies installed as well. When working with selenium, make sure your chrome driver is the same as your chrome browser, which you can read about on the chrome webdriver page.

Open HTML in chrome from command line using app flag

(Before downvote im aware how to do this using code thats inline to this command but not how to do it using a file that uses the --app="data:text/html,<sometags></sometags>)
How would I open a local html (mar.html) file using this command
C:\'Program Files (x86)'\Google\Chrome\Application\chrome.exe --profile-directory="Default" --app=
Specifically, the issue is my lack of familiarity with the --app flag
I tried
C:\'Program Files (x86)'\Google\Chrome\Application\chrome.exe --profile-directory="Default" --app="mar.html"
C:\'Program Files (x86)'\Google\Chrome\Application\chrome.exe --profile-directory="Default" --app="file:///mar.html"
Both don't work.
Giving me the error
Your file was not found
It may have been moved or deleted.
ERR_FILE_NOT_FOUND
You almost got it. The file descriptor path must be absolute and encoded.
Encoding the path correctly with cli tools like "urlencode"(gridsite-clients) did not work for me.
If you have NodeJS installed and would use a linux machine, you could use this command.
chromium --app=`node -e "console.log('file://'+encodeURI(process.argv[1]))" "$(realpath "/path/of/your/file.html")"`
This works also fine with relative paths.
For windows you have to rewrite this yourself.

Can I upload a directory to a remote node via watir-webdriver?

I have a cucumber test that uploads a directory by entering the directory path into the file field. It works perfectly fine when I run the test on my machine but I'm getting the following error when I try to run it against my selenium grid setup:
you may only upload files: "/cucumber_tests/temp/uploads/Cuke1477494492767281" (Selenium::WebDriver::Error::WebDriverError)
(eval):1:in 'process_watir_call'
Full backtrace:
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'instance_eval'
/.rvm/gems/ruby-2.2.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/remote/bridge.rb:432:in 'send_keys_to_element'
/.rvm/gems/ruby-2.2.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/common/element.rb:146:in 'send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:319:in 'block in send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:621:in 'element_call'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:319:in 'send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/file_field.rb:24:in 'value='
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/file_field.rb:13:in 'set'
(eval):1:in 'process_watir_call'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'instance_eval'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'process_watir_call'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:846:in 'file_field_value_set'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/accessors.rb:1021:in 'block in file_field'
My code pretty much looks like this:
#browser.file_field(id: "assets").send_keys "/cucumber_tests/temp/uploads/Cuke1477494492767281"
Again, I'd like to emphasize that this works perfectly fine on my machine but not on the remote node. Also, single file uploads are fine for me on both my machine and on the grid. I'm wondering if any of you have had luck uploading directories on remote nodes or know if it's even possible (even if I have to install more gems). Thanks in advance!
Try passing in the absolute path to the file:
File.expand_path("/cucumber_tests/temp/uploads/Cuke1477494492767281")
Unless you are trying to upload something from your local computer to a remote computer via Watir. That you can't do.
No, Selenium & Watir are not designed to upload directories. You could loop through files, but they wouldn't be in a subdirectory.
Dir["/path/to/files/*"].each do |file|
#browser.file_field(id: "assets").set File.expand_path(file)
#browser.form.button.click
end

Ruby Shoes App packaged for Windows doesn't display images

When I package my Shoes App for Windows images doesn't work. I have this very simple app (min_test.rb):
Shoes.app()
{
background "bg.jpg"
}
Which works fine if I run it through Shoes, but when I package it with Shoes so that I get a standalone .exe file the images doesn't load. Inside the folder these are the contents:
min_test.rb
bg.jpg
min_test.exe (after packaging)
If Shoes3.3.1, indeed, on linux too.
console (alt-/) saying "couldn't find tmp.....bg.jpg" ?
(background or image)
could you file a bug report, please : https://github.com/Shoes3/shoes3/issues
EDIT: Sorry, wait
if Shoes3.3.1 !
you have to first make a shy then an exe and the resulting exe will be outside of the directory where your script and image is.
follow this : https://github.com/Shoes3/shoes3/wiki/Packaging
(note: tested on linux and on Windows)

Running casperjs tests with slimerjs

I wrote a few tests with casperjs. They run just fine with phantomjs. However, when I tried to use slimerjs with the following command:
casperjs --verbose --engine=slimerjs test create-project-suite.js
A small window appers with the SlimerJs logo and version number but the console seems to hang with the following line:
Test file: create-project-suite.js
Is there anything else I need to do? Here are the version numbers:
Mozilla Firefox 28.0
CasperJS version 1.1.0-beta3
Innophi SlimerJS 0.9.1
3.8.0-37-generic #53~precise1-Ubuntu
Update:
I removed code until I got slimerjs to open the browser and execute tests. It seems that it hangs whenever I require a js file (I'm following the page objects pattern):
var Login = require('./objects/login');
I think require.paths could be helpful. Any ideas on how to get around this?
Using full paths makes slimerjs happy:
var path = fs.absolute(fs.workingDirectory + '/objects/login');
var Login = require(path);
It is plain simpler to move all modules to the same directory where the script is.
I tried your command and it works for me, maybe in your file you use an instruction specific to phantom :
http://docs.slimerjs.org/0.8/differences-with-phantomjs.html
But it should open the window(at least the start() ).
Anyway the command is fine.

Resources