Last active
August 29, 2015 14:00
-
-
Save ishubin/11029509 to your computer and use it in GitHub Desktop.
A concept of using Galen together with TestNG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.mindengine.galen.browser.SeleniumBrowser; | |
import net.mindengine.galen.browser.Browser; | |
import net.mindengine.galen.page.Page; | |
import net.mindengine.galen.specs.page.PageSection; | |
import net.mindengine.galen.specs.reader.page.PageSpec; | |
import net.mindengine.galen.specs.reader.page.PageSpecReader; | |
import net.mindengine.galen.validation.PageValidation; | |
import net.mindengine.galen.validation.SectionValidation; | |
import net.mindengine.galen.validation.ValidationError; | |
import net.mindengine.galen.validation.ValidationListener; | |
import net.mindengine.galen.specs.reader.page.SectionFilter; | |
public class GalenTests { | |
@Test(dataProvider = "allMyDevices") | |
public void homePage(screenSize, tags) { | |
WebDriver driver = createDriver("http://example.com", screenSize); | |
checkPageLayout(driver, "layouts/homePage.spec", tags); | |
} | |
public void checkPageLayout(WebDriver driver, String pageSpecPath, List<String> tagsToInclude){ | |
Browser browser = new SeleniumBrowser(driver); | |
PageSpecReader pageSpecReader = new PageSpecReader(browser); | |
PageSpec spec = pageSpecReader.read(pageSpecPath); | |
SectionFilter sectionFilter = new SectionFilter(tagsToInclude); | |
List<PageSection> pageSections = spec.findSections(tagsToInclude); | |
// allows to subscribe for all validation events. Could also be null | |
ValidationListener validationListener = configureValidationListener(); | |
SectionValidation sectionValidation = new SectionValidation(pageSections, new PageValidation(browser, page, spec, validationListener, sectionFilter), validationListener); | |
List<ValidationError> errors = sectionValidation.check(); | |
if (errors != null) { | |
//TODO do something with errors | |
} | |
} | |
public ValidationListener configureValidationListener() { | |
//TODO | |
} | |
public WebDriver createDriver(String url, Dimension screenSize) { | |
WebDriver driver = initDriver(); | |
driver.get(url); | |
driver.manage().window().setSize(screenSize); | |
return driver; | |
} | |
public WebDriver initDriver() { | |
//TODO initialize driver | |
} | |
@DataProvider | |
public Object[][] allMyDevices() { | |
return new Object[][]{ | |
[size(400, 800), asList("mobile","all")], | |
[size(600, 800), asList("tablet", "all")], | |
[size(1024, 768), asList("desktop", "all")], | |
}; | |
} | |
public static Dimension size(int w, int h) { | |
return new Dimension(w, h); | |
} | |
} |
Don't think I can do much with this without the ValidationListener being implemented, any idea when you are planning to get to it?
The tests are running fine and able to access the spec file. Is there a way I can get the htmlreports using Maven goals? Like a maven version of galen check --htmlreport "reports"
Hi Rashi!
The initDriver method is just a placeholder for WebDriver initialization
As for ValidationListener at the moment there is no proper reporting implemented which could be used as a library. Whole reporting mechanism is messed up and I am planning to refactor it and implement a simpler one. In my case I need it for this ticket galenframework/galen#62. But that would work in your case as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the Purpose of initDriver() method? Just to initialise the driver or is it meant to do something else also?