📜 ⬆️ ⬇️

Smok-test release candidate autotests for 15 minutes

My name is Lilia, I am QA Lead in one of the projects of the financial group BCS (service for the selection of lucrative offers for the client from a number of loan products), and today I will tell how we automated the smk-testing, what problems we faced and what technology stack we use.

At first we decided to automate the regression testing, but as time went on, the functionality changed and we realized that quite a lot of time was being spent on supporting already written autotests. Therefore, we decided to automate the smk test first, and then expand it to automatic regression testing. The testing department was tasked to automate the smk-testing as soon as possible, since The project continued to grow and grow into additional functions.

What is smok testing


Smok testing, as it is also called “smoke testing,” is a quick test of the most critical functionality.
')
On our project:


Technology stack for writing autotests


We write autotests on this stack: Java + Selenium + Cucumber + reports in Allure2.

image

BDD Autotest for smk-testing


1. Feature file with the .feature extension with a description of test scripts in the Gerkin language.

Example:

:  ,     @all :              :      :      **********  :       :       ****  :         :            :       :       :       :       :       

2. Steps steps. It contains classes that describe actions with elements on the page and checks of these elements.

Example:

 @When("^  (.*)") public void pressKey(String key) { webElementUtils.pressKey(key); } @When("^(.*):   (.*)") public void press(String pageTitle, String elementName) { waitUtils.waitElementToBeClickable(getWebElementOnWebPageWithWaiter(elementName, pageTitle)).click(); } @When("^(.*):    (.*)") public void checkCheckbox(String pageTitle, String elementName) { WebElement element = getWebElementOnWebPageWithWaiter(elementName, pageTitle); if (!webElementUtils.isCheckboxSelected(element)) { element.click(); } } @When("^(.*):    (.*)") public void uncheckCheckbox(String pageTitle, String elementName) { WebElement element = getWebElementOnWebPageWithWaiter(elementName, pageTitle); if (webElementUtils.isCheckboxSelected(element)) { element.click(); } } @And("^(.*):    (.*)$") public void erase(String pageTitle, String elementName) { WebElement element = getWebElementOnWebPageWithWaiter(elementName, pageTitle); webElementUtils.clearElement(element); } @And("^(.*):   (.*)  (.*)$") public void enterValue(String pageTitle, String elementName, String text) { WebElement element = getWebElementOnWebPageWithWaiter(elementName, pageTitle); webElementUtils.fillElementWithText(element, expressionUtils.parseString(text)); } @And("^(.*):  (.*)  (.*)$") public void selectValue(String pageTitle, String dropdownListName, String value) { WebElement element = getWebElementOnWebPageWithWaiter(dropdownListName, pageTitle); webElementUtils.selectValueFromCombobox(element, value); } @Then("^(.*):  (.*)  $") public void elementDoesNotContainAnyText(String pageTitle, String elementName) { WebElement element = getWebElementOnWebPageWithWaiter(elementName, pageTitle); assertEquals("", webElementUtils.getTextFromWebElement(element).trim()); } @Then("^(.*):  (.*)    (.*)$") public void checkSliderPosition(String pageTitle, String elementName, String expectedPosition) { WebElement element = getWebElementOnWebPageWithWaiter(elementName, pageTitle); String sliderTrackPosition = StringUtils.substringBetween(element.findElement(By.cssSelector(".rc-slider-track")).getAttribute("style"), "width: ", ";"); String sliderHandlePosition = StringUtils.substringBetween(element.findElement(By.cssSelector(".rc-slider-handle")).getAttribute("style"), "left: ", ";"); assertEquals(expectedPosition, sliderTrackPosition); assertEquals(expectedPosition, sliderHandlePosition); } @Then("^(.*):   (.*)$") public void checkComponentIsDisplayed(String pageTitle, String component) { WebElement element = getWebElementOnWebPageWithWaiter(component, component); assertTrue(webElementUtils.isElementVisible(element)); } @When("^(.*):   (.+)  (.*)$") public void loadFileInField(String pageTitle, String fileName, String elementName) { WebElement element = getWebElementOnWebPage(elementName, pageTitle); File file = new File(Objects.requireNonNull(getClass().getClassLoader().getResource(fileName)).getFile()); element.sendKeys(file.getAbsolutePath()); } @Then("^(.+):   (.+)  (.+)   (.+)$") public void checkAttributeInElement(String pageTitle, String elementName, String attributeName, String expectedValue) { WebElement element = getWebElementOnWebPage(elementName, pageTitle); String attribute = webElementUtils.getAttribute(element, attributeName); String message = String.format(" '%s'   '%s'   '%s'    .\n" + " : '%s'.\n : '%s'.\n", attributeName, elementName, pageTitle, expectedValue, attribute); assertEquals(message, expectedValue, attribute); } @Then("^(.+):   (.+)  (.+)/$") public void checkValueTag(String pageTitle, String tagName, String expectedValue) { WebElement title = webDriver.findElement(By.tagName(tagName)); assertEquals(expectedValue, title.getAttribute("innerHTML").trim()); } } 

3. Working with page locators (PageObject pattern)

Example:

 import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import ru.bcs.creditmarkt.acceptance.pageobject.annotation.PageObject; import ru.yandex.qatools.htmlelements.annotations.Name; @PageObject(title = "", path = "/entry/login") public class LoginPage extends WebPage { @Name(" ") @FindBy(xpath = "//a[text()='']") private WebElement registrationLink; @Name(" ") @FindBy(xpath = "//a[text()='']") private WebElement loginLink; @Name(" ") @FindBy(css = "#phone") private WebElement phoneInput; @Name("  ") @FindBy(css = "button[type=submit]") private WebElement receiveCodeButton; @Name("  ") @FindBy(css = "input#sms") private WebElement smsInput; @Name("      ") @FindBy(css = "button#personalAgreement") private WebElement personalAgreementCheckbox; @Name(" -") @FindBy(css = "div.wa-userpic") private WebElement chatBotIcon; } 

4. Report in Allure2

image

CI Setup


While we were writing autotests, the BCS financial group got Selenoid, and we were able to set up the launch of tests in the pipline GitLab

The organization of writing autotests for different stands


We have several booths where development, debugging, and acceptance take place, and there are still a lot of feature booths where we test new functions developed by distributed teams.

We also have several booths of branches that correspond to different development environments. When files change on the stand, the corresponding stand with autotests automatically starts.

Total


Now in our project, when publishing a release to an acceptance stand, a full set of smoke tests is automatically performed in 15 minutes. Depending on the results obtained, the testing team decides on the acceptance of a release candidate for testing for regression testing.

Source: https://habr.com/ru/post/459734/


All Articles