This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Writing a Test Case for ESB UI
The main purpose of this page is to describe the steps involved in writing selenium tests with WSO2 Test Automation Framework.
For this demonstration, a simple server - login operation selenium test was used.
Prerequisites:
- Prior to running selenium based UI tests, you need to install the relevant web browser (E.g. Firefox, Google Chrome, IE etc.)
You need to set the relevant configurations in the automation.xml file.
</configurations> <tools> <selenium> <!-- Change to enable remote webDriver --> <!-- URL of remote webDriver server --> <remoteDriverUrl enable="false">http://xx.xx.xx.xx:4444/wd/hub/</remoteDriverUrl> <!-- Type of the browser selenium tests are running" --> <browser> <browserType>firefox</browserType> <!-- path to webDriver executable - required only for chrome--> <webdriverPath enable="false">/path/to/chromedriver</webdriverPath> </browser> </selenium> </tools>
- ESBLoginTestCase.java
Â
package org.wso2.carbon.esb.ui.test.login; import org.openqa.selenium.WebDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.automation.api.selenium.home.HomePage; import org.wso2.carbon.automation.api.selenium.login.LoginPage; import org.wso2.carbon.automation.engine.context.AutomationContext; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.extensions.selenium.BrowserManager; import org.wso2.carbon.esb.ui.test.ESBIntegrationUITest; public class ESBLoginTestCase extends ESBIntegrationUITest { private WebDriver driver; //01 @BeforeClass(alwaysRun = true) public void setUp() throws Exception { super.init(); // 02 driver = BrowserManager.getWebDriver(); //03 driver.get(getLoginURL("ESB")); //04 } @Test(groups = "wso2.am", description = "verify login to ESB Server") public void testLogin() throws Exception { LoginPage test = new LoginPage(driver, false); // 05 HomePage home = test.loginAs("admin", "admin"); // 06 home.logout(); driver.close(); // 07 } @AfterClass(alwaysRun = true) public void tearDown() throws Exception { driver.quit(); // 08 }
Description:
Create a java class and name it ESBLoginTestCase.java.
Extend the ESBIntegrationUITest class. This class will contain some common operational methods that can be useful for all UI based tests. Â
Please refer the numbers displayed in the test class for the following descriptions.
@BeforeClass
- You need to create a web driver instance to proceed with the test.
- Invoke the init() of the ESBIntegrationUITest class. This will initialize the automationContext object.
This will create a driver instance based on your choice of web browser type mentioned in the automation.xml file. Please refer following section of the automation.xml file.
<browser> <browserType>firefox</browserType> <!-- path to webDriver executable - required only for chrome--> <webdriverPathenable="false">/path/to/chromedriver</webdriverPath> </browser>
- This will generate the login url for the ESB server login page. Now you can start writing your test case under the @Test annotation.
- Create a Login page instance by passing the driver instance you created in step 3.
- Invoke the loginAs() method by passing your login credentials to login to the server home/login page. If you have set everything correctly, you should be able to see a successful login operation running on your chosen web browser. You can then perform the logout operation by calling the home.logout() method.
- Â Close the driver used for the test.
@AfterClass - In the tearDown() you can quit() of the selenium web driver interface.
Sample ESBIntegrationUITest.java:
public abstract class ESBIntegrationUITest { protected Log log = LogFactory.getLog(getClass()); private AutomationContext automationContext; // 1 protected void init() throws IOException, XMLStreamException, XPathExpressionException { automationContext = new AutomationContext("ESB","lbw001", TestUserMode.SUPER_TENANT_ADMIN); } protected String getBackendURL() throws XPathExpressionException { return automationContext.getContextUrls().getBackEndUrl(); } protected String getSessionCookie() throws RemoteException, XPathExpressionException, LoginAuthenticationExceptionException { String sessionCookie = automationContext.login(); return sessionCookie; } protected String getServiceURL() throws XPathExpressionException { String serviceURL = automationContext.getContextUrls().getServiceUrl(); return automationContext.getContextUrls().getServiceUrl(); }
Note how the ESBIntegrationUITest.java class, to be used as the base class for all tests, is defined. Consider the possible alternatives for initializing the automationContext instance. You can create more custom automationContext instance by passing desired arguments/parameters.
In this case the productGroupName (ESB) and the testUserMode (TestUserMode.SUPER_TENANT_ADMIN) is passed for initialization purposes.
A few common operational methods such as getBackendURL(), getSessionCookie() and getServiceURL() were added as they might be useful when writing selenium based UI tests.