I want to open the incognito window in JMeter Webdriver sampler.Following is my code.How to open incognito browser?
var pkg=JavaImporter(org.openqa.selenium) //import java selenium package
var support_ui=JavaImporter(org.openqa.selenium.support.ui.WebDriverWait) //import WebDriverWait Package
var ui=JavaImporter(org.openqa.selenium.support.ui) //import Selenium Support UI package
var wait=new support_ui.WebDriverWait(WDS.browser,180)
WDS.sampleResult.sampleStart() //sample starting point
WDS.browser.get('${__P(application.url)}')
wait.until(ui.ExpectedConditions.visibilityOfElementLocated(pkg.By.id('pmj-login-btns')))
WDS.sampleResult.sampleEnd()
I think it is not possible without modifying the JPGC_ChromeDriverConfig plugin code. Atleast, I am not aware of it.
But, there is an option to use JSR223. Please check the below code:-
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized")
options.addArguments("--incognito");
System.setProperty("webdriver.chrome.driver", "D:\\Path\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
driver.get('http://jmeter-plugins.org')
Above will launch the browser in incognito and maximized mode.
Hope this help.
Related
I just upgraded to version 4.5.0 of WebDriver, using JMeter 5.5, and can't perform any actions.
Based on the official docs: https://jmeter-plugins.org/wiki/WebDriverSampler/
should be using like:
var pkg = JavaImporter(org.openqa.selenium) but I faced exception.
Is there any way how to resolve this exception, so I can use it for sendKeys or click actions?
You're using groovy as the language
JavaImporter object is specific for JavaScript
This mix of languages is not supported, you either need to switch to javascript in the "Language" dropdown or re-write your code in Groovy using import statement and replace var occurrences with def
Also according to Top 15 UI Test Automation Best Practices
NEVER use Thread.sleep() unless there are specific test requirements
so consider migrating to Explicit Wait instead
thanks # Dmitri T for your direction. Since javaScript is droppped after java15, here is some sample code that I found usefull using: Jmeter5.5 + Java17 + selenium version 4.5.0 + groovy as language
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
WDS.sampleResult.sampleStart();
WDS.browser.get("http://gmail.com/");
JMeterVariables vars = JMeterContextService.getContext().getVariables();
java.lang.Thread.sleep(3000);
def userIdElement = WDS.browser.findElement(By.xpath("//input[#id='identifierId']"));
userIdElement.sendKeys("gest#gmail.com");
java.lang.Thread.sleep(3000);
WDS.sampleResult.sampleEnd()
I am using jp#gc - Firefox Driver Config plugin to hit some URL and assert some element in UI.
But I am not able to launch firefox driver as I cant see an option to enable to run firefox as a headless browser .
JP#GC - WebDriver Sampler:
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait
def wait = new WebDriverWait(WDS.browser,5000);
WDS.sampleResult.sampleStart(); WDS.browser.get('https://google.com/'); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[#name='q']"))); WDS.sampleResult.sampleEnd()
How about checking Headless box in the jp#gc - Firefox Driver Config?
Going forward be aware that you can always bypass any JMeter limitation by implementing whatever you want/need using JSR223 Test Elements and Groovy language, example code to kick off a headless Firefox would be something like:
System.setProperty('webdriver.gecko.driver','c:/apps/webdriver/geckodriver.exe')
def options = new org.openqa.selenium.firefox.FirefoxOptions()
options.addArguments('--headless')
def driver = new org.openqa.selenium.firefox.FirefoxDriver(options)
driver.get('http://example.com')
log.info('Current page title: ' + driver.getTitle())
driver.quit()
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
I have Safari browser on Win with installed webdriver on it and following code in JSR223 for Safari:
import org.openqa.selenium.safari.SafariOptions;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.concurrent.TimeUnit;
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("userAgent", "vars.get("userAgent")");
Map<String, Object> safariOptions = new HashMap<>();
safariOptions.put("mobileEmulation", mobileEmulation);
SafariOptions safari = new SafariOptions();
options.setExperimentalOption("mobileEmulation", mobileEmulation);
SafariDriver driver = new SafariDriver(options);
driver.get("url");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath")));
driver.findElement(By.xpath("xpath")).click();
vars.putObject("driver", driver);
Error messages are folllowing:
Response code:500
Response message:javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script19.groovy: 2: unable to resolve class org.openqa.selenium.safari.SafariOptions
# line 2, column 1.
import org.openqa.selenium.safari.SafariOptions;
^
Script19.groovy: 3: unable to resolve class org.openqa.selenium.safari.SafariDriver
# line 3, column 1.
import org.openqa.selenium.safari.SafariDriver;
^
2 errors
Could you please help me to find, what I'm missing?
With regards to the error you're getting it seems that you don't have selenium-safari-driver under JMeter Classpath so you need to download the appropriate .jar, drop it to "lib" folder of your JMeter installation and restart JMeter to pick the library up.
With regards to your "Safari browser on Win" stanza, are you absolutely sure this is something you really want to be doing? Windows version of Safari EOL was in 2012 and I don't think you should be investing into automated testing of 8-years-old browser.
Going forward I think this line:
mobileEmulation.put("userAgent", "vars.get("userAgent")");
should look like:
mobileEmulation.put("userAgent", vars.get("userAgent"));
I also fail to see a valid use case for JMeter there, if you need to simulate different browsers doing a performance test - you can easily send the relevant User-Agent header using HTTP Header Manager and conduct the load using normal JMeter's HTTP Request Samplers and if you're just creating automated tests - you don't need JMeter at all
My Firefox recently got updated recently. My firefox version is 44.0.1. When I run a simple code as below in selenium webdriver, two tabs are opening in firefox. How can i get rid of the unwanted tab. I changed Firefox setting, but still two tabs are opening. one tab is a plain tab and the second tab is https://support.skype.com/en/faq/FA34612/what-is-the-skype-extension. How can I load my URL that I want to automate in a single firefox window. Do I need to change any firefox setting.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class Another {
#Test
public void tester(){
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://jqueryui.com/datepicker/");
}
}
Create a Firefox Profile and save it with name after making settings as per your requirement. Please call this profile in script.
Here is the steps to create firefox profile
Below is the script for example
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("CreatedProfile");
WebDriver driver = new FirefoxDriver(myprofile);
Thank You,
Murali
I am new to selenium. And I am trying to open multiple instances of firefox browser.
I am not using any Grid. And My selenium version is 2.47.1 and firefox version is 37.0.1.
Also, my browser is not closing automatically even I used quit()
Below is my code:
package TestAutomation;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestClassOpenBrowser {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
WebDriver d2 = new FirefoxDriver();
d2.get("http://yahoo.com");
d2.manage().window().maximize();
driver.quit();
d2.quit();
}
}
Keep in mind that version 2.42.0 was probably the last version of Selenium that really supported Firefox native events (for Firefox 31). Selenium 2.43 says it supports native events for Firefox32 but I don't think it really worked. In general, if you are running local Firefox instances, you want to be using Firefox 31 or Firefox31.0.6 , even if your on Selenium 2.47+ .
Also, if you are having trouble managing multiple driver instances, take a look at how I did it here (see the ShootoutSuiteTestBase.java
class) :
https://gist.github.com/djangofan/f5eda36f556fc55a5dcb
Tried with jar file version 2.45.0. it worked. Issue was in the latest jar files 2.47.1