###IntelliJ IDEA set up for work with functional tests
- Make sure that you have installed JDK, Maven and GIT and set all environment variables for these tools
- Download IntelliJ IDEA (choose Community Edition FREE)
- Clone repository for functional tests via Git or IntelliJ IDEA.
- Open file pom.xml with IntelliJ IDEA
- Open menu File - Project Structure. Select Project item and under Project SDK select JDK. Choose folder where you installed JDK.
- Add Maven to your IntelliJ IDEA: go to File - Settings - Maven. Select checkbox Override at the Maven home directory item. Paste path to Maven folder in textbox.
- Go to menu Run - Edit Configuration. Add new configuration for type "TestNG". Fill Name and Suite fields with path to testng.xml, i.e. %path_to_project%/functional-tests-jcommune/src/test/resources/testng.xml. Fill "Working directory" field with %path_to_project%. Set "Use classpath of module" to maven module name (functional-tests-jcommune) Press "Ok".
####Running with Local Selenium Server
If you'd like to use your local browser to run tests, download selenium server,
unzip it and run as java -jar selenium-server-standalone-2.44.0.jar
. It will start on http://localhost:4444/wd/console.
Now in IntelliJ you have to specify env vars: Edit Configuration -> Environment Variables:
- SELENIUM_VERSION - your browser version (e.g. 35.0.1)
- SELENIUM_BROWSER - your browser name (firefox)
- SELENIUM_URL - http://localhost:4444/wd/hub
In your testng.xml file you should also set:
<parameter name="webDriverUrl" value="http://localhost:4444/wd/hub"/>
###Functional Tests Best Practices
- Do not use XPath if possible, use IDs or CSS. XPaths depend on all the elements in the hierarchy of HTML. If you need
to find a link and you're doing something like this
//tbody/tr/td/a[contains(@href,'branches')]
you'll get in trouble when at least one of the elementstbody
,tr
,td
,a
changes. The less elements to be changed, the better. Moreover XPath usually is a bit complicated.