Modern Web architectures

25. Januar 2012

The most important thing about analyzing infrastructures or building web systems is to understand the underlying protocols. A good tool to learn http is the java dsc tool, which allows to send single http commands and look at their respond. Also you can put yourself in the role of the server. Authentication or caching are very useful, but often forgotten, features within http.

Client state vs. server state. Addressability, security, granularity, development time.

Optimizing.
You can use yslow as additional plugin for Firefox firebug to rate websites, the rating is splitted into different aspects like number of requests necessary.

Reverse cache is a very interesting solution to fasten up very big websites through caching on the server site.

Using sessions in web technologies is like using globals variables in other system. Almost every web application would run without any session states.

Notes from OOP 2012, talk by Stefan Tilkov

Test Design Methode

25. Januar 2012

If you are limited in time, what you always are, markov chains resulting in trees with percentages of usage, can help you to priorize parts of the system for testing.

Finding the right test cases is always a big problem. In the following an outline of methods, which can lead to an idea or directly to a test case:

Black box:
- requirement / use case based testing
- traceability matrix
- crud ( create read update delete
- flow testing, scenario testing, soap opera testing
- user / operational profiles, frequency and priority / statistical ( markov) – feature functions interfaces
- design by contract
- equivalence class partitioning , boundary value analysis
- classification tree method
- state based testing
- cause effect graphing
- decision tables, decision trees
- combinatorial testing ( orthogonal arrays, pair-wise, n-wise) – time cycles

Grey box
- dependencies relations between classes, methods or components, services, application, system – communication behavior
- trace or protocol based testing

White box
- control flow-based
- statements (c0), nodes
- branches (c1), transitions, links, paths
- conditions, decisions (c2,c3)
- elementary comparison mc/dci
- interfaces (s1,s2)
- cyclomatic complexity
- read / write acces
- def / use criteria

Positiv valid test cases vs. negative invalid test cases

Fault based testing including risks, attacks, errors, bug patterns and exploratory testing.

Also choose the right selection for regression testing.

Notes from OOP 2012, talk by Peter Zimmerer

Modern Web architectures

25. Januar 2012

Laden …

Hudson job running Selenium RC tests with TestNG Parameters

29. September 2011

I really can recommend to execute tests under the testng framework. It provides optional parameters and execution of test suites in an easily understanding way and allows to modify the style of the reports through a css file. Optional parameters also allows you to run tests within Eclipse without setting them (then the default value is used, see below)For my Tests I used a superclass containing the „setUp“ method, which is executed just before each testclass:

@Parameters({ "seleniumhost", "seleniumport",
"browser"})
@BeforeClass
public void setUp(
@Optional("localhost") String seleniumhost,
@Optional("4444") String seleniumport,
@Optional(SeleniumExt.FIREFOX) String browser){

As you can see the parameters „seleniumhost“ etc. are optional. If this one isn’t set, then the default value „localhost“ is used.

You want to insert all your testclasses into your  testsuite often named „testng.xml“. There you also can set values for the parameters:

<suite name="testsuite">
<parameter name="seleniumhost" value="192.168.1.22"/>
<parameter name="seleniumport" value="4444"/>
<parameter name="browser" value="*iexplore"/>

<test name="Login">
<classes>
<class name="usecases.Login" />
</classes>
</test>
<test name="Logout">
<classes>
<class name="usecases.Logout" />
</classes>
</test></suite>

For running a testng.xml you just need to type "java org.testng.TestNG testng1.xml" into your command prompt.

For the execution of your tests by hudson, you’ll need to create a new hudson job, build it once, then copy your tests into the established directory of the job (you’ll find it at usr/.hudson/jobs ) and write a ant file, which can be executed by hudson.

An Ant file has different targets, which can or can’t be executed separatly, sequential. You can define them in the hudson job configuration. Your ant file could look like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="testsuite"
name="Selenium">

<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>

<path id="TestNG.libraryclasspath">
<pathelement location="../../libs/testng-6.0.1.jar"/>
</path>
<path id="Selenium.classpath">
<pathelement location="bin"/>
<path refid="TestNG.libraryclasspath"/>
<pathelement location="../../libs/selenium-java-client-driver-1.0.2-SNAPSHOT.jar"/>
<pathelement path="${env.JAVA_HOME}\jre\lib\rt.jar"/>
</path>

<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>

<target name="clean">
<delete dir="bin"/>
</target>

<target depends="clean" name="cleanall"/>

<target depends="build-project" name="build"/>

<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin"
target="${target}" includeantruntime="false">
<src path="src"/>
<classpath refid="Selenium.classpath"/>
</javac>
</target>

<target depends="build" name="runTestsuite"
description="Running testsuite">
<echo>Running testsuite ... </echo>
<taskdef resource="testngtasks" classpathref="Selenium.classpath"/>
<testng outputDir="output/testsuite" haltonfailure="false"
classpathref="Selenium.classpath">
<xmlfileset dir="src" includes="testsuite.xml"/>
</testng>
</target>

</project>

For publishing results I can recommend to use testng-plugin and/or HTML Publisher Plugin for Hudson.

Cheers,
strayparade

Running javascript with selenium

6. Oktober 2010

If you want to run longer javascript code with the selenium java api, you’ll need to use the selenium.getEval(String jsCode); method. Also you have to consider, that only the last line of the javascript code is returned.
For Example, if you have a TextModifier Object in your page which has the Method inverseString(StringToInverse) , a HTML-Element with known id, which name is „dlroW“ and you’ll run the following command:

String result = selenium.getEval("var h = ' olleH';
var name = selenium.browserbot.getCurrentWindow().document. getElementById('"+id+"').name;
var hw = selenium.browserbot.getCurrentWindow(). TextModifier.inverseString(name+h);
hw ");

The result will be Hello World

Cheers,
strayparade

Get the screen coordinates of any html-element

23. September 2010

The previous posted implementation for getting the screen coordinates of html elements is only working for html elements, which are not placed in a scrollable container elment. Otherwise the java.awt.robot will click at a wrong screen position.
I’ve created method, which also works for elements surrounded by a scrollable div, etc.. Right now I’m not sure, if the coverage is worth the loss in performance, but it is a solution. So the following code calculates the screen coordinates of any html element by its id.

int leftOffset = selenium.getElementPositionLeft("id="+id).intValue();
int topOffset = selenium.getElementPositionTop("id="+id).intValue();

int width = selenium.getElementWidth("id="+id).intValue();
int height = selenium.getElementHeight("id="+id).intValue();
int elementXPosition = this.pageInnerX + leftOffset;
int elementYPosition = this.pageInnerY + topOffset;

/* TODO verify the scroll calculations for IE and Safari*/
int scrollTop=0;
int scrollLeft=0;
String parentNode = "selenium.browserbot.getCurrentWindow().document.getElementById('"+id+"').parentNode";

while(!"BODY".equals(selenium.getEval(parentNode+".tagName"))){

scrollTop = scrollTop + new Integer(selenium.getEval(parentNode+".scrollTop")).intValue();

scrollLeft = scrollLeft + new Integer(selenium.getEval(parentNode+".scrollLeft")).intValue();

parentNode = parentNode+".parentNode";
}

elementXPosition = elementXPosition - scrollLeft - new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().scrollX")).intValue();

elementYPosition = elementYPosition - scrollTop - new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().scrollY")).intValue();

int elementWidth = new Integer(width).intValue();
int elementHeight = new Integer(height).intValue();
/* end of scroll calculations */

In the while loop I’m getting the parent-element of the previous element each cycle. Then the element is investigated for any necessary scroll-values. The rest of the code should be self-explaining.

Cheers,
strayparade

Selenium RC – Java – mouseOver

17. August 2010

There are different possibilities to potentially fire a mouseOver event in Selenium, but none of them is really working. I first tried it withselenium.mouseMove(String locator), but my button on the page, which should change colour by hovering it, kept shining in yellow. Then I tried to fire the event with selenium by using selenium.fireEvent(String locator, String event) and then with some custom script while using selenium.runScript(String javascript) nothing changed. Finally I’ve seen, that Selenium comes with a remote java.awt.robot , which we can use for controlling the mouse, keyboard and screen. My solution for doing a mouse Over (just implemented it for firefox, yet) :

int leftOffset = selenium.getElementPositionLeft(locator).intValue();
int topOffset = selenium.getElementPositionTop(locator).intValue();
int width = selenium.getElementWidth(locator).intValue();
int height = selenium.getElementHeight(locator).intValue();

int elementXPosition = this.pageInnerX + leftOffset + new Integer(width/2).intValue();
int elementYPosition = this.pageInnerY + topOffset + new Integer(height/2).intValue();

Robot robot = RobotRetriever.getRobot();
robot.mouseMove(elementXPosition, elementYPosition);

where pageInnerX and pageInnerY are defined somewhere up the road by the following code (firefox specific):

int outerHeight = new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().outerHeight")).intValue();
int outerWidth = new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().outerWidth")).intValue();

int innerHeight = new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().innerHeight")).intValue();
int innerWidth = new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().innerWidth")).intValue();

int windowTopMenusHeight = outerHeight - innerHeight - 25; // 25 equals ~Statusbar Height
int windowLeftSpaceWidth = new Float((outerWidth - innerWidth)/2).intValue();

int screenXBrowser = new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().screenX")).intValue();
int screenYBrowser = new Integer(selenium.getEval("selenium.browserbot.getCurrentWindow().screenY")).intValue();

this.pageInnerX = screenXBrowser + windowLeftSpaceWidth;
this.pageInnerY = screenYBrowser + windowTopMenusHeight;

This is working fine so far. So the next step would be to find a convenient way for getting the height of the statusbar. And finally make it compatible with IE and so on.

Cheers,
strayparade

Selenium RC – Java – Get elements by attribute

12. August 2010

Selenium doesn’t have a method for receiving all html-elements by the value of an attribute. But I needed that kind of method for testing a subset of buttons on a page without knowing their ids, occurrence or having other information. Let’s say the mentioned buttons are identified by the value „true“ for the attribute „testing=“. Now I want to test each button with testing=“true“. I found, that the methods getXpathCount(String locator) and getAttribute(String IdLocator) are very useful for doing so.

//Strings for building the locator
String request = "xpath=//*[";
String done="@"+attribute+"='"+aValue+"']";

//counts the elements with the given attribute and value
int elementsCount = selenium.getXpathCount(request+done).intValue();
String[] elementIds= new String[elementsCount];

for(int i=0;i<elementsCount;i++){

//getting the id of the element
String elementId = selenium.getAttribute((request+done+"/@id"));
elementIds[i] = elementId;
done = "@id!="+elementId+"and"+done;

}

While Selenium cannot handle multiple results you have the request each element by its own. With the code above you’ll get the ids for doing so. The request disqualifies the last read element by its id to get the next one. The requests will look like:

xpath=//*[@id!=7and@testing='true']/@id
__________________________________________________
xpath=//*[@id!=8and@id!=7and@testing='true']/@id
__________________________________________________
xpath=//*[@id!=13and@id!=8and@id!=7and@testing='true']/@id
 

Finally all the ids of the elements to test are saved in the elementIds-Array.

Cheers,

strayparade

fedora 7: reseting root password

20. Juli 2010

Reseting the root password is not a big thing, just follow these steps:

  1. reboot the system
  2. wait for the blue fedora booting screen telling you „Press any key to enter the menu“
    1. Press any key
  3. Press „e“ for edit => the kernel’s boot menu will appear
  4. Select the line beginning with „kernel“
  5. Press „e“ for edit => a prompt will appear
  6. add „single“ to the shown line, which makes the complete line resulting in „</LogCol00 rhgb qiuet single“
  7. Hit Enter, which will bring you back to the boot menu
  8. Press „b“ to boot => a prompt will appear

Now you can change the root password by entering the common command „passwd“. After this you can change the run level by typing „init *“, where * has to be one of the following numbers:

Fedora runlevels

0 Halt
1 Single-User mode
2 Multi-user mode console logins only (without networking)
3 Multi-User mode, console logins only
4 Not used/User-definable
5 Multi-User mode, with display manager as well as console logins
6 Reboot

[1]

Have a nice day,

strayparade

[1] http://en.wikipedia.org/wiki/Runlevel    20.07.2010


Follow

Get every new post delivered to your Inbox.