[main-sub projects][1][1]: https://i.stack.imgur.com/1YL97.jpg
As shown in the picture, I've created two JMeter projects (Main. JMX, Sub1.JMX). The main.JMX has a thread group (Subscription) that has include controller to run the Sub1.jmx project.
Sub1.JMX is created with a Thread Group (Subscription) and Test Fragment. All the reusable functionalities are added under the test fragment such as Sub1-Login, Sub1-Logout, and Sub1-close using the simple controllers. A test case (Test Case-1) is created under the thread group Subscription that is invoking Sub1-Login, Sub1-Logout simple controllers using module controller. The Sub1-close simple controller is not used in the test case.
When I run the Main.JMX, is executing the test case (Test Case-1), which includes login and logout and also remaining simple controllers from the test fragment (Sub1-close).
what is the best way to run only simple controllers (defined in the test fragment) referenced in the test cases?
JMeter's Module Controller runs a Test Fragment. Entire.
If you don't want to run a certain part of the test fragment you have 2 options:
Either put it under the If Controller and come up with a JMeter Function or Variable which will control whether it will be executed now or not
Or split your Test Fragment into 2 (or more) separate fragments and compose your "test case" from smaller parts .
Related
I would like to ask if we can also achieved a Page/Window Object Model in AutoIT? Majority of my project assignment was on Web Automation and I'm using Selenium Webdriver with Framework uses Page Object Model. Currently, I'm assigned to a project for GUI automation. I like to implement this kind of approach also in AutoIT if feasible so that I can reuse the objects to other classes. We are planning to use AutoIT standalone. I noticed that most of the example available in the internet was the object created on each class/script.
Your insights are highly appreciated.
Thanks!
General:
That common approach of using the Page Object Model (POM) Design Pattern isn't quit good feasible with AutoIt. Of course you can create a object structure with AutoIt too, but it was not intended for the language. Anyway, some of the goals of POM can be achieved with the following example suggestion of a test structure.
Please notice:
Since you don't provide enough information about your application under test (AUT), I explain a basic structure. The implementation depends on your application (SWING/RCP, WinForm etc.). It's also important which tool support do you need for your page object recognition. Besides WinForm that could be controled by ControlCommand functions in AutoIt, it's a proper way to use UIASpy or au3_uiautomation as helper tools.
UIASpy - UI Automation Spy Tool
au3_uiautomation
It's an advantage to know the POM structure in context with Selenium. I usually include a test case description with behavior driven development BDD (Gherkin syntax with Cucumber or SpecFlow), but this will not be a part of that example here.
Example structure:
The structure consists of two applications under test Calc and VlcPlayer. Both follow the common structure PageObjects and Tests. You should try to devide your page objects (files) in many subfolders to keep an overview. This substructure should be similar for the Tests folder/subfolders.
In the Tests area you could include several test stages or test categories depending on your test goals (Acceptance/UI tests, just functional smoke tests and so on). It's also a good idea to control the execution order by an separat wrapper file, TestCaseExecutionOrder.au3. This should exist for all test categories to avoid a mixing of them.
This wrapper au3 file contains the function calls, it's the processing start/control.
Approach description:
TestCaseExecutionOrder.au3
Calls the functions which are the test cases in the subfolders (Menu, PlaylistContentArea, SideNavigation).
Test case NiceName consists of some test steps.
These test steps have to be included into that script/file by:
#include-once ; this line is optional
#include "Menu\OpenFolder.au3"
Test step OpenFolder.au3 (which is a part of a test case) contains the function(s) to do the folder loading and there content.
In that functions the PageObject MenuItemMedia.au3 will be loaded/included into the script/file by:
#include-once ; this line is optional
#include "..\..\..\PageObjects\Menu\MenuItemMedia.au3"
File MenuItemMedia.au3 should only contain the recognition mechanism for that area and actions.
This could be find menu item Media (as a function).
or find open folder menu item (as a function) and so on.
Func _findMenuItemMedia()
; do the recognition action
; ...
Return $oMenuItem
EndFunc
In the test step OpenFolder.au3 which calls _findMenuItemMedia() like:
Global $oMedia = _findMenuItemMedia()
can a .click executed or something like .getText etc.
The test cases should only #include the files which are necessary (test steps). The test steps should also only #include the necessary files (page objects) and so on. So it's possible to adjust the recognition functions once and it can be used in the corresponding test steps.
Conclusion:
Of course it's hard to explain it in this way, but with this approach you can do a similar way like in Selenium for web testing. Please notice that you properbly have to use Global variables often. You have to be ensure the correct includings and don't lose the overview of your test, which is in OOP test based approaches much easier.
I recommend the usage of VS Code, because you can jump from file to file at the #include statements. That's pretty handy.
I hope this will help you.
I am using Jmeter and I saw simple controller and module controller and I could not understand the difference between them.
I tried adding them both but I don't know how to use them more efficiently.
Can anyone please help me?
Module Controller can be used to run other Logic Controllers, for example if you have a Transaction Controller which implements Login and you are creating a test assuming different groups of users which need to be logged in - you can call the aforementioned "Transaction Controller" using the Module Controller in 2 different Thread Groups instead of copying and pasting it.
See Using JMeter Module Controller article for more information.
Simple Controller actually does nothing apart from grouping Samplers. You might use Simple Controller in the Module Controller or apply a single Post-Processor, Assertion, Pre-Processor, etc. to all Simple Controller's children. Apart from these two use cases it doesn't add any value.
Simple Controller is just a container to group samplers in it and apply some scoping rules for example:
http://jmeter.apache.org/usermanual/component_reference.html#Simple_Controller
Module Controller is a way to reuse code accross your test:
http://jmeter.apache.org/usermanual/component_reference.html#Module_Controller
Module controller can be used to choose between Simple Controllers see example
Module controller will allow me to run only selected simple controller's requests.
I am working on a test plan for our REST web application and we have several common test types which have common criteria we want to test for. For example, when creating entities through the API we have a common set of expectations for the JSON response; id should be set, created date should be set, etc.
Now, I would like to model my plans like this:
Thread Group
Users (Simple Controller)
User Create Tests (Simple Controller)
Create Test 1 (Sampler)
Create Test 2 (Sampler)
Create Test 3 (Sampler)
Common Creation Asserts (Module Controller)
User Delete Tests (Simple Controller)
Samplers...
Common Delete Asserts (Module Controller)
Events (Simple Controller)
Event Create Tests (Simple Controller)
Samplers...
Common Creation Asserts (Module Controller)
Event Delete Tests (Simple Controller)
Samplers...
Common Delete Asserts (Module Controller)
Thread Group for common assertions (disabled)
Common Creation Assertions (Simple Controller)
BSF Assertion 1
BSF Assertion 2
BSF Assertion 3
Common Delete Assertions (Simple Controller)
Asserts...
Now, I understand how the scoping works and that if I placed assertions where the BOLDed module controllers are they would be invoked for each sampler. However, I'd rather not have to copy-paste-maintain numerous copies of the same assertions in each of these locations. Hence, why I want a way to define assertions once, and invoke where appropriate.
However, with this approach, the ACCENTed assertions placed in the common simple controllers are never invoked (confirmed by using a BSF assertion with logging messages). If I place an additional sampler in the common assertions simple controller it is invoked. But only a single time.
I'm using JMeter 2.12 but have confirmed that JMeter 2.8 behaves the same way.
So, how can I use JMeter to define assertions once, and re-use them anywhere?
Thanks!
There is no way to do this.
You can try factoring by using Variables within Assertions, thus if it's a Response Assertion you will factor out this.
I ended up getting creative.
Using JSR223 assertions in Javascript I've accomplished what I wanted. This is a natural fit because all the response data I want to test is in JSON, YMMV.
In User Defined Variables I define the tests I want to perform using Javascript.
Tests like:
TEST_JSON:
try
{
eval('var obj = ' + prev.getResponseDataAsString());
} catch(e)
{
setFailed();
}
TEST_RESULT_SUCCESS
if(obj.status != "success")
{
setFailed();
}`
Then in the assertion(s) I can do something like:
eval(vars.get("TEST_JSON"));
eval(vars.get("TEST_RESULT_SUCCESS"));
And I don't have to re-write tests over and over and over.
I even have some a some utility functions that I can add to my assertion by doing
eval(vars.get("TEST_UTIL"));
which allows me to print additional logging from my assertions if I desire.
I've used a Module Controller to invoke a Test Fragment. This is a great way to reuse Controllers and Samplers across multiple Thread Groups.
I have a set of about a dozen Extractors (CSS and RegEx) that I'd like to reuse for different HTTP Samplers. (The Samplers would be different, but the Extractors I'd run against each would be the same.)
Is there a way I can accomplish this?
You have 2 options:
You can use scopes if it applies , see http://jmeter.apache.org/usermanual/test_plan.html#scoping_rules
Otherwise put you CSS expressions in Variables and use them in extractor
I'm doing unit testing on a Zend Framework, and I'm presently testing functions in my model controller. At some point, one of the functions assigns:
Zend_Layout::getMvcInstance()->assign('var_name', $someVar);
Because I have not called any controllers or views, I am unsure of how to view this data. I'd like to keep things isolated so my unit tests remain properly contained. Is there any reasonable way to grab this variable without modifying the function I am testing?
For reference, I am using PHPUnit.
This should work:
$someVar = Zend_Layout::getMvcInstance()->var_name;