Log In | Sign Up   View a printable version of the current page.
  Dashboard > [fleXive] > ... > Checking out and working with the sources > Browser Tests

Added by Markus Plesser, last edited by Anonymous on Jan 18, 2012  (view change)
Labels: 
(None)

[fleXive] uses Selenium Remote Control to launch browser tests in TestNG, which potentially allows to automatically test a [fleXive] application under a variety of browsers with a single test case.

For a quick manual overview of the [fleXive] component library, some static test pages exist under /flexive/adm/test/ (link on localhost:8080).

Browser test setup

For running the browser tests, first thing you need to do is install a recent Selenium snapshot. At the moment of writing, the latest release did not work, this snapshot did. Newer snapshots are available here. Extract the files from this archive to a local directory.

Launch selenium server

You can then launch the server in the selenium/selenium-server-0.9.2-SNAPSHOT directory with

java -jar selenium-server.jar -port 7983

(set the port to any desired value, 7983 is the current default for flexive browser tests).

On Ubuntu, you need to perform additional setup to allow testing in firefox:

  1. Create a symbolic link to firefox-bin:
    cd /usr/bin
    sudo ln -s ../lib/firefox/firefox-bin .
  2. You also have to add /usr/lib/firefox to your LD_LIBRARY_PATH, since Selenium does not work with Ubuntu's firefox startup script. Create a shell script to do this automatically:
    #!/bin/sh
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/firefox
    cd <PATH_TO_SELENIUM>/selenium-server-0.9.2-SNAPSHOT
    java -jar selenium-server.jar -port 7983
  3. Execute this shell script using sh <script_name>.

Set test environment properties

You need to set the environment properties (i.e. the Selenium server URI and the local test domain) in a file called browser.properties in /src/framework/tests/java/com/flexive/tests/browser/browser.properties. Create a new file and paste the contents of browser.properties.sample in the same directory. Enter your selenium server address and port, as well as the base URL for accessing the local [fleXive] installation. A valid browser.properties might look like this:

tests.browser.selenium.host=localhost
tests.browser.selenium.port=7983
#tests.browser.selenium.baseUrl=http://www.flexive-develop1.com:8080
tests.browser.selenium.baseUrl=http://localhost:8080

# values : 
#	*firefox
#	*mock
#	*firefoxproxy
#	*pifirefox
#	*chrome
#	*iexploreproxy
#	*iexplore
#	*firefox3
#	*safariproxy
#	*googlechrome
#	*konqueror
#	*firefox2
#	*safari
#	*piiexplore
#	*firefoxchrome
#	*opera
#	*iehta
# for ie use *iexploreproxy 
tests.browser.selenium.browserStart=*firefox
Writing your own browser tests

When writing browser tests for your own [fleXive] application, you might want to use another properties file or hardcode the parameters in the testcase. You can supply the properties file name as well as other parameters to the base class of all [fleXive] browser tests, com.flexive.tests.browser.AbstractSeleniumTest.

Run the [fleXive] browser tests

The flexive3 application has to be up and running on your application server. You also have to add the flexiveTest datasource to your datasources, e.g. for JBoss

jboss/server/all/deploy/flexive_test-ds.xml
<!--
 JBoss MySQL Datasource Configuration

 Please make sure mysql-connector-java-<version>-bin.jar is copied to the <JBoss>/server/<profile>/lib directory!

 See http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.3/doc/Server_Configuration_Guide/html/Connectors_on_JBoss-Configuring_JDBC_DataSources.html
 for detailed configuration infos
-->
<datasources>

    <!--
        transactional datasource, as configured in the global configuration
    -->
    <xa-datasource>
        <jndi-name>jdbc/flexiveTest</jndi-name>
        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
        <!-- Note: "&amp;" has to be used instead of "&" for parameters -->
        <xa-datasource-property name="URL">jdbc:mysql://localhost:3306/flexiveTest?useUnicode=true&amp;characterEncoding=utf8&amp;characterResultSets=utf8</xa-datasource-property>
        <user-name>root</user-name>
        <password>a</password>

        <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
        <no-tx-separate-pools/>
        <!-- This disables transaction interleaving (which BTW, most DB vendors don't support) -->
        <track-connection-by-tx/>
        <isSameRM-override-value>false</isSameRM-override-value>

        <!--pooling parameters-->
        <min-pool-size>5</min-pool-size>
        <max-pool-size>20</max-pool-size>
        <blocking-timeout-millis>5000</blocking-timeout-millis>
        <idle-timeout-minutes>15</idle-timeout-minutes>

        <!-- If you supply the usr/pw from a JAAS login module -->
        <security-domain/>

        <exception-sorter-class-name>
            com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
        </exception-sorter-class-name>
        <valid-connection-checker-class-name>
            com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
        </valid-connection-checker-class-name>
        <metadata>
            <type-mapping>mySQL</type-mapping>
        </metadata>
    </xa-datasource>

    <!--
        non-transactional datasource for database structure patches, Quartz, etc.
        As per convention, non-transactional datasources have the same name like
        transactional but use the suffix "NoTX"
    -->
    <no-tx-datasource>
        <jndi-name>jdbc/flexiveTestNoTX</jndi-name>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <!-- Note: "&amp;" has to be used instead of "&" for parameters -->
        <connection-url>jdbc:mysql://localhost:3306/flexiveTest?useUnicode=true&amp;characterEncoding=utf8&amp;characterResultSets=utf8</connection-url>
        <user-name>root</user-name>
        <password>a</password>

        <!--pooling parameters-->
        <min-pool-size>5</min-pool-size>
        <max-pool-size>20</max-pool-size>
        <blocking-timeout-millis>5000</blocking-timeout-millis>
        <idle-timeout-minutes>15</idle-timeout-minutes>

        <!-- If you supply the usr/pw from a JAAS login module -->
        <security-domain/>

        <exception-sorter-class-name>
            com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
        </exception-sorter-class-name>
        <valid-connection-checker-class-name>
            com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
        </valid-connection-checker-class-name>
        <metadata>
            <type-mapping>mySQL</type-mapping>
        </metadata>
    </no-tx-datasource>

</datasources>
Naming

The datasource have to have a "-ds.xml" suffix.

Before the first browser test run, you need to setup the test database using

ant db.update.test
Beware of flexive caching

Don't reset the test database without restarting the application server. [fleXive] caches lots of data retrieved from the database, and resetting the database of a running instance will likely wreck [fleXive]

To execute the browser tests, go to the [fleXive] installation directory and execute

ant db.noupdate tests.groups -Dtests.groups=browser

If all goes well, the browser tests will connect to the selenium server and run its tests in a local browser window. Also check the selenium server console for errors.

Hi, did you know selenium doesn't continue to test case after it finish with selenium.start(), this is the snippet:

@BeforeMethod(alwaysRun = true)
public void setup()
{
LOGGER.info("<< Setup Test >>");
try

Unknown macro: { selenium = new DefaultSelenium("localhost", 4444, "*custom /usr/local/bin/firefox", "http}

catch (Exception e)

Unknown macro: { LOGGER.info("Error Message Selenium}

}

selenium only run until selenium.start() command and do nothing after that.

thank u.

Sai

Reply To This

Hi Sai,

did you start Selenium server before running the tests? It's not clear from the code snippet you gave, but you have to execute the test cases on the DefaultSelenium instance you created in the call above.

Daniel

Reply To This
Add Comment
Site running on a free Atlassian Confluence Open Source Project License granted to [fleXive] . Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.1 Build:#916 Nov 09, 2007) - Bug/feature request - Contact Administrators