In many cases test files are needed for software tester. Partially with specified file size. With a small set of commands, it is very easy to create these files. In order to check the generated file(s), you can use the following:
# Check file size
$ ls -lh test-file
# Determine file type
$ file test-file
# Display output one screen
$ less test-file
# or
$ hexdump test-file
Perl
# Example for 1.0K
$ perl -e 'print "a" x 1024' > test-file
# Example for 1.0M
$ perl -e 'print "a" x 1048576' > test-file
mkfile
# Example for 1.0K
$ mkfile 1k test-file
# Example for 1.0M
$ mkfile 1m test-file
dd
# Example for 1.0K
$ dd if=/dev/zero of=test-file bs=1k count=1
# Example for 1.0M
$ dd if=/dev/zero of=test-file bs=1m count=1
base64
# Example for 1.0K
$ base64 /dev/urandom | head -c 1024 > test-file
# Example for 1.0M
$ base64 /dev/urandom | head -c 1048576 > test-file
Testing RESTful application is very simple with jMeter. In the first part of the tutorial in this series, the basics are shown. As requests can be created and evaluated. The request going to http://httpbin.org.
Preconditions
JAVA is installed
jMeter is installed
Steps
Create new “Thread-Group” on “Test Plan” (Add – Threads (User) – Thread Group)
Now add one “HTTP Request” inside the “Thread Group” (Add – Sampler – HTTP Request)
Inside the “HTTP Request” we add now a “HTTP Header Manager” (Add – Config Element – HTTP Header Manager). For configuring we add the Name/Value – “Content-Type”/”application/json”.
At the end we add the “View Results Tree” on “Thread Group” (Add – Listener – View Results Tree)
Our first request example will be a “GET”. On HTTP Request we add following values.
Server Name or IP: httpbin.org
Method: GET
Path: /ip
Implementation: HttpClient4
Follow Redirects: yes
Use KeepAlive: yes
After save we can start the first run. How to see result will show later. Now second request with POST example. For this we modify the HTTP Request with following values.
Method: POST
Path: /post
Send Parameters With the Request: {“firstName”:”harry”;”lastName”:”Hirsch”}
Include Equals?: yes
Now save and run again. On View Results Tree we can check the results for every http request (Sampler results, Request, Response data).
For the JSON response, switching from Text to JSON view. The same way can used for PUT, DELETE or other requests.
This tutorial shows a very simple Jenkins – jslint4java integration over Shell.
Preconditions
Jenkins is installed
Steps
Start Jenkins, open the browser (http://<host>:8080) and setup a new “Free Style Project” (JS-Lint-Example).
# start jenkins
$ service jenkins start
Back to Jenkins… here you create a “Freestyle-Project”
The tutorial does not use any VCS, so we press the “Build Now” button to create the project “workspace” folder. After successful creation, we create 3 new folders (src, lib, build) inside the workspace folder.
# create new folders inside the workspace
$ cd /var/lib/jenkins/workspace/JS-Lint-Example/
$ mkdir {src,lib,build}
# change owner of folders
$ chown jenkins:jenkins src/ lib/ build/
# upload jar to lib folder
$ scp jslint4java-2.0.5.jar <user>@<host>:/var/lib/jenkins/workspace/JS-Lint-Example/lib
# change owner and make executable
$ chown jenkins:jenkins jslint4java-2.0.5.jar
$ chmod u+x jslint4java-2.0.5.jar
It`s time to test if jslint4java is running. The 1st test can be done inside the terminal self.
$ java -jar jslint4java-2.0.5.jar --help
The 2nd test direct on Jenkins. Open the “JS-Lint-Example” job in browser – press link “Configure” and we create a “Build-Step” with “Execute Shell”.
After save and build the “Console Output” of the respective build should show the help. If there is a problem here, please check if Java is installed and the file permissions are correct. If everything works fine we create a simple JavaScript file and upload this into the “src” folder.
function myFunction(p1, p2) {
return p1 * p2;
}
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
};
test = myFunction(10, 10);
document.write('Hello World');
document.write(test);
document.write(person.firstName);
# upload example.js to src folder
$ scp example.js <user>@<host>:/var/lib/jenkins/workspace/JS-Lint-Example/src
Now we change the “Execute Shell” command and add the “Post-Build-Action” – “Publish JUnit Test Results” with value “build/js_report.xml”.
*** Settings ***
Documentation This is just a tutorial
...
Metadata VERSION 0.1
Library Selenium2Library
Suite Setup Start Browser
Suite Teardown Close Browser
*** Variables ***
${SERVER} https://www.google.ch
${BROWSER} firefox
*** Keywords ***
Start Browser
[Documentation] Start firefox browser on Selenium Grid
Open Browser ${SERVER} ${BROWSER} None http://127.0.0.1:4444/wd/hub
*** Test Cases ***
Check something
[Documentation] Check the page title
Title Should Be Google
Now start the Selenium Grid (Hub and Node)
# start the hub (in terminal 1)
$ java -jar selenium-server-standalone-2.44.0.jar -role hub -port 4444
# start the node (in terminal 2)
$ java -jar selenium-server-standalone-2.44.0.jar -role node -hub http://localhost:4444/grid/register
Note: The actual version for selenium-server-standalone may be different!
In the last step we start the test. Open a 3rd terminal, browse to the folder and start the Robot Framework.
# run pybot
$ pybot tutorial.robot
If everything works well, the output should look like this:
================================================================
Tutorial :: This is just a tutorial
================================================================
Check something :: Check the page title | PASS |
----------------------------------------------------------------
Tutorial:: This is just a tutorial | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
================================================================
Output: /output.xml
Log: /log.html
Report: /report.html
This tutorial should show, how easy it is to use the Robot Framework with PyCharm. After this small setup you can use PyCharm for your test automation with Robot Framework.
# check installed modules
$ pip list
# install Robot Framework (if not listed)
$ sudo pip install robotframework
# upgrade to the latest version
$ sudo pip install --upgrade robotframework
# verify installation
$ pybot --version
Configuration of PyCharm
Now start PyCharm and open “Preferences” – “Plugins”. Press “Browse repositories…” button and search for “Intellibot”. Press “Install plugin” button and restart PyCharm.
Now create a new directory “testsuite” with new file named “example.robot” inside and insert the following content.
*** Test Cases ***
Example action log this is a test
Open “Preferences” – “Tools” – “External Tools” and press “+” button. Insert a value for “Name”, enable checkbox “Open console”, insert “pybot” into Program, “test suite/” into Parameters and select you specific Working directory.
After press “OK” buttons, go to menu “Tools” – “External Tools” and select your given name. The output should show something like this:
Now we create inside the “testsuite” directory a file called “1st_test.robot” with following content.
*** Settings ***
Documentation This is a simple test with Robot Framework
Library Selenium2Library
*** Variables ***
${SERVER} http://google.com
${BROWSER} Firefox
${DELAY} 0
*** Keywords ***
Open Browser To Login Page
Open Browser ${SERVER} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
*** Test Cases ***
Valid Login Open Browser To Login Page
[Teardown]. Close Browser
After running the output should look like this:
/usr/local/bin/pybot testsuite/
=============================================================
Testsuite
=============================================================
Testsuite.1St Test :: This is a simple test with Robot Framework
=============================================================
Valid Login | PASS |
-------------------------------------------------------------
Testsuite.1St Test :: This is a simple test with Robot Framework | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
=============================================================
Testsuite.Example
=============================================================
Example action | PASS |
-------------------------------------------------------------
Testsuite.Example | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
=============================================================
Testsuite | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
=============================================================
Output: /output.xml
Log: /log.html
Report: /report.html
Process finished with exit code 0
var message = Device.isName();
UIALogger.logMessage("Name: " + message);
var message = Device.isSystemName();
UIALogger.logMessage("SystemName: " + message);
var message = Device.isSystemVersion(); UIALogger.logMessage("SystemVersion: " + message);
if (!Device.isIPad()) {
throw new Error("Test suite only works on iPad");
}