Ruby: How to store proxy authentication inside chromedriver? - ruby

i've created browser instance using watir like below:
proxies = ['--proxy-server=hostname:portnumber', '--proxy-auth=username:password']
browser = Watir::Browser.new :chrome, :switches => proxiesle
but the problem above the code is cannot authenticate proxy by passing parameters --proxy-auth=username:password, i was wondering how could i automatically set username and proxy in chrome driver? Some solution was written in java like below:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user:password#proxy.com:8080"));
WebDriver driver = new ChromeDriver(capabilities);
how you guys to override proxy authentication inside chrome ?

Chrome has stopped support for URL authentication system for latest Chrome version.
I have a Java code, which will authenticate pop-up:
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(username, password));
Convert this code in Ruby.

Related

Selenium w/ Firefox not accepting HTTP Proxy IP with user authentication

I'm looking to use Selenium with a username/password authenticated proxy in Ruby. I realize that most people use ProxyChain when doing this in Chrome, but I'd like to use a solution without any additional gems since it doesn't play well on Heroku, plus I'm using Firefox so there seems to be a possible other option judging by THIS question though it's written in Python.
I used the selenium docs to translate that code to Ruby, but Selenium is still not using my proxy when navigating to a webpage. Oddly enough when I refresh the page manually it prompts me for the username/password but it doesn't do that on the initial page load.
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 1
# proxy ip and port are fake for this example
profile["network.proxy.http"] = "182.192.157.60"
profile["network.proxy.http_port"] = 12345
# set the username and password
profile["network.proxy.socks_username"] = "my_username"
profile["network.proxy.socks_password"] = "my_password"
options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
driver = Selenium::WebDriver.for :firefox, options: options
If anyone has any ideas I would certainly appreciate the help. Thank you.

Selenium get http request ajax url after button click

I need to get the http request URL when a button is clicked in a webpage programatically.
I am using selenium to trace the button and I am performing click on the button. on click of the button it makes a http request and the same can be traced in the network tab of the browser.
How can i get the request URL programatically once I trigger the button click using selenium.
Any other tools or libraries that I can use to achieve the same functions is also ok for me. I just need to be able to get the URL after button click programatically. This is a dynamic URL which changes periodically and the objective is to automate the download process through code.
Thanks in advance for any help!
You can use JavaScript executor to get network data. Please refer https://stackoverflow.com/a/45859018/5966329
get request/response data from there.
DesiredCapabilities d = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
d.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
WebDriver driver = new ChromeDriver(d);
driver.get("https://www.google.co.in/");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
LogEntries les = driver.manage().logs().get(LogType.PERFORMANCE);
for (LogEntry le : les) {
System.out.println(le.getMessage());
}
Python Equivalent:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import
DesiredCapabilities
caps = DesiredCapabilities.CHROME
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get('https://stackoverflow.com')
for entry in driver.get_log('performance'):
print(entry)
Please refer thread for more info python

Headless browser using jmeter

I tried to use (jp#gc - HtmlUnit Driver Config) to create a headless browser test using jmeter, but I get this error
Response message: com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "getComputedStyle" is not defined.
I read online and it suggest that jp#gc - HtmlUnit Driver Config doesn't support javascript. Is there a way I can fix this via jmeter? or is there any other option to do headless browser testing. I have linux server as load injector
Update:
I have a webdriver sampler to open google page
WDS.sampleResult.sampleStart() WDS.browser.get('http://google.com')
WDS.sampleResult.sampleEnd()
and have downloaded Phanton JS, but when I run it it doesn't show anything on the report. Should I add any other config?
HtmlUnit do not support very well JS.
I done many tests and used each one and i can say that PHANTOMJS is the best one with good support of all JS/CSS... have a beautiful renderer to have nice screenshots.
by code you can use it like this (you can download it from here http://phantomjs.org/download.html (phantomjs-1.9.8 is very stable)):
Capabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((DesiredCapabilities) caps).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"your custom path\\phantomjs.exe"
);
WebDriver driver = new PhantomJSDriver(caps);
If you want to do that via JMeter GUI, you need to add before your Logic Controller an element JSR223 Sampler JSR223_Sampler
and inside the script panel :
org.openqa.selenium.Capabilities caps = new org.openqa.selenium.remote.DesiredCapabilities();
((org.openqa.selenium.remote.DesiredCapabilities) caps).setJavascriptEnabled(true);
((org.openqa.selenium.remote.DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((org.openqa.selenium.remote.DesiredCapabilities) caps).setCapability(
org.openqa.selenium.phantomjs.PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"your custom path\\phantomjs.exe");
org.openqa.selenium.WebDriver driver = new org.openqa.selenium.phantomjs.PhantomJSDriver(caps);
org.apache.jmeter.threads.JMeterContextService.getContext().getCurrentSampler().getThreadContext()
.getVariables().putObject(com.googlecode.jmeter.plugins.webdriver.config.WebDriverConfig.BROWSER, driver);
Do not hesitate if you need more informations.

selenium firefox webdriver - accessing session

I am already logged in to my googlemail account in Firefox browser with profile named: test_profile.
Using Selenium, I launch Firefox browser with profile test_profile, but I am seeing login page. Meaning, the session/cookies are not being used.
What am I doing wrong? Or what can be done so I can use my session.
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("test_profile");
WebDriver driver = new FirefoxDriver(profile);
driver.get("https://www.googlemail.com");
Thanks.

centOS, Jenkins, Firefox & Selenium GRID - HTTPS certificate issue

I have Jenkins running headless on a remote machine(centOS). I am trying to run some automated login tests using Selenium Grid (with both hub and a node on same centOS machine) on a development environment whose security certificate is self signed. So, on the home page, when the login link is clicked, it lands up at https error page, while selenium webdriver expects the login page. So all tests are getting failed. I tried to create firefox profile:
nodeUrl = "http://localhost:4444/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
capability.setCapability(FirefoxDriver.PROFILE, profile);
capability.setBrowserName("firefox");
capability.setPlatform(Platform.ANY);
driver = new RemoteWebDriver(new URL(nodeUrl), capability);
But this does not work out. How can i make sure that when the node invokes firefox, it accept that untrusted certificate?

Resources