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
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 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.
I'm currently running a script to pull data from Google Analytics with googleapiclient Python package (that is based on httplib2 client object)
--> My script works perfectly without any proxy.
But I have to put it behind my corporate proxy, so I need to adapt my httplib2.Http() object to embed proxy information.
Following httplib2 doc 1 I tried:
pi = httplib2.proxy_info_from_url('http://user:pwd#someproxy:80')
httplib2.Http(proxy_info=pi).request("http://www.google.com")
But it did not work.
I always get a Time out error, with or without the proxy info (so proxy_info in parameter is not taken into account)
I also downloaded socks in PySocks package (v1.5.6) and tried to "wrapmodule" httplib2 as described in here:
https://github.com/jcgregorio/httplib2/issues/205
socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, "proxyna", port=80, username='p.tisserand', password='Telematics12')
socks.wrapmodule(httplib2)
h = httplib2.Http()
h.request("http://google.com")
But I get an IndexError: (tuple index out of range)
In the meantime,
When I use the requests package, this simple code works perfectly:
os.environ["HTTP_PROXY"] = "http://user:pwd#someproxy:80"
req = requests.get("http://www.google.com")
The problem is that need to fit with googleapiclient requirements and provide a htpplib2.Http() client object.
rather than using Python2, I think you'd better try using httplib2shim
You can have a look at this tutorial on my blog :
https://dinatam.com/fr/python-3-google-api-proxy/
In simple words, just replace this kind of code :
from httplib2 import Http
http_auth = credentials.authorize(Http())
by this one :
import httplib2shim
http_auth = credentials.authorize(httplib2shim.Http())
I decided to recode my web app in Python 2, still using the httplib2 package.
Proxy info are now taken into account. It now works.
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