I'm using cucumber-jvm , and trying to implement global #After method which should be executed only once after all scenario's execution was completed.
The #After method should quit the appium driver.
Currently #After hook being executed after each running scenario , and it means that the driver should be created each time from scratch , but I do want to reuse it.
Any help will be much appreciated
You can try using QAF which support Gherkin, where driver management is taken care by the framework. It is dedicated framework built upon TestNG for web, mobile web, mobile native, and webservices functional test automation.
When using QAF you don't need to write any code to setup/teardown driver. You can configure as per your need through testng xml configuration file and properties. You can specify behavior by using property selenium.singletone. For example:
#will reuse driver session for close browser after all testcase configured under xml test node
selenium.singletone=true
#will teardown after each scenario/testcase
selenium.singletone=Method
#will reuse driver session for group
selenium.singletone=Groups
If you are running in parrallel it will you can have driver session sharing between test running in same thread. All combinations you can achieve through execution configuration.
Moreover, you can use all TestNG listener and annotations. For example:
#BeforeMethod:Invokes Before each Testcase/Scenario
#BeforeSuite: Invokes once before entire suite
#BeforeTest: Invokes once before each xml test node for each xml test node in configuration
#BeforeGroup: Invokes once before starting execution of test in group for each group
#AfterSuite: Invokes once after entire suite
#AfterTest: Invokes once after entire xml test node
#AfterGroup:Invokes once after all test in group for each group
#AfterMethod:Invokes after each Testcase/Scenario
Refer Gherkin with QAF
Related
I've created a few tests for my project, some test need to be run async while others can run sync.
Currently the config file is set to run async.
I've set a test file which runs them in the correct order. I've imported all the tests that should run sync into a single file. And tried adding
test.describe.configure({ mode: 'parallel' })
This changes the whole test process to run in parallel.
I can't seem to find any documentation on how to only execute certain test async and other sync. Does anyone have experience with this?
The reason I need it to run async for certain files is to log in and authenticate before continuing, also certain actions affect the layout of the whole UI (even in a different browser) and will mess up other tests screenshots.
PW runs all test in parallel by default. But there are options to serialize tests per file. You cannot have both paralel and serial tests in one file.
https://playwright.dev/docs/test-parallel#serial-mode
As far as I know, JMeter allows you to send multiple POST request with different parameters (e.g. { "value": "value1"}, {"value": "value2"}, ...) However, I'm more comfortable using a terminal-based interface similar to ab or siege. Basically, I need to load test a server simulating the case in which some requests are not previously cached.
Are there alternatives to JMeter for Linux that are able to use different parameters for a POST request?
UPDATE
As far as I can tell, JMeter requires the creation of a test plan (jmx file) in order to run via the command line. Unfortunately, this test plan needs to be built using the GUI, which is precisely what I want to avoid.
UPDATE 2
I will use JMeter because it offers dynamic parameters for POST requests and most alternatives depend on JMeter. However, if anyone knows of a standalone library that works exclusively from the terminal (similar to ab), please let me know.
you can use JMeter in terminal mode, it's called Non GUI mode.
To variabilize just use CsV dataset to load variables (varName for example )per thread, then use ${varName}
See :
http://jmeter.apache.org/usermanual/get-started.html#non_gui
http://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config
Nice report at end:
http://jmeter.apache.org/usermanual/generating-dashboard.html
If you don't want to use GUI even for building the test, then look at :
https://github.com/flood-io/ruby-jmeter
It allows you to generate the JMX from a DSL file.
Examples here:
https://github.com/flood-io/ruby-jmeter/tree/master/examples
DSL here:
https://github.com/flood-io/ruby-jmeter/blob/master/lib/ruby-jmeter/DSL.md
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'ruby-jmeter'
test do
csv_data_set_config name:'MyCsv', filename: '/path to file', variableNames: 'myParam'
threads count: 10 do
visit name: 'Qwant Search', url: 'https://lite.qwant.com/?q=flood.io&t=web&p=${myParam}'
end
end.jmx(file: "path to your output plan")
Save file to ruby-jmeter-csv.rb
You can then generate the plan with:
ruby ruby-jmeter-csv.rb
And run it in non gui mode.
In fact JMeter GUI should be used for tests development and debugging only, when it comes to running the load test - it is recommended to run JMeter in command line mode, via Ant task or Maven plugin. Also there is a couple of more "geek" alternatives, i.e.:
JMeter .jmx scripts are basically XML files so you can use your favourite text editor to create or amend them
You can use JMeter API to create and kick off JMeter tests using Java language
If you're still looking for an alternative, here are few free and open source load testing tools
Grinder - you can write scripts in Jython
Gatling - you can write scripts in Scala-based DSL
Tsung - this guy exists for Linux and Unix-based platforms only, Erlang-based. Scripts are XML files.
Taurus - automation framework which supports all aforementioned tools (and some more), Python based, configuration files have simple YAML syntax.
See Open Source Load Testing Tools: Which One Should You Use? for more information on the above tools and comparison of them with JMeter
I'm working on a service class that needs to process some sort of data payload. In my automated tests, I'm adding some mock data to check the behavior of the service for different inputs. I need to extract these mock data to several files so I can reuse them for other tests. Where do I put such file in a Grails (2.4) app? By convention, most Java projects have src/test/resources for the purpose, but Grails doesn't seem to consider that.
If you are writing unit tests you can put them under test/unit/resources and if you are writing integration tests you put them under test/integration/resources.
I'm new to JMeter and Ant and my web searches have not been fruitful so I'm posing a question here: Is it possible to start and stop a JMeter script using Ant?
Here's what I'm trying to do:
I have a JMeter test plan with a loop in it that is to simulate a user (or several users) sitting on a page for an indeterminate amount of time after a page refresh. In JMeter GUI mode, I can schedule the thread group to spin up users at a specified time and continue doing so for a specified duration. I'd ideally run this script for 45 minutes or so, stop the script and analyze the results. I would like to automate the running of this script and Ant seemed like the way to go. I did not see an appropriate property to specify a start time or a duration when running the script. Does such a thing exist? Is there a suitable workaround? Any help that can be offered is greatly appreciated.
There is a JMeter Ant Task available. You can kick off your Test Plan using this Task according to documentation.
For 45 minutes test duration I would go for the following:
<jmeter
jmeterhome="/path/to/your/JMeter/installation"
testplan="/path/to/your/test/plan.jmx"
resultlog="/path/to/your/test/results.jtl">
<property name="duration" value="2700"/>
</jmeter>
And put ${__P(duration,)} into Thread Group Scheduler's "Duration" input field
Once you start Ant JMeter will pick up that "duration" property and ask threads to stop when 2700 seconds (45 minutes) pass. Remember that in case of high number of threads shut down process may not be immediate as JMeter might need some time to gracefully shut down all the test threads.
For detailed explanation on using JMeter Ant Task and few more options of running tests in non-GUI mode see 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide.
From what have you written I think you want to schedule a test from non-gui mode and control the parameters also. I am not sure about ant but we have workaround.
For this you can use JMeter non-gui features
If you want to start a test then you can use
Jmeter.bat/.sh -n -t
You can stop the test using stoptest.bat/.sh and shutdown.bat/.sh at any time (Maybe a wrapper shell/batch script can help you to automate this)
For specifying parameters you can override the existing parameters by specifying them from command line as properties local/global like,
-D[prop_name]=[value] - defines a java system property value
-J[prop name]=[value] - defines a local JMeter property
and use these properties in your test plan so that you can pass values while running the test for a specific amount of time or infinitely and stop the test in between (like you said after 45 min) using stoptest.bat/.sh
Example,
In Thread Group set Number of Threads to ${__property(users,,)} and specify it from command line as,
jmeter -Jusers=50 -n -t Test_Plan.jmx
Remember this local property and not global.
For using properties and non-gui mode you can refer this, Jmeter Manual
My goal is to write test for my own Grails plugin. steps taken so far:
Step - Create separate grails app (in our case, testApp) inside
the Grails Plugin 'test' folder
Step - Make the plugin to be
inline for the application - testApp by adding following Line in BuildConfig.groovy
grails.plugin.location.PluginName = '../../../../PluginName'
The issue is that in the Unit test, the Service (from the inline plugin) are not injected like it is for regular app in Unit Test. Here is sample test:
#TestFor(SampleService)
class SampleServiceUnitSpec extends UnitSpec {
def "Sample Test"(){
setup:
def test = 'ok'
when:
test = "changed"
then:
assert service
assert "changed" == test
}
}
The service is injected if this test is run from grails app and service is part of the app. The service is not injected if this test is run from the testApp with inline plugin containing the service. The service is not injected if the test is plugin unit test and the service declared in the plugin.
How to inject service so it can be tested? Any good docs,posts.etc on how best test Grails plugins? Thank You
Why you want to create a unit test for your plugin service inside an application. Shouldn't be better your application just worry with his own code?
I suggest you to separate your concerns: plugin classes should be tested in the plugin, and application classes in the application. For the point of view fo the application, assume that your services "should just work", because they are well tested in the plugin.
Also, I advise against creating an application inside your Grails plugin. The test folder is used only for your test classes and nothing more.
If you want to maintain only the last version of your plugin, you can create just one application (in another folder, outside your plugin) and always update there.
If you need to maintain more than one version, or more than one Grails version, then maybe a Groovy script that create your test application with an specified version will be a better approach.