How to use SpecOn class of com.galenframework.specs package

Best Galen code snippet using com.galenframework.specs.SpecOn

Source:SpecReader.java Github

copy

Full Screen

...52import com.galenframework.specs.SpecImage;53import com.galenframework.specs.SpecInside;54import com.galenframework.specs.SpecLeftOf;55import com.galenframework.specs.SpecNear;56import com.galenframework.specs.SpecOn;57import com.galenframework.specs.SpecRightOf;58import com.galenframework.specs.SpecText;59import com.galenframework.specs.SpecText.Type;60import com.galenframework.specs.SpecVertically;61import com.galenframework.specs.SpecWidth;62import com.galenframework.specs.colors.ColorRange;63import java.io.File;64import java.util.ArrayList;65import java.util.LinkedList;66import java.util.List;67import java.util.Optional;68import org.apache.commons.lang3.StringUtils;69import org.apache.commons.lang3.tuple.Pair;70/**71 *72 *73 */74public class SpecReader {75 private static SpecReader specReader;76 public static SpecReader reader() {77 if (specReader == null) {78 specReader = new SpecReader();79 }80 return specReader;81 }82 public SpecContains getSpecContains(List<String> objects, Boolean isPartly) {83 return new SpecContains(objects, isPartly);84 }85 public SpecWidth getSpecWidth(General.RelativeElement rElement, String value, String relativeObjectName) {86 return new SpecWidth(getRange(rElement, value, relativeObjectName, "/width"));87 }88 public SpecHeight getSpecHeight(General.RelativeElement rElement, String value, String relativeObjectName) {89 return new SpecHeight(getRange(rElement, value, relativeObjectName, "/height"));90 }91 private Range getRange(General.RelativeElement rElement, String value, String relativeObjectName, String type) {92 switch (rElement) {93 case None:94 return Parser.parseRange(value);95 case WebElement:96 return Parser.parseRangePercent(value).withPercentOf(relativeObjectName + type);97 default:98 break;99 }100 return null;101 }102 public SpecText getSpecText(Type type, String value) {103 return new SpecText(type, value);104 }105 public SpecCss getSpecCSS(Type type, String value) {106 String cssPropertyName = Expectations.word().read(new StringCharReader(value));107 if (cssPropertyName.isEmpty()) {108 throw new SyntaxException("Expected two values {property (space) value} but only got " + value);109 }110 String cssValue = value.replaceFirst(cssPropertyName + "(,|=|:| )", "");111 return new SpecCss(cssPropertyName, type, cssValue);112 }113 public SpecTitle getSpecTitle(Type type, String value) {114 return new SpecTitle(type, value);115 }116 public SpecUrl getSpecUrl(Type type, String value) {117 return new SpecUrl(type, value);118 }119 public SpecAttribute getSpecAttribute(Type type, String value) {120 String attributeName = Expectations.word().read(new StringCharReader(value));121 if (attributeName.isEmpty()) {122 throw new SyntaxException("Expected two values {attribute (space) value} but only got " + value);123 }124 String attrValue = value.replaceFirst(attributeName + "(,|=|:| )", "");125 return new SpecAttribute(attributeName, type, attrValue);126 }127 public SpecInside getSpecInside(String objectName, String value, Boolean isPartly) {128 SpecInside spec = new SpecInside(objectName, Parser.parseLocation(value));129 spec.setPartly(isPartly);130 return spec;131 }132 public SpecNear getSpecNear(String objectName, String value) {133 List<Location> locations = Parser.parseLocation(value);134 if (locations == null || locations.isEmpty()) {135 throw new SyntaxException("There is no location defined");136 }137 return new SpecNear(objectName, Parser.parseLocation(value));138 }139 public SpecAbove getSpecAbove(String objectName, String value) {140 return new SpecAbove(objectName, Parser.parseRange(value));141 }142 public SpecBelow getSpecBelow(String objectName, String value) {143 return new SpecBelow(objectName, Parser.parseRange(value));144 }145 public SpecLeftOf getSpecLeftOf(String objectName, String value) {146 return new SpecLeftOf(objectName, Parser.parseRange(value));147 }148 public SpecRightOf getSpecRightOf(String objectName, String value) {149 return new SpecRightOf(objectName, Parser.parseRange(value));150 }151 public SpecHorizontally getSpecHorizontally(String objectName, String value) {152 return (SpecHorizontally) processAlignment(objectName, value, "horizontally");153 }154 public SpecVertically getSpecVertically(String objectName, String value) {155 return (SpecVertically) processAlignment(objectName, value, "vertically");156 }157 private Spec processAlignment(String objectName, String value, String type) {158 StringCharReader reader = new StringCharReader(value);159 String[] words = ExpectWord.readAllWords(reader);160 Alignment alignment = Alignment.ALL;161 int errorRate = 0;162 if (words.length == 1) {163 errorRate = Parser.parseInt(words[0]);164 if (errorRate == 0) {165 alignment = Alignment.parse(words[0]);166 }167 } else if (words.length == 2) {168 alignment = Alignment.parse(words[0]);169 errorRate = Parser.parseInt(words[1]);170 }171 switch (type) {172 case "horizontally":173 if (alignment.isOneOf(CENTERED, TOP, BOTTOM, ALL)) {174 return new SpecHorizontally(alignment, objectName).withErrorRate(errorRate);175 } else {176 throw new SyntaxException("Horizontal alignment doesn't allow this side: " + alignment.toString());177 }178 case "vertically":179 if (alignment.isOneOf(CENTERED, LEFT, RIGHT, ALL)) {180 return new SpecVertically(alignment, objectName).withErrorRate(errorRate);181 } else {182 throw new SyntaxException("Verticall alignment doesn't allow this side: " + alignment.toString());183 }184 default:185 throw new SyntaxException("Unknown alignment: " + type);186 }187 }188 public SpecCentered getSpecCentered(String objectName, String value, SpecCentered.Location location, SpecCentered.Alignment alignment) {189 int errorRate = Parser.parseRange(value).getFrom().asInt();190 errorRate = errorRate == -1 ? 2 : errorRate;191 return new SpecCentered(objectName, alignment, location).withErrorRate(errorRate);192 }193 public SpecOn getSpecOn(String objectName, Side sideHorizontal, Side sideVertical, String value) {194 List<Location> locations = Parser.parseLocation(value);195 if (locations == null || locations.isEmpty()) {196 throw new SyntaxException("There is no location defined");197 }198 return new SpecOn(objectName, sideHorizontal, sideVertical, locations);199 }200 public SpecColorScheme getSpecColorScheme(String value) {201 List<ColorRange> colorRanges = Parser.parseColorRanges(value);202 if (colorRanges == null || colorRanges.isEmpty()) {203 throw new SyntaxException("There are no colors defined");204 }205 SpecColorScheme spec = new SpecColorScheme();206 spec.setColorRanges(colorRanges);207 return spec;208 }209 public SpecImage getSpecImage(String pageName, String objectName, String value) {210 SpecImage spec = new SpecImage();211 spec.setImagePaths(getImagepath(pageName, objectName));212 spec.setErrorRate(GalenConfig.getConfig().getImageSpecDefaultErrorRate());...

Full Screen

Full Screen

Source:OnValidationTest.java Github

copy

Full Screen

...20import com.galenframework.specs.Side;21import static com.galenframework.specs.Range.between;22import static com.galenframework.specs.Range.exact;23import static com.galenframework.specs.Side.*;24import com.galenframework.specs.SpecOn;25import com.galenframework.validation.ValidationObject;26import org.testng.annotations.DataProvider;27import java.util.HashMap;28import static java.util.Arrays.asList;29public class OnValidationTest extends ValidationTestBase {30 @DataProvider31 @Override32 public Object[][] provideGoodSamples() {33 return new Object[][]{34 {specOn(TOP, LEFT, "container", location(exact(10), LEFT, BOTTOM)), page(new HashMap<String, PageElement>(){{35 put("object", element(90, 110, 50, 50));36 put("container", element(100, 100, 100, 100));37 }})},38 {specOn(TOP, LEFT, "container", location(exact(10), RIGHT), location(exact(10), TOP)), page(new HashMap<String, PageElement>(){{39 put("object", element(110, 90, 50, 50));40 put("container", element(100, 100, 100, 100));41 }})},42 {specOn(TOP, LEFT, "container", location(exact(90), RIGHT), location(exact(10), BOTTOM)), page(new HashMap<String, PageElement>(){{43 put("object", element(190, 110, 50, 50));44 put("container", element(100, 100, 100, 100));45 }})},46 {specOn(TOP, LEFT, "container", location(exact(90), RIGHT), location(exact(20), BOTTOM)), page(new HashMap<String, PageElement>(){{47 put("object", element(190, 120, 50, 50));48 put("container", element(100, 100, 100, 100));49 }})},50 {specOn(BOTTOM, RIGHT, "container", location(exact(10), LEFT), location(exact(20), TOP)), page(new HashMap<String, PageElement>(){{51 put("object", element(190, 180, 50, 50));52 put("container", element(100, 100, 100, 100));53 }})},54 {specOn(BOTTOM, RIGHT, "container", location(exact(10), RIGHT), location(exact(20), BOTTOM)), page(new HashMap<String, PageElement>(){{55 put("object", element(210, 220, 50, 50));56 put("container", element(100, 100, 100, 100));57 }})}58 };59 }60 @DataProvider61 @Override62 public Object[][] provideBadSamples() {63 return new Object[][]{64 {validationResult(NO_AREA, messages("\"object\" is not visible on page")),65 specOn(TOP, LEFT, "container", location(exact(10), LEFT, BOTTOM)), page(new HashMap<String, PageElement>(){{66 put("object", invisibleElement(10, 40, 50, 50));67 put("container", element(100, 100, 100, 100));68 }})},69 {validationResult(NO_AREA, messages("\"object\" is absent on page")),70 specOn(TOP, LEFT, "container", location(exact(10), LEFT, BOTTOM)), page(new HashMap<String, PageElement>(){{71 put("object", absentElement(10, 40, 50, 50));72 put("container", element(100, 100, 100, 100));73 }})},74 {validationResult(NO_AREA, messages("\"container\" is not visible on page")),75 specOn(TOP, LEFT, "container", location(exact(10), LEFT, BOTTOM)), page(new HashMap<String, PageElement>(){{76 put("object", element(10, 40, 50, 50));77 put("container", invisibleElement(100, 100, 100, 100));78 }})},79 {validationResult(NO_AREA, messages("\"container\" is absent on page")),80 specOn(TOP, LEFT, "container", location(exact(10), LEFT, BOTTOM)), page(new HashMap<String, PageElement>(){{81 put("object", element(10, 40, 50, 50));82 put("container", absentElement(100, 100, 100, 100));83 }})},84 {validationResult(areas(new ValidationObject(new Rect(95, 110, 50, 50), "object"), new ValidationObject(new Rect(100, 100, 100, 100), "container")),85 messages("\"object\" is 5px left instead of 10px")),86 specOn(TOP, LEFT, "container", location(exact(10), LEFT, BOTTOM)), page(new HashMap<String, PageElement>(){{87 put("object", element(95, 110, 50, 50));88 put("container", element(100, 100, 100, 100));89 }})},90 {validationResult(areas(new ValidationObject(new Rect(105, 90, 50, 50), "object"), new ValidationObject(new Rect(100, 100, 100, 100), "container")),91 messages("\"object\" is 5px right which is not in range of 10 to 15px, is 10px top instead of 5px")),92 specOn(TOP, LEFT, "container", location(between(10, 15), RIGHT), location(exact(5), TOP)), page(new HashMap<String, PageElement>(){{93 put("object", element(105, 90, 50, 50));94 put("container", element(100, 100, 100, 100));95 }})}96 };97 }98 private SpecOn specOn(Side sideHorizontal, Side sideVertical, String parentObjectName, Location...locations) {99 return new SpecOn(parentObjectName, sideHorizontal, sideVertical, asList(locations));100 }101}...

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1import com.galenframework.specs.SpecOn;2import com.galenframework.specs.SpecVisible;3import com.galenframework.specs.SpecInvisible;4import com.galenframework.specs.SpecOn;5import com.galenframework.specs.SpecVisible;6import com.galenframework.specs.SpecInvisible;7import com.galenframework.specs.SpecOn;8import com.galenframework.specs.SpecVisible;9import com.galenframework.specs.SpecInvisible;10import com.galenframework.specs.SpecOn;11import com.galenframework.specs.SpecVisible;12import com.galenframework.specs.SpecInvisible;13import com.galenframework.specs.SpecOn;14import com.galenframework.specs.SpecVisible;15import com.galenframework.specs.SpecInvisible;16import com.galenframework.specs.SpecOn;17import com.galenframework.specs.SpecVisible;18import com.galenframework.specs.SpecInvisible

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.sample;2import java.io.IOException;3import java.util.LinkedList;4import java.util.List;5import com.galenframework.api.Galen;6import com.galenframework.reports.model.LayoutReport;7import com.galenframework.specs.SpecOn;8import com.galenframework.specs.page.Locator;9import com.galenframework.specs.page.PageElement;10import com.galenframework.specs.page.PageSection;11import com.galenframework.specs.page.PageSpec;12public class GalenJavaSpecOnExample {13 public static void main(String[] args) throws IOException {14 PageSpec pageSpec = new PageSpec();15 pageSpec.setTitle("Page spec for login page");16 PageSection section = new PageSection("Login section", new Locator("css", ".login-section"));17 PageElement loginButton = new PageElement("Login button", new Locator("css", ".login-button"));18 section.addSpec(new SpecOn(loginButton, "color", "red"));19 pageSpec.addSection(section);20 List<SpecOn> specList = new LinkedList<SpecOn>();21 specList.add(new SpecOn(loginButton, "color", "red"));22 specList.add(new SpecOn(loginButton, "size", "100x100"));23 section.addSpecs(specList);24 List<PageSection> sectionList = new LinkedList<PageSection>();25 sectionList.add(section);26 pageSpec.addSections(sectionList);27 List<PageElement> pageElementList = new LinkedList<PageElement>();28 pageElementList.add(loginButton);29 section.addElements(pageElementList);30 System.out.println(layoutReport.getErrorMessages());31 }32}33package com.galenframework.java.sample;34import java.io.IOException;35import java.util.LinkedList;36import java.util.List;37import com

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1import com.galenframework.specs.SpecOn;2import com.galenframework.specs.page.PageSpec;3import com.galenframework.browser.Browser;4import com.galenframework.browser.SeleniumBrowser;5import com.galenframework.browser.SeleniumBrowserFactory;6import com.galenframework.browser.BrowserSize;7import com.galenframework.browser.BrowserType;8import com.galenframework.reports.GalenTestInfo;9import com.galenframework.reports.HtmlReportBuilder;10import com.galenframework.reports.TestReport;11import com.galenframework.reports.model.LayoutReport;12import com.galenframework.reports.model.LayoutReportError;13import com.galenframework.reports.model.LayoutReportErrorList;14import com.galenframework.reports.model.LayoutReportStatus;15import com.galenframework.reports.model.LayoutReportValidationError;16import com.galenframework.reports.model.LayoutReportValidationWarning;17import com.galenframework.reports.model.LayoutSectionReport;18import com.galenframework.reports.model.LayoutSectionReportList;19import com.galenframework.reports.model.LayoutSectionStatus;20import com.galenframework.reports.model.LayoutValidationReport;21import com.galenframework.reports.model.LayoutValidationReportList;22import com.galenframework.reports.model.LayoutValidationStatus;23import com.galenframework.reports.model.PageReport;24import com.galenframework.reports.model.SpecReport;25import com.galenframework.reports.model.TestReportStatus;26import com.galenframework.reports.model.TestReportValidationError;27import com.galenframework.reports.model.TestReportValidationWarning;28import com.galenframework.reports.model.ValidationReport;29import com.galenframework.reports.model.ValidationStatus;30import com.galenframework.specs.Spec;31import com.galenframework.specs.SpecContainsText;32import com.galenframework.specs.SpecExactText;33import com.galenframework.specs.SpecInside;34import com.galenframework.specs.SpecNear;35import com.galenframework.specs.SpecNot;36import com.galenframework.specs.SpecNotContainsText;37import com.galenframework.specs.SpecNotExactText;38import com.galenframework.specs.SpecNotNear;39import com.galenframework.specs.SpecNotOn;40import com.galenframework.specs.SpecOn;41import com.galenframework.specs.SpecOutside;42import com.galenframework.specs.SpecVisible;43import com.galenframework.specs.page.PageSection;44import com.galenframework.specs.page.PageSpec;45import com.galenframework.specs.page.Page

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1import com.galenframework.specs.SpecOn;2import com.galenframework.specs.Spec;3import com.galenframework.specs.SpecOn;4import com.galenframework.specs.Spec;5import com.galenframework.specs.SpecOn;6import com.galenframework.specs.Spec;7import com.galenframework.specs.SpecOn;8import com.galenframework.specs.Spec;9import com.galenframework.specs.SpecOn;10import com.galenframework.specs.Spec;11import com.galenframework.specs.SpecOn;12import com.galenframework.specs.Spec;13import com.galenframework.specs.SpecOn;14import com.galenframework.specs.Spec;15import com.galenframework.specs.SpecOn;16import com.galenframework.specs.Spec;17import com.galenframework.specs.SpecOn;18import com.galenframework.specs.Spec;19import com.galenframework.specs.SpecOn;20import com.galenframework.specs.Spec;

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.sample;2import com.galenframework.java.sample.components.*;3import com.galenframework.specs.SpecOn;4import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8public class GalenTest {9 public static void main(String[] args) throws Exception {10 WebDriver driver = new ChromeDriver();11 WebElement mainMenu = driver.findElement(By.cssSelector(".main-menu"));12 SpecOn specOn = new SpecOn(mainMenu);13 specOn.object("main menu").inside("body");14 driver.quit();15 }16}17package com.galenframework.java.sample;18import com.galenframework.java.sample.components.*;19import com.galenframework.specs.SpecOn;20import org.openqa.selenium.By;21import org.openqa.selenium.WebDriver;22import org.openqa.selenium.WebElement;23import org.openqa.selenium.chrome.ChromeDriver;24public class GalenTest {25 public static void main(String[] args) throws Exception {26 WebDriver driver = new ChromeDriver();27 WebElement mainMenu = driver.findElement(By.cssSelector(".main-menu"));28 SpecOn specOn = new SpecOn(mainMenu);29 specOn.object("main menu").inside("body");30 driver.quit();31 }32}33package com.galenframework.java.sample;34import com.galenframework.java.sample.components.*;35import com.galenframework.specs.SpecOn;36import org.openqa.selenium.By;37import org.openqa.selenium.WebDriver;38import org.openqa.selenium.WebElement;39import org.openqa.selenium.chrome.ChromeDriver;40public class GalenTest {41 public static void main(String[] args) throws Exception {42 WebDriver driver = new ChromeDriver();43 WebElement mainMenu = driver.findElement(By.cssSelector(".main-menu"));44 SpecOn specOn = new SpecOn(mainMenu);45 specOn.object("main menu").inside("body");46 driver.quit();47 }48}49package com.galenframework.java.sample;50import com.galenframework.java.sample.components.*;51import

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.sample;2import com.galenframework.specs.SpecOn;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.chrome.ChromeOptions;6import java.io.IOException;7public class GalenSpecOn {8 public static void main(String[] args) throws IOException {9 WebDriver driver = new ChromeDriver(new ChromeOptions().addArguments("--headless"));10 SpecOn specOn = new SpecOn("div#footer", "check-specs", "check-specs");11 String spec = specOn.toString();12 System.out.println(spec);13 driver.close();14 }15}

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.sample;2import com.galenframework.specs.SpecOn;3import com.galenframework.specs.page.PageSpec;4import com.galenframework.specs.page.PageSection;5public class SpecOnExample {6 public static void main(String[] args) throws Exception {7 PageSpec pageSpec = new PageSpec();8 PageSection pageSection = new PageSection("header", "header");9 pageSection.addSpec(new SpecOn("logo", "visible", "true"));10 pageSpec.addSection(pageSection);11 System.out.println(pageSpec);12 }13}14package com.galenframework.java.sample;15import com.galenframework.specs.SpecOn;16import com.galenframework.specs.page.PageSpec;17import com.galenframework.specs.page.PageSection;18public class SpecOnExample {19 public static void main(String[] args) throws Exception {20 PageSpec pageSpec = new PageSpec();21 PageSection pageSection = new PageSection("header", "header");22 pageSection.addSpec(new SpecOn("logo", "visible", "false"));23 pageSpec.addSection(pageSection);24 System.out.println(pageSpec);25 }26}

Full Screen

Full Screen

SpecOn

Using AI Code Generation

copy

Full Screen

1SpecOn spec = new SpecOn("div", "top", "10px");2spec.check(driver, By.id("element_id"), report);3SpecNot spec = new SpecNot(new SpecOn("div", "top", "10px"));4spec.check(driver, By.id("element_id"), report);5SpecVisible spec = new SpecVisible();6spec.check(driver, By.id("element_id"), report);7SpecNot spec = new SpecNot(new SpecVisible());8spec.check(driver, By.id("element_id"), report);9SpecHidden spec = new SpecHidden();10spec.check(driver, By.id("element_id"), report);11SpecNot spec = new SpecNot(new SpecHidden());12spec.check(driver, By.id("element_id"), report);13SpecWidth spec = new SpecWidth("100px");14spec.check(driver, By.id("element_id"), report);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Galen automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful