How to set System property in JMeter selenium? [duplicate] - selenium

This question already has answers here:
How to create and run Apache JMeter Test Scripts from a Java program?
(5 answers)
Closed 2 years ago.
Im Using Selenium with JMeter's WebDriver Sampler and I want to test my app in Internet Exoplorer buy when I run it I got this error:
java.lang.IllegalStateException: The driver executable does not exist: C:\Users\PNB01\Desktop\JMETER\apache-jmeter-3.3\bin
And this is my script in WebDriver Sampler:
System.setProperty("webdriver.ie.driver", "C:/IEDriverServer.exe");
WDS.sampleResult.sampleStart()
WDS.browser.get('http://www.google.com')
WDS.sampleResult.sampleEnd()

You have at least 3 ways of setting a JMeter Property:
Add the relevant line to system.property file (lives in the "bin" folder of your JMeter installation)
webdriver.ie.driver=C:/IEDriverServer.exe
JMeter restart will be required to pick the property up
Pass it to JMeter startup script via '-D command-line argument` like:
jmeter -Dwebdriver.ie.driver=C:/IEDriverServer.exe -n -t ....
If you want to run JavaScript in Java you need to provide the full package name of System class like:
java.lang.System.setProperty('webdriver.ie.driver', 'C:/IEDriverServer.exe')
References:
Configuring JMeter
Apache JMeter Properties Customization Guide

Some encoding issue. I guess you have copy pasted the code from google.
Tip:
Copy the code to some text editor and then copy paste the code to eclipse.
If you are using eclipse use this command to change the encoding/format and it will work fine.
command 1: crtl+a (to select all)
command 2: ctrl+shift+f (to change the format to uft8 encoding)
Hope this helps. thanks.

Related

Running a single .feature file [duplicate]

This question already has an answer here:
Unable to use read('classpath:') when running tests with standalone karate.jar
(1 answer)
Closed 1 year ago.
I'd like to run a single .feature file, the one I'm trying to debug, instead of the full set of over 100 tests we have... it it possible?
I'v tried adding the "classpath" to the karate options, as I saw in other answers, but it still runs everything even if the path doesn't exists:
$ mvn clean test \
-Dtest=ParallelTest \
-DargLine="-Dkarate.options='--tags ~#ignore classpath:relative/path/to/my/new.feature" \
-Denv='dev'
This is what the IDE support is for, we have Visual Studio Code (recommended), IntelliJ and Eclipse: https://github.com/intuit/karate/wiki/IDE-Support
If you are interested in the details, there is a "CLI way" to do this (0.9.5 onwards): https://github.com/intuit/karate/wiki/Debug-Server#maven - so just put a feature classpath: instead of the -d
And for Maven / JUnit users, most teams write a "Runner" class, and you can add a test method and run a single feature, please refer to the docs: https://github.com/intuit/karate#junit-5

How to get rid of the BrowserStack Local extension popup using ChromeDriver Chrome and Selenium

Am just new to automation and trying to automate browserstack. And i successfully logged to browserStack and passed the credentials and clicked on adding chrome extension . There comes the popup and am unable to get the selector for the buttons in the popup.Did any body face across this issue.
Am using an internal tool to automate,behind the scene i guess its using selenium.
Can anybody help me to find the selectors for the popup in browser stack.
Will attach the screenshot
Any help will be hihly helpful,since its a big blocker for me
If you want to Automate a local hosted URL or internal URL you will have to use BrowserStack Local testing feature. There is no need to add this extension.
There is one documentation on How to Perform local testing. All the steps are mentioned in the documents.
BrowserStack Automate Local Testing
If your usecase involves adding the BrowserStack Local or any other extension as a part of your Test Strategy you need to do it programatically.
You can find a couple od relevant discussions in:
How to install extension permanently in geckodriver
How to load extension within chrome driver in selenium with python
Alternative
As an alternative you can enable Enabling Local Testing either programatically through language bindings or through the command-line interface as follows:
Using language bindings:
Java:
import com.browserstack.local.Local;
# creates an instance of Local
Local bsLocal = new Local();
# replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
HashMap<String, String> bsLocalArgs = new HashMap<String, String>();
bsLocalArgs.put("key", "<browserstack-accesskey>");
# starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs);
# check if BrowserStack local instance is running
System.out.println(bsLocal.isRunning());
#stop the Local instance
bsLocal.stop();
Steps for using command line:
Download the matching binary for your os: OS X / Linux 32 bit / Linux 64 bit / Windows
Untar/Unzip the binary to a folder/directory on your system.
Open your command-line interface and navigate to the folder containing the Local binary.
Run the binary using the following command:
//OS X/Linux
./BrowserStackLocal --key ACCESS_KEY
//Windows
BrowserStackLocal.exe --key ACCESS_KEY
Configure tests to run with Local Testing connection as follows:
caps.setCapability("browserstack.local", "true");

JMeter with Webdriver Sampler - Browser window not opening

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.

selenium RC and Flow control

Currently I am working on selenium IDE, now I need to switch to selenium RC. I have downloaded selenium server.But I really don't know how to proceed further. Even I am not able to start server from command prompt. I have used C:\Selenium RC\selenium-server\jave -jar selenium-server.jar, but it struck in between and not proceeding further..
I am looking for language java or PHP.
Let me know how should I move further for successful execution of scripts by using selenium RC
First of all: save a test suite in Selenium IDE (File > Save Test Suite). You should generate test suite - it will contain information about test cases (which, of course, should also be saved (File > Save Test Case)).
Then you are ready for testing with Selenium RC.
Try it with below command:
java -jar path/to/selenium-server-standalone.jar -htmlsuite "*firefox" "http://google.com" "path/to/your/testsuite1" "path/to/result.html"
result.html - this file will be generated during/after execution.
Be sure that name of browser, URL and paths to test suite and result file are in the quotation marks.
I am using Selenium with PHPUnit. I have got class called, lets say, somethingTest (test classes must have 'Test' at the end of their names) and extended PHPUnit_Extensions_SeleniumTestCase. This class contains several test cases as methods (e.g. function testSomeMethod1() - 'test' at the beginning).
And I run it by command:
phpunit somethingTest.php
As to the second thing:
Unknown command: gotoIf
You should load gotoif extension by adding to the execution command something like: -userExtensions path/to/extension-file
This indicates a JavaScript file that will be loaded into Selenium.
If you choose Java to write code, a better approach would be using an IDE like Eclipse. Once you link the JARs and import them in your Java classes you can write your code quickly and efficiently. On top of that, Ecplise has lot of plugins for testing software like Junit, TestNG's to help you create better test suites. Not to mention a Java IDE is always helpful in debugging test code. Here is a tutorial on how to setup Eclipse with Selenium: http://selftechy.com/2011/05/31/setting-up-selenium-with-eclipse
Hope it helps.

Selenium: How to read values from any file (text, excel or csv)?

Some of my project data needs to be changed every time i run the script. In order to have automated system i require to read values from any file and send its data as input to selenium script.
If you are using Selenium IDE, export your script to JUNIT ( java), then create a java project using that java file, then download the Selenium server library (jar file) and add to your project. then start the selenium server and run your script it should run successfully.
If it is working then you can simply use a java code to read files and set the values in the relevant places in your code.
ex: if you are using excel you can use jxl.jar library
You may refer my blog for more details. http://hrftools.blogspot.com/
From your description, it seems like you need to run the selenium script for different values and values have to be read from a file. You can use testNG's dataprovider to achieve this very easily.