I need to set proxy for Chrome browser in Fitnesse , so that the browser can open certain websites.
Is it possible to add it while initialising the selenium grid in Fitnesse ?
And also is it possible to add username and password to it ?
Adding Fitnesse code below : I am using a selenium hub
|Import |
|nl.hsac.fitnesse.fixture.slim.web|
!define GRID_HUB {http://remote-selenium.local:4444/wd/hub}
|script |selenium driver setup |
|connect to driver at |${GRID_HUB} |with capabilities|!{browserName:chrome} |
I need to pass the proxy object to this. How can I do that ?
A similar code in Java would be :
String nodeUrl = "http://remote-selenium.local:4444/wd/hub";
Proxy proxy = new Proxy();
proxy.setHttpProxy("proxy:8080");
proxy.setSslProxy("proxy:8080");
ChromeOptions options = new ChromeOptions();
options.setCapability("proxy",proxy);
RemoteWebDriver driver = new RemoteWebDriver(new URL(nodeUrl),options);
How can I achieve this in Fitnesse ?
I have to admit I never had to work with proxies, but some googling suggests that you should also be able to configure the proxy using the generic chrome.switches capability which passes them as command line options. Those options are described at: https://www.chromium.org/developers/design-documents/network-settings
So that would give you something like:
|script |map fixture |
|set value |chrome |for|browserName |
|set value |--proxy-server="http=http://proxy:8080/;https=http://proxy:8080/"|for|chrome.switches[0]|
|$chromeCapabilities=|copy map |
!define GRID_HUB {http://remote-selenium.local:4444/wd/hub}
|script |selenium driver setup |
|connect to driver at|${GRID_HUB}|with capabilities|$chromeCapabilities|
You could add more elements by adding lines setting values for chrome.switches[1], chrome.switches[2], etc.
So for instance:
|set value |--proxy-bypass-list="*.google.com;127.0.0.1:8080"|for|chrome.switches[1]|
To not proxy requests to any google.com subdomain or requests to 127.0.0.1 port 8080.
When not using a remote chrome (e.g. starting chrome using |start driver for|chrome|) you can pass command line arguments as profile. This should also allow for proxy settings. See for instance hsac-fitnesse-fixture's BrowserTest.SuiteSetUp that passes command line options to make Chrome run in headless mode.
Related
Is there a way to change protractor's default debugger port 5858? Currently I'm using the following command to launch protractor:
$> protractor debug protractor.conf.js
There's an optional parameter you can pass to pause to use a different port, e.g. browser.pause(5859) :
https://angular.github.io/protractor/#/api?view=Protractor.prototype.pause
The port is hardcoded in several locations of the protractor code:
https://github.com/angular/protractor/search?q=5858&ref=cmdform
So i guess, you could fill an issue explaining your requirement, or you could fork, modify protractor and make a pull request.
When running Selenium tests remotely with PHPUnit and Firefox, onChange events are not fired as they are when a user is operating the browser.
The solution to this seems to be to set the focusmanager.testmode option to true in Firefox's preferences (i.e. about:config), as suggested in a Selenium bug report.
However all the examples are using Selenium directly, while I am using PHPUnit which has its own API hiding the Selenium internals. I can't figure out how to set this Firefox option using PHPUnit, so I'm hoping someone else can tell me how this can be done!
(No, I can't go into about:config and set it myself manually because the tests create a new clean browser profile each time the tests are run, so any manual config changes are lost.)
Thanks to the Selenium developers I have a solution!
Short version
Put this in your test so that it gets called in the setUp() function:
// Firefox mini-profile that sets focusmanager.testmode=true in about:config
define('FIREFOX_PROFILE',
'UEsDBAoAAAAAADqAxkSBK46tKgAAACoAAAAIABwAcHJlZnMuanNVVAkAA1BZkVM6WZFTdXgLAAEE
6AMAAARkAAAAdXNlcl9wcmVmKCJmb2N1c21hbmFnZXIudGVzdG1vZGUiLCB0cnVlKTsKUEsBAh4D
CgAAAAAAOoDGRIErjq0qAAAAKgAAAAgAGAAAAAAAAQAAAKSBAAAAAHByZWZzLmpzVVQFAANQWZFT
dXgLAAEE6AMAAARkAAAAUEsFBgAAAAABAAEATgAAAGwAAAAAAA==');
protected function setUp()
{
$this->setDesiredCapabilities(Array('firefox_profile' => FIREFOX_PROFILE));
}
This sets focusmanager.testmode to true.
Long version
You need to create your own mini Firefox profile with the preferences you want set, and pass it along at the start of your tests. Here's how to do it:
Create a new folder and put the files you want in the Firefox profile in there. This can be anything (bookmarks, extensions, a copy of your own profile, etc.) but all we need here is a file called prefs.js which stores our about:config settings.
Create prefs.js in this folder with the following content:
user_pref("focusmanager.testmode", true);
Zip up the folder (prefs.js should be in the root of the archive), and base64 encode it.
If you're using Linux, you can do it all like this:
mkdir firefox-profile
cd firefox-profile
echo 'user_pref("focusmanager.testmode", true);' >> prefs.js
zip -r ../firefox-profile.zip *
base64 < ../firefox-profile.zip
Then take the base64 value and set it as the "firefox_profile" capability as per the short version above.
I am running jasmine tests on Karma server.
On my tests I have to load a image and a json file test.
They depend on path. Which is the default path for Karma? I mean if i have a image in a directory inside my .js test files how can I reach that file?
I have tested src="myDir/myImage.jpg" but no sucess...
If you use a nodejs web-server to run your app, you can add this to karma.conf.js :
proxies: {
'/path/to/img/': 'http://localhost:8000/path/to/img/'
},
If you don't use or want to use another server you can define a local proxy but as Karma doesn't provide access to port in use, dynamically, if karma starts on another port than 9876 (default), you will still get a 404 error...
proxies = {
'/images': 'http://localhost:9876/base/images'
};
Based on this answer
Related GitHub issue for more info ;)
I would also suggest using requireJS because Karma does not deal well with fixtures...
proxies = {
'/images': 'http://localhost:9876/base/images'
};
To avoid 404 error if karma starts in in a different port, even after setting proxies, do the following:
Kill all the process using the port starting from 9876 (killing node.exe will do the trick)
Run you karma with 9876 port free now
Subsequent runs will be mapped automatically by karma to whatever port it launches
I have nearly identical versions of webapps on different sites.
What I'd like to do is specify the site at command line...
cucumber --server server1 --tags #tests
....
#servers = {'server1' => 'https://www.tests.com', 'server2' => 'https://www.foobar.com'}
....
Background:
Given I am on {#server1}
Scenario: Happy plan
When I go here
And I see this
Then I get that
What is the best way to running the same script on multiple similar websites? Can it be run from the command line?
Your best option is to use an environment variable for your server name:
cucumber SERVER=server1 --tags #tests
You can create a generic step:
Given I am on the configured test server
Then, in your step definition, you can look that up as you would in any normal Ruby code and set it as Capybara's base URL:
Given /^I am on the configured test server$/ do
server_name = ENV['SERVER']
url = #servers[server_name] or raise "Unknown test server: #{server_name}"
Capybara.app_host = url
end
Note that when using a remote server, you'll need to use a Capybara driver that supports it, such as Selenium: the default RackTest driver does not. You may also want to set run_server to false. See https://github.com/jnicklas/capybara#calling-remote-servers
Create some config and read it before executing scripts.
Put code for parsing config to features/support/env.rb, for example.
I am running cucumber tests with Webrat in external mode that is using Selenium. In production we are running behind https and so we are required to run our cucumber tests on https.
Is there any place we can specify that cucumber, webrat, or selenium needs to be using https? Ideally this could be specified through a parameter that is given to Webrat.
I have seen some stuff that looks like it might be possible if I override the default SeleniumClientDriver that comes bundled under the selenium.rb file.
env.rb =>
Webrat.configure do |config|
config.mode = :selenium
config.aplication_address = 'localhost'
config.aplication_port = 11090
config.selenium_server_address = 'localhost'
config.selenium_server_port = 4444
config.selenium_browser_key = '*iexploreproxy'
config.application_framework = :external
end
World do
session = Webrat::SeleniumSession.new
session.extend(Webrat::Methods)
session.extend(Webrat::Selenium::Methods)
session.extend(Webrat::Selenium::Matchers)
session
end
Thanks for any help!
This apparently is not something that the webrat team has decided to support.
So a team member changed the source to allow that this can be specified through env.rb properties. The pull request can be found here.