net.mindengine.galen.suite.actions.GalenPageActionCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of galen Show documentation
Show all versions of galen Show documentation
A library for layout testing of websites
/*******************************************************************************
* Copyright 2015 Ivan Shubin http://mindengine.net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package net.mindengine.galen.suite.actions;
import java.io.IOException;
import java.util.List;
import net.mindengine.galen.api.Galen;
import net.mindengine.galen.browser.Browser;
import net.mindengine.galen.reports.LayoutReportNode;
import net.mindengine.galen.reports.TestReport;
import net.mindengine.galen.reports.TestReportNode;
import net.mindengine.galen.reports.model.LayoutReport;
import net.mindengine.galen.suite.GalenPageAction;
import net.mindengine.galen.suite.GalenPageTest;
import net.mindengine.galen.validation.ValidationListener;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
public class GalenPageActionCheck extends GalenPageAction {
private List specs;
private List includedTags;
private List excludedTags;
@Override
public void execute(TestReport report, Browser browser, GalenPageTest pageTest, ValidationListener validationListener) throws IOException {
LayoutReport layoutReport = Galen.checkLayout(browser, getSpecs(), getIncludedTags(), getExcludedTags(), getCurrentProperties(), validationListener);
if (report != null) {
String reportTitle = "Check layout: " + toCommaSeparated(getSpecs()) + " included tags: " + toCommaSeparated(includedTags);
TestReportNode layoutReportNode = new LayoutReportNode(layoutReport, reportTitle);
if (layoutReport.errors() > 0) {
layoutReportNode.setStatus(TestReportNode.Status.ERROR);
}
report.addNode(layoutReportNode);
}
}
public GalenPageActionCheck withSpecs(List specFilePaths) {
this.setSpecs(specFilePaths);
return this;
}
public List getSpecs() {
return specs;
}
public void setSpecs(List specs) {
this.specs = specs;
}
public GalenPageActionCheck withIncludedTags(List includedTags) {
this.setIncludedTags(includedTags);
return this;
}
public List getIncludedTags() {
return includedTags;
}
public void setIncludedTags(List includedTags) {
this.includedTags = includedTags;
}
public GalenPageActionCheck withExcludedTags(List excludedTags) {
this.setExcludedTags(excludedTags);
return this;
}
public List getExcludedTags() {
return excludedTags;
}
public void setExcludedTags(List excludedTags) {
this.excludedTags = excludedTags;
}
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(specs)
.append(includedTags)
.append(excludedTags)
.toHashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (obj == this)
return true;
if (!(obj instanceof GalenPageActionCheck))
return false;
GalenPageActionCheck rhs = (GalenPageActionCheck)obj;
return new EqualsBuilder()
.append(specs, rhs.specs)
.append(includedTags, rhs.includedTags)
.append(excludedTags, rhs.excludedTags)
.isEquals();
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("specs", specs)
.append("includedTags", includedTags)
.append("excludedTags", excludedTags)
.toString();
}
public GalenPageAction withOriginalCommand(String originalCommand) {
setOriginalCommand(originalCommand);
return this;
}
private static String toCommaSeparated(List list) {
if (list != null) {
StringBuffer buff = new StringBuffer();
boolean comma = false;
for (String item : list) {
if (comma) {
buff.append(',');
}
comma = true;
buff.append(item);
}
return buff.toString();
}
return "";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy