Selenium: Is there a way to change the hosts file on the machine the server is running on - selenium

I want to make the browser open a local url with a name of the live url. Meaning that when I do:
sel.open('http://live-url/)
selenium will actually open the local url.
One would test this by changing it's hosts file but this is impossible when running on many machines.
ideas?

No
Selenium cannot change the hosts file as it can only interact with pages rendered inside a broswer.
You could probably set your CI server up to do something like this, but again I have to ask why. Hacking around with a site and then testing it will surely invalidate your tests?

Related

chimp.js configuration - the browser is not opening localhost

I am having problem with chimp.js configuration. When I run tests the browser is not using provided host / post. I tried many things but without success. Does anyone know how to set up it properly? Please find my config in screenshot provided.
When the browser first starts, it defaults to data;. You need to navigate somewhere first.
The host and port settings are not related to browsing. They tell Chimp where the Selenium server is, which by default is chromedriver.
I had to setup beforeFeature hook to start using localhost:3000

Jenkins Execution Issue

A selenium script , when executing from Eclipse in a local machine , clicks an UPLOAD button in browser to upload some files from local machine to that application running in browser.
This uploading part is failing when the script is executing from Jenkins because Jenkins server is unable to access local machine.
Any idea how to overcome this issue..??
Accessing these files from the server is a bad idea (unless it's a Jenkins's slave) though can be achieved via your code or some CMD tool, with providing the address and credentials. Put some effort in this and you'll find how to do it...
The better solutions will be adding these files to the Jenkins server as well or committing these files to your repository and checkout them before the test.
A shared folder could also do the trick on a filer type server or similar.
Hope it helps. Anyway there's no substitute to your own research e.g. Google and StackOverflow.

WebRTC - Browser doesn't ask for mic access permission for local html file

I have some simple webRTC code which uses getUserMedia to gain access to user's mic. Now when I load that html file (saved at my localhost) in my browser, the browser doesn't ask for mic access permission and thus get failed to get access.
But when I run the same html inside the w3schools.com editor, it asks for mic access permission and upon allowing it to access my mic, it works fine...
Why is this strange behaviour?
When you open an html file right off the filesystem (file:// prefix), Chrome will auto-block getUserMedia permissions. You have to run a server locally.
I started up a sinatra server like this:
# server.rb
require 'sinatra'
get '/' do
File.read('index.html')
end
Then give it ago.
$ gem install sinatra
$ ruby server.rb
http://localhost:4567
Because of security Chrome won't open user media, e.g. WebCam when executing a file:/* document.
You could override however the security policy by starting chrome with the --disable-web-security command line option.
For testing check also the --use-fake-device-for-media-stream option.
N.B. When specifying command line options make sure there is no chrome/chromium process running.
P.S Give it a try by creating a file test.html containing
<!DOCTYPE HTML>
<video autoplay/>
<script>
navigator.webkitGetUserMedia({audio:true,video:true},
function(stream){
document.querySelector('video').src =
URL.createObjectURL(stream);
});
</script>
and than kill all chrome instances and start chrome like this:
chrome.exe --use-fake-device-for-media-stream --disable-web-security test.html
This behavior is caused by Chrome security settings.
If you have PHP installed and you don't wanna setup Apache or other more advanced web server, probably the easiest way would be to run internal PHP web server this way (assuming you have your web files in /home/user/web/):
php -S 127.0.0.1:3000 -t /home/user/web/
Here is a description of the parameters:
-S <addr>:<port> Run with built-in web server.
-t <docroot> Specify document root <docroot> for built-in web server.
After you run the server start your browser and open this URL (assuming your test file is called webrtc.html):
http://127.0.0.1:3000/webrtc.html
Just some troubleshooting suggestions:
Check chrome://settings/content (scroll down to "Media"), to see if you've accidentally selected that site to always allow or always deny. (I'm on Chrome 26[dev]; this may be located somewhere else on Chrome 24.)
Also try restarting your browser - this bit of Chrome is still pretty buggy in my experience, and sometimes a restart fixes it.
And make sure you've got an error handler in your getUserMedia() call - there may be some additional info there.
Are you loading the file via something like file://? It seems chromium does not give access to those files at all and completely ignores the request. Just tried myself and after uploading the file to a dev server it worked fine.
Even setting it to allow always it still does not work with file://.
You can't run HTML5 that uses getUsermedia API locally without using a local server. Use WampServer and place your HTML5 file inside the www folder.
This answer is for chrome
In Chrome you can use the --allow-file-access-from-files flag to allow webcam access from a local file.
Mac
On a mac you can open the terminal and type:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files /path/to/file.html
change /path/to/file.html with your path
Windows
In Windows you can create a shortcut. Right click Google Chrome And in the menu select: Copy To -> Desktop (shortcut), then right click the shortcut and click properties add the flag:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files C:\path\to\file.html
Hope this answer helps!

How do I communicate to the outside world from a Safari extension?

How would I let a running process know that a context menu has been clicked in Safari?
I've read that this is not possible due to security, but that seems wrong because 1Password somehow pulls all of the information from the desktop app's database into the Safari extension. I wrote the extension to display the context menu and was trying to send an XMLRPC request to localhost, but couldn't get it to work.
I'm not certain of this, but I think 1Password does what it does by having a background process (1PasswordAgent) constantly polling for certain changes in the extension's local database and/or config files. For example, to initially get your passwords into the extension, the extension could set a certain flag in its localStorage db, which would get written (by Safari, not by the extension) to a file. The agent would then notice the flag in the file and copy your passwords from the main 1Password database into the extension's local database. Similarly, when the extension creates a new password entry, the agent would notice the change in the extension's database and mirror it to the 1Password database.
Perhaps you could do something similar?
Although I have no idea about the implementation of 1Password, LiveReload achieves the same by using WebSocket to connect to a localhost URL (handled by the application). If you do it from the global page, cross-domain limitations do not apply, so you are free to connect to any URL:
var ws = new WebSocket("ws://localhost:98765");
...
(Be careful with that localhost thing, though, Chrome on Linux wants 0.0.0.0 instead of 127.0.0.1 or localhost. At least it used to want it.)

Apache not loading CSS files on remote browsers but works on localhost

I have an ubuntu installation on my laptop i use for web app development. When i type in http://localhost/blah.php i see my php web page as i normally would with all css style loaded and rendering fine.
When i try to connect to this same apache server from a remote machine by typing in the IP address the page loads but without any css styling at all. I also get the same problem trying to connect to the apache server from a virtual machine on the same box. I would like to get this working so i can test my web apps in IE but obviously css not loading is a problem. Any tips ?
Look into your source code and look how your style sheets are referenced.
If you have references to http://localhost/mystylesheet.css, that's your problem right there.
If that doesn't help, try to access a style sheet directly (enter the address in the browser) and tell us what happens. Also post the URL you are using. The head of the HTML document you are calling would also be helpful.