horizon-framework v1.0.54
horizon-framework
A micro framework for interface testing. Thanks for checking this project out!
A bit of background
This project was born out of a necessity of our commerce development team to improve our automated testing coverage in an easy and fast way. It was born as a wrapper around Selenium and evolved into a full solution that utilizes a IoC engine to scan for test files and execute them all.
The development Team
Horizon was initially developed by Leonardo Borba as a POC and had improvements made by Natan Portilho and Renan Santos and is being maintened by Leonardo.
Testing 101:
In order to develop tests using this framework you will use a couple simple concepts: Pages, Test Suites and test methods.
Pages
Pages are a simple abstraction of real webpages. To create the page's components one can declare said components using the By object provided by Selenium.
All page classes need to extend the Page class and have the @wired decorator. the @wired decorator is very similar to the decorator with the same name from the Spring framework. It registers the object to be used by the Dependency injection engine.
Besides that, the other necessary things are to call the super constructor inside your page's constructor and give your page a URL.
Page classes have access to a this.drive property. this drive object is wrapper around your browser's driver, providing methods to access and interact with the DOM.
@wired
export class LoginPage extends Page {
userNameInput = By.id("j_username")
userPassInput = By.id("j_password")
sendFormButton = By.xpath("//button[@class='btn btn-primary btn-block']")
createAccountButton = By.xpath("//div[@class='login-register-welcome-subtitle']/a")
constructor() {
super();
this.URL = Constants.LOGIN_URL
}
async fillLoginForm(user: string, password: string) {
let userInput = await this.driver.waitFor(this.userNameInput)
userInput.sendKeys(user)
let userPass = await this.driver.waitFor(this.userPassInput)
userPass.sendKeys(password)
}
}
Test Suites
A test suite class needs to extent the TestBase class and be decorated with the @test decorator.
A test suite class is where the framework will look for test methos. These methods names need to end with the word Test (just as the example below). Hooks for Before/after and before/after all are also available, for this you just need to override the TestBase class methods. Also, test methods should be async, take no arguments and have no return value(apart from the void promise that async methods naturally yeld).
@test
export class LoginPageTestSuite extends TestBase {
constructor(private loginpage: LoginPage){
super()
this.testName = "Register test suite"
}
async shouldGoToCreateAccountTest(){
await this.loginpage.navigate()
let active = await this.loginpage.isActivePage()
if(!active)
throw new Error()
await this.loginpage.click(this.loginpage.createAccountButton)
}
}
all methods that are tests need to be named using the pattern:
BLABLABLATest
*********Test
Dependency Injection
This framework has a dependency injection mechanism that utilizes the class constructor to inject the components you need, using a Type based injection. This means that in order to use the beans you created using the @wired decorator, you just need to declare your beans as an argument to the class constructor, just like the example below.
constructor(private loginpage: LoginPage){
super()
this.testName = "Register test suite"
}
Drivers
Drivers are abstractions of a Web Browser, currently there are only two supported drivers Firefox and Chrome. To customize browser capabilities (chrome and firefox) just extend it's base class and override the setCapabilities method.
How to configure and run?
To configure and run the project you need to call the HorizonBootstrap.run passing a HorizonConfig object as argument.
The HorizonConfig object has all the flags necessary to run your tests
Just call HorizonBootstrap.run passing a HorizonConfig object as argument and your tests should be executed
BROWSER_DRIVERS // this argument accepts an array of driver classes these are the browsers on which your tests will be executed. The current available driver classes are FirefoxDriver and GoogleChromeDriver.
WAIT_TIME_BETWEEN_BROWSERS // this represents the time the framework will wait between tests.
MOCHA_TIMEOUT // this is the timeout of each test
SCREENSHOTS_LOCATION // location where you want to save your screenshots
ENABLE_REPORTS / boolen value that indicate if you want a html report of your tests
TEST_FILES_LOCATION // main folder where your test classes are stored
HEADLESS: // boolean value for the headless option
}
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago