How to use withPercentOf method of com.galenframework.specs.Range class

Best Galen code snippet using com.galenframework.specs.Range.withPercentOf

Source:InsideValidationTest.java Github

copy

Full Screen

...58 {specInside("container", location(exact(5), LEFT), location(between(5, 15), TOP)), page(new HashMap<String, PageElement>(){{59 put("object", element(10, 15, 100, 100));60 put("container", element(5, 5, 120, 120));61 }})},62 {specInside("container", location(exact(20).withPercentOf("container/height"), TOP)), page(new HashMap<String, PageElement>(){{63 put("object", element(10, 15, 100, 20));64 put("container", element(5, 5, 120, 50));65 }})},66 {specInside("container", location(between(15, 22).withPercentOf("container/height"), TOP)), page(new HashMap<String, PageElement>(){{67 put("object", element(10, 15, 100, 20));68 put("container", element(5, 5, 120, 50));69 }})},70 // checking that it allows 2 pixels overlap71 {specInside("container", location(exact(5), TOP)), page(new HashMap<String, PageElement>(){{72 put("object", element(0, 5, 102, 97));73 put("container", element(0, 0, 100, 100));74 }})}75 };76 }77 @SuppressWarnings("serial")78 @DataProvider79 public Object[][] provideBadSamples() {80 return new Object[][]{81 {validationResult(areas(new ValidationObject(new Rect(10, 10, 500, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),82 messages("\"object\" is not completely inside. The offset is 380px."), NULL_META),83 specInside("container"), page(new HashMap<String, PageElement>(){{84 put("object", element(10, 10, 500, 50));85 put("container", element(0, 0, 130, 120));86 }})87 },88 {validationResult(areas(new ValidationObject(new Rect(10, 10, 500, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),89 messages("\"object\" is not completely inside. The offset is 380px."), NULL_META),90 specInside("container", location(exact(10), LEFT)), page(new HashMap<String, PageElement>(){{91 put("object", element(10, 10, 500, 50));92 put("container", element(0, 0, 130, 120));93 }})94 },95 {validationResult(areas(new ValidationObject(new Rect(10, 10, 500, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),96 messages("\"object\" is not completely inside. The offset is 380px."), NULL_META),97 specInside("container", location(exact(10), LEFT)), page(new HashMap<String, PageElement>(){{98 put("object", element(10, 10, 500, 50));99 put("container", element(0, 0, 130, 120));100 }})101 },102 {validationResult(areas(new ValidationObject(new Rect(190, 110, 500, 500), "object"), new ValidationObject(new Rect(10, 10, 100, 100), "container")),103 messages("\"object\" is 180px left instead of 10px"),104 asList(LayoutMeta.distance("object", LEFT, "container", LEFT, "10px", "180px"))),105 specInsidePartly("container", location(exact(10), LEFT)), page(new HashMap<String, PageElement>(){{106 put("object", element(190, 110, 500, 500));107 put("container", element(10, 10, 100, 100));108 }})109 },110 {validationResult(areas(new ValidationObject(new Rect(30, 10, 50, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),111 messages("\"object\" is 30px left instead of 10px"),112 asList(LayoutMeta.distance("object", LEFT, "container", LEFT, "10px", "30px"))),113 specInside("container", location(exact(10), LEFT)), page(new HashMap<String, PageElement>(){{114 put("object", element(30, 10, 50, 50));115 put("container", element(0, 0, 130, 120));116 }})117 },118 {validationResult(areas(new ValidationObject(new Rect(30, 20, 50, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),119 messages("\"object\" is 30px left and 20px top instead of 10px"),120 asList( LayoutMeta.distance("object", LEFT, "container", LEFT, "10px", "30px"),121 LayoutMeta.distance("object", TOP, "container", TOP, "10px", "20px") )122 ),123 specInside("container", location(exact(10), LEFT, TOP)), page(new HashMap<String, PageElement>(){{124 put("object", element(30, 20, 50, 50));125 put("container", element(0, 0, 130, 120));126 }})127 },128 {validationResult(areas(new ValidationObject(new Rect(30, 10, 50, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),129 messages("\"object\" is 50px right instead of 10px"),130 asList(LayoutMeta.distance("object", RIGHT, "container", RIGHT, "10px", "50px"))131 ),132 specInside("container", location(exact(10), RIGHT)), page(new HashMap<String, PageElement>(){{133 put("object", element(30, 10, 50, 50));134 put("container", element(0, 0, 130, 120));135 }})},136 {validationResult(areas(new ValidationObject(new Rect(30, 20, 50, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),137 messages("\"object\" is 20px top instead of 10px"),138 asList(LayoutMeta.distance("object", TOP, "container", TOP, "10px", "20px"))139 ),140 specInside("container", location(exact(10), TOP)), page(new HashMap<String, PageElement>(){{141 put("object", element(30, 20, 50, 50));142 put("container", element(0, 0, 130, 120));143 }})},144 {validationResult(areas(new ValidationObject(new Rect(30, 10, 50, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),145 messages("\"object\" is 60px bottom instead of 10px"),146 asList(LayoutMeta.distance("object", BOTTOM, "container", BOTTOM, "10px", "60px"))147 ),148 specInside("container", location(exact(10), BOTTOM)), page(new HashMap<String, PageElement>(){{149 put("object", element(30, 10, 50, 50));150 put("container", element(0, 0, 130, 120));151 }})},152 {validationResult(areas(new ValidationObject(new Rect(30, 10, 50, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),153 messages("\"object\" is 30px left which is not in range of 10 to 20px"),154 asList(LayoutMeta.distance("object", LEFT, "container", LEFT, "10 to 20px", "30px"))155 ),156 specInside("container", location(between(10, 20), LEFT)), page(new HashMap<String, PageElement>(){{157 put("object", element(30, 10, 50, 50));158 put("container", element(0, 0, 130, 120));159 }})},160 {validationResult(NO_AREA, messages("Cannot find locator for \"container\" in page spec"), NULL_META),161 specInside("container", location(between(10, 20), LEFT)), page(new HashMap<String, PageElement>(){{162 put("object", element(30, 10, 50, 50));163 }})},164 {validationResult(areas(new ValidationObject(new Rect(30, 5, 50, 50), "object"), new ValidationObject(new Rect(0, 0, 130, 120), "container")),165 messages("\"object\" is 30px left instead of 10px and 5px top instead of 20px"),166 asList(167 LayoutMeta.distance("object", LEFT, "container", LEFT, "10px", "30px"),168 LayoutMeta.distance("object", TOP, "container", TOP, "20px", "5px")169 )170 ),171 specInside("container", location(exact(10), LEFT), location(exact(20), TOP)), page(new HashMap<String, PageElement>(){{172 put("object", element(30, 5, 50, 50));173 put("container", element(0, 0, 130, 120));174 }})},175 {validationResult(areas(new ValidationObject(new Rect(30, 5, 10, 50), "object"), new ValidationObject(new Rect(0, 0, 50, 120), "container")),176 messages("\"object\" is 60% [30px] left instead of 20% [10px]"), NULL_META),177 specInside("container", location(exact(20).withPercentOf("container/width"), LEFT)), page(new HashMap<String, PageElement>(){{178 put("object", element(30, 5, 10, 50));179 put("container", element(0, 0, 50, 120));180 }})},181 {validationResult(areas(new ValidationObject(new Rect(30, 5, 10, 50), "object"), new ValidationObject(new Rect(0, 0, 50, 120), "container")),182 messages("\"object\" is 60% [30px] left which is not in range of 20 to 40% [10 to 20px]"), NULL_META),183 specInside("container", location(between(20, 40).withPercentOf("container/width"), LEFT)), page(new HashMap<String, PageElement>(){{184 put("object", element(30, 5, 10, 50));185 put("container", element(0, 0, 50, 120));186 }})},187 {validationResult(NO_AREA, messages("\"object\" is absent on page"), NULL_META),188 specInside("container", location(exact(10), LEFT), location(exact(20), TOP)), page(new HashMap<String, PageElement>(){{189 put("object", absentElement(30, 5, 50, 50));190 put("container", element(0, 0, 130, 120));191 }})},192 {validationResult(NO_AREA, messages("\"object\" is not visible on page"), NULL_META),193 specInside("container", location(exact(10), LEFT), location(exact(20), TOP)), page(new HashMap<String, PageElement>(){{194 put("object", invisibleElement(30, 5, 50, 50));195 put("container", element(0, 0, 130, 120));196 }})},197 {validationResult(NO_AREA, messages("\"container\" is absent on page"), NULL_META),...

Full Screen

Full Screen

Source:WidthAndHeightValidationTest.java Github

copy

Full Screen

...41 }})},42 {specWidth(between(20, 30)), page(new HashMap<String, PageElement>(){{43 put("object", element(305, 140, 25, 50));44 }})},45 {specWidth(exact(50).withPercentOf("container/width")), page(new HashMap<String, PageElement>(){{46 put("object", element(305, 140, 15, 50));47 put("container", element(305, 400, 30, 50));48 }})},49 {specWidth(between(45, 55).withPercentOf("main-container-1/width")), page(new HashMap<String, PageElement>(){{50 put("object", element(305, 140, 15, 50));51 put("main-container-1", element(305, 400, 30, 50));52 }})},53 {specWidth(exact(new RangeValue(333, 1)).withPercentOf("main-container-1/width")), page(new HashMap<String, PageElement>(){{54 put("object", element(0, 0, 100, 50));55 put("main-container-1", element(0, 0, 300, 50));56 }})},57 // Height58 {specHeight(exact(20)), page(new HashMap<String, PageElement>(){{59 put("object", element(305, 140, 60, 20));60 }})},61 {specHeight(between(20, 30)), page(new HashMap<String, PageElement>(){{62 put("object", element(305, 140, 60, 20));63 }})},64 {specHeight(between(20, 30)), page(new HashMap<String, PageElement>(){{65 put("object", element(305, 140, 60, 30));66 }})},67 {specHeight(between(20, 30)), page(new HashMap<String, PageElement>(){{68 put("object", element(305, 140, 65, 25));69 }})},70 {specHeight(exact(50).withPercentOf("container/height")), page(new HashMap<String, PageElement>(){{71 put("object", element(100, 140, 65, 20));72 put("container", element(305, 140, 65, 40));73 }})}74 };75 }76 @DataProvider77 @Override78 public Object[][] provideBadSamples() {79 return new Object[][]{80 // Width81 {validationResult(NO_AREA, messages("Cannot find locator for \"object\" in page spec")),82 specWidth(exact(10)), page(new HashMap<String, PageElement>())83 },84 {validationResult(NO_AREA, messages("\"object\" is absent on page")),85 specWidth(exact(10)), page(new HashMap<String, PageElement>(){{86 put("object", absentElement(310, 250, 100, 50));87 }})},88 {validationResult(NO_AREA, messages("\"object\" is not visible on page")),89 specWidth(exact(10)), page(new HashMap<String, PageElement>(){{90 put("object", invisibleElement(310, 250, 100, 50));91 }})},92 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" width is 100px instead of 10px")),93 specWidth(exact(10)), page(new HashMap<String, PageElement>(){{94 put("object", element(100, 100, 100, 50));95 }})},96 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" width is 100px but it should be greater than 110px")),97 specWidth(Range.greaterThan(110)), page(new HashMap<String, PageElement>(){{98 put("object", element(100, 100, 100, 50));99 }})},100 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" width is 100px but it should be less than 90px")),101 specWidth(Range.lessThan(90)), page(new HashMap<String, PageElement>(){{102 put("object", element(100, 100, 100, 50));103 }})},104 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" width is 100px which is not in range of 10 to 40px")),105 specWidth(between(10, 40)), page(new HashMap<String, PageElement>(){{106 put("object", element(100, 100, 100, 50));107 }})},108 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" width is 50% [100px] instead of 10% [20px]")),109 specWidth(exact(10).withPercentOf("container/width")), page(new HashMap<String, PageElement>(){{110 put("object", element(100, 100, 100, 50));111 put("container", element(100, 100, 200, 50));112 }})},113 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" width is 50% [100px] which is not in range of 10 to 20% [20 to 40px]")),114 specWidth(between(10, 20).withPercentOf("container/width")), page(new HashMap<String, PageElement>(){{115 put("object", element(100, 100, 100, 50));116 put("container", element(100, 100, 200, 50));117 }})},118 // Height119 {validationResult(NO_AREA, messages("Cannot find locator for \"object\" in page spec")),120 specHeight(exact(10)), page(new HashMap<String, PageElement>())121 },122 {validationResult(NO_AREA, messages("\"object\" is absent on page")),123 specHeight(exact(10)), page(new HashMap<String, PageElement>(){{124 put("object", absentElement(310, 250, 100, 50));125 }})},126 {validationResult(NO_AREA, messages("\"object\" is not visible on page")),127 specHeight(exact(10)), page(new HashMap<String, PageElement>(){{128 put("object", invisibleElement(310, 250, 100, 50));129 }})},130 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" height is 50px instead of 10px")),131 specHeight(exact(10)), page(new HashMap<String, PageElement>(){{132 put("object", element(100, 100, 100, 50));133 }})},134 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" height is 50px which is not in range of 10 to 40px")),135 specHeight(between(10, 40)), page(new HashMap<String, PageElement>(){{136 put("object", element(100, 100, 100, 50));137 }})},138 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" height is 25% [50px] instead of 10% [20px]")),139 specHeight(exact(10).withPercentOf("container/height")), page(new HashMap<String, PageElement>(){{140 put("object", element(100, 100, 100, 50));141 put("container", element(100, 100, 100, 200));142 }})},143 {validationResult(singleArea(new Rect(100, 100, 100, 50), "object"), messages("\"object\" height is 25% [50px] which is not in range of 10 to 15% [20 to 30px]")),144 specHeight(between(10, 15).withPercentOf("container/height")), page(new HashMap<String, PageElement>(){{145 put("object", element(100, 100, 100, 50));146 put("container", element(100, 100, 100, 200));147 }})}148 };149 }150 private SpecHeight specHeight(Range range) {151 return new SpecHeight(range);152 }153 private SpecWidth specWidth(Range range) {154 return new SpecWidth(range);155 }156}...

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful