JMeter with Webdriver Sampler - Browser window not opening - selenium

I am running Jmeter with the Webdriver plugin installed on Windows 7. My current test plan contains the Webdriver sampler and Firefox driver config. When I try to run the test plan, nothing happens. There is nothing recorded in the View Results Tree window, and the remaining test indicator in the top right hand corner counts down to 0 without anything happening.
When I deactivate the Webdriver Sampler and Firefox driver config elements, the remaining tests run without a problem.
Is there a bug with this software, or am I missing something? My code is below, if that helps.
var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
WDS.browser.get('https://test.test.test.test') var username =
WDS.browser.findElement(pkg.By.id('USERNAME')).sendKeys([WDS.args[0]])
var password =
WDS.browser.findElement(pkg.By.id('PASSWORD')).sendKeys([WDS.args[1])
WDS.sampleResult.sampleEnd()
I have installed firefox 26, as this is the recommended supported browser, so it's not that there's no compatible browser.
My main question is this - Why doesn't the browser window open? Why do the other tests in the test plan fail to run when the config elements are active?

In 99% of cases the answer should be in jmeter.log file. In the meantime a couple of recommendations:
add the following line to system.properties file (lives in the /bin folder of your JMeter installation)
webdriver.firefox.bin=/path/to/your/firefox.exe
See https://code.google.com/p/selenium/wiki/FirefoxDriver page for other Firefox-related properties
locate all duplicate http* libraries like httpcore*.jar httpmime.jar etc. and remove the ones with lesser version
restart JMeter to pick the property and the changes up
Check out The WebDriver Sampler: Your Top 10 Questions Answered guide for other tips and tricks

You need to make sure you provided the full path of the Firefox driver in the jp#gc config element.

Related

How to choose which monitor Robot Framework will display test execution?

I'm currently working with 2 monitors, and I've noticed that Robot Framework (using SeleniumLibrary) always open the test execution in the main display that is selected in windows display settings.
Is there any way to choose which monitor will be used to display test execution?
This is how I'm starting the browser. I'm currently using Chrome
Start Browser
Open Browser ${url} ${BROWSER}
... options=add_experimental_option("excludeSwitches", ["enable-logging"])
Maximize Browser Window
Ragnoroct's answer here seems to be a solution: https://stackoverflow.com/a/57545639/16635196.
Chrome has a command-line switch for window position
--window-position=x,y
https://peter.sh/experiments/chromium-command-line-switches/#window-position
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('window-position=2000,0') # opens at x=2000,y=0 from the start
driver = webdriver.Chrome(options=options)
Since I was not using Python directly in the Robot tests, I resorted to directly modifying the Python package source where these options are set. For example, AppData\Local\Programs\Python\Python310\lib\site-packages\QWeb\internal\browser\chrome.py for combination of QWeb and Windows10. Obviously not a good way of doing things in the long run, but virtual environment could be of help here.
Start-maximized didn't work in conjunction with window-position, so I had to additionally use window-size=2560,1440.

Selenium Tests for Internet Explorer doesn't executs properly through Jenkins

We have our Health Check automated wherein all of our applications are logged onto, all via Selenium and only on Internet Explorer.
The code runs well when it was executed directly from a batch file. However, when Jenkins calls this batch (.bat) file, it doesn't execute it completely.
BTW the platform is Windows Server 2008 R2 Standard
This is the .bat file code
#echo off
set path="";
set path="E:\XXXX\jre1.8.0_141\bin";
pushd E:\Jenkins_Softwares\SeleniumCode\HealthCheck_jar
SET JAVA_OPTS=-Xmx4g -Xms512m -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=128m -XX:MaxHeapSize=512m
java -jar HealthCheck_JenkinsNG.jar
I've added these additional IE options in the JAVA code before launching the IE driver.
InternetExplorerOptions options = new InternetExplorerOptions();
options.introduceFlakinessByIgnoringSecurityDomains();
options.enableNativeEvents();
options.destructivelyEnsureCleanSession();
When Jenkins executes the batch file, the IE browser opens into the Login page. There's something odd when this page is displayed - the entire page alignment is disrupted and all elements get aligned to the left. (I'd like to stress that when the batch file is instead executed directly, there is no such page alignment disruption. The elements retain their original centre position. For some reason, Jenkins sets all of this to the left). The alignment is not exactly a deal breaker for me.
However, when username and password is entered via the Selenium code, it types into the perfect text boxes; but when the submit button is hit, the content in these textboxes turn blank and I'm unable to login. (When this same piece of code is executed via running the batch file directly, I'm able to login and The homepage of my application is displayed)
I doubt if there's something wrong with the selenium java code. Since, it executes properly, when run from the .bat file or even command line or even as a Java Application from an IDE.
For some reason, when this is executed from Jenkins it does not work.
Is there any options or settings that needs to be set when Jenkins works with Selenium on IE 11? Because I've tried tweaking the selenium code so much, they all yield the same result - The elements on the Login page get cleared after the submit button is clicked.
Also, just to mention, all of this is run on one Master node of Jenkins only. There are no slave nodes.
You need to take care of a couple of things as follows:
For the build process Jenkins would need the path of jdk. Simply jre may not suffice.
JDK 8u141 is ancient now and you need to upgrade to latest JDK 8u202
introduceFlakinessByIgnoringSecurityDomains() (in Java) and IntroduceInstabilityByIgnoringProtectedModeSettings() (in DotNet) is not an ideal solution to address the issues croping out of Protected Mode settings.
Here you can find a detailed discussion in Internet Explorer Protective mode setting and Zoom levels
To work with Selenium, InternetExplorerDriver and InternetExplorer you need to fulfill the Required Configuration

Starting protractor execution from a selenium session

How can we use protractor with an existing selenium browser session rather than always create a new one. If I have started up a selenium browser session, run some tests in there, and exported the session ID into the environment conf file in protractor or in some other way made it available, it would be nice to be able to configure protractor in the normal way (e.g. using an option in the protractor configuration file) to access this session.
I would need to start a protractor execution in the middle of a selenium execution, do some test, and come back to selenium execution. Something like pseudo-code snippet would really help.
You'll need to session id from the launched browser. You should be able to get it from the http://localhost:4444/wd/hub/static/resource/hub.html. So let's say this session id is '12345', you have two options, you could pass it as a command line or via the configuration file.
command line
protractor protractor.conf.js --seleniumSessionId=12345
configuration file
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumSessionId: '12345',
...
}
After you have set the selenium session id, you should be able to use the browser session. An example of this being exercised is: https://github.com/angular/protractor/blob/master/scripts/driverProviderAttachSession.js
If you would like to read more about it, I also have a medium post about this feature that I might have worked on: https://medium.com/#cnishina/attaching-a-protractor-test-to-an-existing-selenium-session-931196936ae2

Is it Firefox or Geckodriver, which creates "rust_mozprofile" directory

Whenever we invoke Firefox, under '/tmp' directory rust_mozprofile directories are getting created. As Firefox internally calls Geckodriver we are not sure whether Firefox or Geckodriver is creating rust_mozprofile directory.
I do want to know whether Geckodriver or Firefox because, my '/tmp' directory is having less memory.
So the question is I really want to modify the path of creating directories for rust_mozprofile.
I am using below technologies,
Selenium - 3.3.0
Firefox - 52.2.0
Geckodriver - 13
Please give us some suggestion, if there is any.
If you have a closer look at the geckodriver v0.18.0 logs closely you will observe the very first occurrence of rust_mozprofile occurs in the following line:
1504762617094 Marionette CONFIG Matched capabilities: {"browserName":"firefox","browserVersion":"56.0","platformName":"windows_nt","platformVersion":"6.2","pageLoadStrategy":"normal","acceptInsecureCerts":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"rotatable":false,"specificationLevel":0,"moz:processID":5848,"moz:profile":"C:\\Users\\AtechM_03\\AppData\\Local\\Temp\\rust_mozprofile.OfFuR9ogm33d","moz:accessibilityChecks":false,"moz:headless":false}
This log clearly indicates that marionette is being configured with:
"moz:profile":"C:\\Users\\AtechM_03\\AppData\\Local\\Temp\\rust_mozprofile.OfFuR9ogm33d"
And this configuration is done by the WebDriver instance i.e. the GeckoDriver.
It's the GeckoDriver which internally configures the Marionette which in-turn initiates the Mozilla Firefox Browser.
IMO, this workflow is in practice since we migrated from the Legacy Firefox to Marionette based Firefox. Hence the same must be the case with Geckodriver - 13 as well.
Update:
GeckoDriver as an application/exe file:
You can set the location with the TMPDIR envvar. It's also useful to set both TMP and TEMP for other programs.
A solution is to use driver.quit() this closes all browsers and takes care of the profiles
Another solution is to add a custom profile
fp = webdriver.FirefoxProfile('specify location to profile .default')
driver = webdriver.Firefox(firefox_profile=fp)
I had a similar problem and I solved it by changing the Environment settings in Windows. Meaning that I changed the directory for the TMP and TEMP files, and after a reboot, the rust_mozprofile folder was generated where I wanted it.
This is the source I used: https://www.toolsqa.com/selenium-webdriver/how-to-use-geckodriver/ Specifically the "Set property in Environment Variables:-" section.
Sadly this will effect all Software that saves files to those folders. (In my case that is what I wanted though.) If there is a way to make only the rust_mozprofile folder be created in a specific directory through the program, I would love to learn more.

Where do I see what firefoxdriver selenium starts while testing?

I have installed firebug for FF. But when i start firefox it always starts some default ff version, i dont' know where selenium finds it.
I already googled alot, tried to use different firefoxbinary:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
final File firefoxPath = new File(System.getProperty("webdriver.firefox.bin")) ;
FirefoxBinary firefoxBinary= new FirefoxBinary(firefoxPath);
firefox = new FirefoxDriver(firefoxBinary,null);
I tried to use different ff profile:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.9.1");
Alas, it does not work!
1. I don't know where to change/find webdriver.firefox.bin
2. I have tried changing path as environment variable,still no progress
maybe I m doing something wrong?
By default, Selenium will open a "vanilla" Firefox profile. If you want to have it launch with your profile, you can do that, but you have to select which profile you want to use. I will warn you that you often don't want to have your regular profile used because you'd like a clean, consistent working environment.
But you could certainly:
set up a profile (call it, for instance, selenium-profile using
Firefox's profile manager
run Firefox choosing that profile--from
Windows's Run dialog run "c:\Program Files(x86)\Mozilla
Firefox\firefox.exe" - P" or the equivalent path to FF if you are
32-but.
install Firebug using that profile.
then choose that profile when you launch your tests.
For information about how to do all this, look at this article.
Then, in your code, you can just call that profile. Step 3 in the article linked above shows how to do this.
Firefoxdriver starts a new default profile on each instance and this profile will be created in your temp folder and will be deleted after you quit the driver. There might be some old instances of ff profile which contains older version of firebug in your temp folder which might be not be deleted as webdriver quited unexpectedly.Try clearing your temp. It might help you as it did for me.