Sunday, January 25, 2015

GIT Cheat Sheet (most useful GIT commands)

Here actually first post for memory and besides of that fact that there're dozens resources about GIT commands in Internet I'd like to have my own place for them.

1. GIT installation for Windows: 

2. GIT installation for Linux: 
         apt-get install git-core

3. GIT installation for OSX: 

4. Setting up user preferences (name, email)
git config --global user.name "Your Name"
git config --global user.email "Your Email"

5. Init repository
        git init
     git clone “url” (this will clone repo from remote)

6. Add remote repo
        git remote add “url”

6.1 View remote repo
        git remote -v

6.2 Remove remote repo
        git remote rm origin

7. Check status
        git status
     git remote show origin (shows remote repo)

8. Get changes from remote
        git fetch (obtains changes but doesn’t merge them automatically)
        git pull (obtains and merges changes)
        git merge origin/master (only merges previously fetched changes)

9. Add files to commit
        git add “filename”
git add –all
git add .

10. Commit changes
        git commit –m “Commit message”
git commit --amend -m "Commit message/additional text"

11. Submit changes to the remote
        git push origin master
     git push origin “Branch name” --force

12. Create and switch on new branch
        git checkout –b “Branch name”

13. Merging branches
        git merge “Branch name” (merges current branch with desired one)

14. Rebasing
        git rebase “Branch name” (rebasing changes from desired branch with current one)

15. Reverting changes
git revert HEAD
     git revert HEAD --hard

16. Removing files from repo
        git rm “File name”

17. Check logs
git log --pretty=oneline
git log --pretty=oneline --max-count=2
git log --pretty=oneline --since='5 minutes ago'
git log --pretty=oneline --until='5 minutes ago'
git log --pretty=oneline --author=<your name>
git log --pretty=oneline --all
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
git log --author="Author name"

18. Creating aliases (You can just put those changes into .gitconfig file)
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'

19. See complete list of files in repo
git ls-tree -r "Branch name" --name-only

20. See complete list of changes for file in repo

git annotate -- "whole path to file including file name"

21. Deleting branch
git branch -D "Branch name"
git push origin --delete "Branch name"

This pretty much it for most interesting and important GIT commands as for me.

P.S. I'll add commands for "cherry picking" and some other later. 

Sunday, January 18, 2015

Your First Test with Sikuli + Java + WebDriver + Maven in IntelliJIdea


It's Sunday so good time for something new and today we'll check out Sikuli, definitely not the newest solution but yet pretty handy and useful one. As usually we start as average user - from setting up environment till writing code in IDE and actually running that.

1. Installing Sikuli.

First we have open: http://www.sikuli.org/download.html - and download setup.jar on our PC. As suggested on screen below we have to save it in folder named SikuliX and run. If You're getting errors it means something wrong with Your java installation (which is needed) in this case I'd recommend You to look into steps I & III from: http://tech-memories.blogspot.com/2014/07/you-first-test-in-java-vs-testng-vs.html.


During first setup run You'll see same screens as below so simply choose needed options and click setup. 





2. Creating first Sikuli script with Sikuli IDE.

After finishing Sikuli installation let's create our project with Maven (it should be installed after step III from instructions above). What You need just open in console some folder in which Your project will be created and run next command: "mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.testproject -DartifactId=FirstSikulliTest -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false" - that's it - Maven will create all what You'll need in future.
After that run siculi-ide.jar and save Your project in the same folder. After these two actions You should have same screen as one below. In case it's difficult - I'll add link for git repo with everything just ready for clone at the end of post.


This how main Sikuli window looks like during first run.


As for me Sikuli is pretty intuitive one and script creation process one of the easiest I ever seen. So You simply need to click on one option of the right panel, then Sikuli will prompt You to select area on the screen and will save a screenshot of needed element.


Here I'll just briefly describe test I've written (I won't go into details, because You can download that from repo, open in Sikuli and run by Your own).
Test Case:

- open firefox browser (You'll need to replace my firefox screens with Your own)
- go to allegro.pl (as always my favorite site for testing new tools)
- type in search bar - "laptop"
- choose sort by highest price
- choose first item
- add item to the bucket
- verify that Your bucket contains one item

As You can see test case is pretty straight forward but we don't need to create a complicated one to get familiar with Sikuli.


Once again - after replacing firefox screens save script and simply Run that.


You probably noticed and aware that such cases we can easily write in Java with WebDriver, by the way we can write our own code not just clicking in Sikuli itself using Jython (something like Java + Python). On the other side in real life there're several cases when WebDriver fails to solve our needs - and one of those - handling native system dialog windows, so here I'll show You how to combine WebDriver and Sikuli for such purpose.


3. Creating Java project with WebDriver + Sikuli combination.

Open IntelliJIDEA and import project(You should have that created from instructions described in previous step) as shown on screens below.





After importing project we have to open project settings and add "sikuli-java.jar" from installation folder to our classpath.


Now we can write a code. Again I won't explain all steps from code (cause it's on the repo as well) but I'll write a test steps for test scenario:

- open chrome browser (for browser start we're using WebDriver - so doesn't matter which You'll use, but don't forget to update needed screens for Sikuli)
- wait until pdf is loaded (I simply put delay here)
- press download button
- save book on desktop
- minimize all windows
- verify that book is saved to our desktop


As You can see process is pretty obvious and if something goes wrong - just try to check everything step by step from beginning (project definitely works for me) or just leave me a comment under post. Also You can look on Sikuli official page for more information (truly speaking their example doesn't work - or it's better to say doesn't described in the best way).

P.S. as promised github repo: https://github.com/operep/Sikulli_Test_Project.git . Enjoy!

Sunday, January 11, 2015

Your First Test with Galen + Java + TestNG

Today I'd like to introduce one interesting instrument for automation testing - Galen framework. Obviously it's probably not the most popular or the best one but I'm sure because of some special features it'll find it's own niche on the market.
No secret that we'll do everything from scratch, so let's try that out...

1. Galen installation

Simply go to http://galenframework.com/ and download zip with binaries on Your PC.


After downloading and extracting let's add that to the path variable just for future convenience.



After all preparations traditional check in console:


And that's all what we need for the start with first test.

2. Our first test with Galen.

Besides of Galen jar in the path variable we need spec file. So let's create one in our project (any folder You want) folder. To be honest till the end, some of next steps You can find on official Galen web page - I've just tried if that example really works. So let's create "home-page.spec" in Galen_Project folder. After creation just put the exact information from screen below and save that.


Now we need to try that test, so open console, go to the project folder and paste next command "galen check home-page.spec --url http://samples.galenframework.com/tutorial1/tutorial1.html --size 640x480 --htmlreport .", press Enter and see what happens. By default Galen uses Firefox browser and I didn't check other options (in any case later in ide during writing code You can choose any other browser). As You can see from screen below test fails and there's actually even information why, which is handy.


Let's modify a bit "home-page.spec" and try again.



Now it passes and if we'll check our project folder we can find a report which is built by Galen itself.



If we need to run several spec files we just put them all after check and before url.


Now in report we can see results for different spec files.




Looks pretty simple but lets put some more magic into it. I'm using IntelliJ IDEA (community which is free) so on the several slides below shown process of project creation.



As we don't use any of build tools here - we need to add Galen jar to build path of our project. Also if You don't have Your Selenium jar in the file path You should add that too.


Final project structure shown on next screen.


I won't be original about web page for our test it's going to be Allegro as usual (hopefully they won't be mad on me for that). So we need to create "allegro-home-page.spec" first and put some information about elements from original page. In my case I'll check header, input field for search  and main navigation menu. I won't describe details of that spec cause they're pretty straight forward but be sure that Galen could do much more, don't believe me? Check that out by Your own - http://galenframework.com/docs/reference-galen-spec-language-guide.


After spec file we're creating our test which is actually even more simple. So in our test file we just have to declare our Layout Report and after all checks pass it to the Report Builder which will generate report for us. Part of this code You can also find on official framework page. So lets run it.


After running we can open report which is in target/reports folder.


Galen creates simple but pretty attractive and informative report as for me. Here we can see all verification's we've done and in case of failure You'll see correct message related to that failed step.


I believe nothing to add for now beside of one short conclusion. This framework looks not really understandable from first time but it's still intuitive one so I didn't spend whole day for that. Also have to admit that we can't compare this instrument with WebDriver or another framework - but we can look on that from point of specific use - when we don't have our own matcher's for position or css checking. So no need to invent another bicycle - just add that to Your project and use where needed.

P.S. added project to the repo: https://github.com/operep/Galen_Test_Project.git, so You can simply clone that

Friday, January 2, 2015

Your First Performance Test With JMeter


If You ask 100 different testers if they know something about performance testing most of them will say: "Yes!". Probably half of that hundred has some experience with that. But propose them to sit next to the monitor and create a simple performance test from scratch and You'll be surprised.
That's why once again I want to put all stuff together and write simple post about creation performance test with Apache JMeter. So let's start...

1. Download and Installation process.
As usually we'll start from such basics steps. Simply go to:  http://jmeter.apache.org/download_jmeter.cgi and according screenshots below download and pack JMeter on Your PC.





After downloading and extracting You have to add JMeter to Your system path (if You don't know how to do that, please refer to one from mine earlier posts). Check if program is available from any folder.



2. Run JMeter & Create first test.

If You simply follow screens below one by one You'll succeed but I'd add some comments where needed.
So first screen You'll see when the program launches.



Here we're creating Thread Group which needed for our future test.


When Group is created select that and make it similar to screen. First parameter defines how many users we'll simulate, second - time period through which we'll make all users active. Scheduler allows us to schedule runs (for now You can leave default value that You'll get) and with last parameter we're telling how much we'll expect the test to be executed (so if test will lasts more then 60 seconds it'll fail).  


Then we're creating two listeners, we need them to display test results and Recording Controller for recording our test steps.




'Next we'll create HTTP'S Test Script Recorder it'll allow us to run a proxy and record script.


Now we're all set so let's configure and start proxy - please just follow screens below one by one during setup process.


Here we're telling that our browser has to use proxy for internet connection.



Point JMeter to the needed port and press Start and OK under notification message then.



Last step after we've started proxy we have to do is simply manually reproduce our test steps in browser. For this example I'm testing login for gmail, so test steps are the next:
- open gmail login page;
- provide credentials and click login;
- verify that we're in the inbox;
- log out.
Obvious question - "If we have only several steps, why we see so many requests? (see screen below)", the reason why: JMeter records ALL requests during PC - Server communication session.
When we're done with test steps - simply stop recording and manually remove redundant calls - You can check next screen, where I've left only 3 important calls.




Now we need to save our test somewhere and time to run.



Test passed and we can check results with tree listener or table one. I won't describe everything - You can explore results by Your own.



This part for geeks - we can run all our scripts without GUI through console - simply go into folder where our script saved and run the command from screenshot below. Last parameter is file for test results output.



This pretty much it for the first test with Apache JMeter, hope it'll be helpful and at least You won't be scared when it comes to face-to-face meeting with this instrument.