In the spirit of my new blog I thought I would start with a trick I learn’t the other day. I really don’t like repetitive testing and I think its our duty (strong words I know) to find interesting ways to get over these challenges.
So I was charged with a piece of API testing. It was a simple sign up process, which set the user into a particular status. The status wasn’t returned by the API response (just a success or failure) however so I needed to go off to the front end to check it.
I had been toying with using SoapUI and Selenium together for some time so I thought what the hell and attempted to hack the two together in a relatively graceful fashion (as we do as testers sometimes). I came up with this approach:
- Download the latest Selenium Standalone server.
- Put it in here – SoapUIRoot\Bin\Ext
- Fire up Soap UI, add a Suite>Test>Groovy Step
- Learn Selenium Webdriver (you’ll need to one day, may as well get on with it)
In terms of Webdriver I kept it really simple:
import org.openqa.selenium.Byimport org.openqa.selenium.WebDriverimport org.openqa.selenium.WebElementimport org.openqa.selenium.ie.InternetExplorerDriverimport org.openqa.selenium.support.ui.ExpectedConditionimport org.openqa.selenium.support.ui.WebDriverWait// Create a new instance of the Internet Explorer driver// Notice that the remainder of the code relies on the interface,// not the implementation.WebDriver driver = new InternetExplorerDriver()// And now use this to visit the sitedriver.get(“https://mysite.project.qa.com/login”)//Get past the Certificate ProblemWebElement override = driver.findElement(By.id(“overridelink”));override.click();//Enter Username and Password, LoginWebElement username = driver.findElement(By.id(“username”));username.sendKeys(“User”);WebElement password = driver.findElement(By.id(“password”));password.sendKeys(“Password1”);WebElement signin = driver.findElement(By.id(“submit”));signin.click();//Find the Customer with the numberWebElement custno = driver.findElement(By.id(“CustomerID”));custno.sendKeys(${#TestCase#CustID});//Assert the StatusassertTrue(isElementPresent(By.linkText(“Status is Live”)));//Close the browserdriver.quit();
I came out with a test that looked like this:
- Groovy step to generate a random username and GUID
- Property transfer to get them into a HTTP step
- HTTP Post to the API (and capture the Customer ID)
- Transfer step for Customer ID
- Groovy step to run Selenium and use the Customer ID to find the sign up and check the status
And there we are! One very boring bit of testing automated forever. Testing and analysis of new stuff is fun, checking old stuff is a bit dull. Automate now to enjoy the future more.