How to use getObjects method of com.galenframework.specs.page.PageSpec class

Best Galen code snippet using com.galenframework.specs.page.PageSpec.getObjects

Source:PageSpecReaderTest.java Github

copy

Full Screen

...39public class PageSpecReaderTest extends PageSpecReaderTestBase {40 @Test41 public void shouldRead_objectDefinitions() throws IOException {42 PageSpec pageSpec = readPageSpec("speclang2/object-definitions.gspec");43 assertThat(pageSpec.getObjects(), is((Map<String, Locator>)new HashMap<String, Locator>(){{44 put("header", new Locator("css", "#header"));45 put("header-icon", new Locator("css", "#header img"));46 put("button", new Locator("xpath", "//div[@id='button']"));47 put("cancel-link", new Locator("id", "cancel"));48 put("caption", new Locator("css", "#wrapper")49 .withCorrections(new CorrectionsRect(50 new CorrectionsRect.Correction(0, CorrectionsRect.Type.PLUS),51 new CorrectionsRect.Correction(100, CorrectionsRect.Type.PLUS),52 new CorrectionsRect.Correction(5, CorrectionsRect.Type.MINUS),53 new CorrectionsRect.Correction(7, CorrectionsRect.Type.PLUS)54 )));55 }}));56 }57 @Test58 public void shouldRead_objectDefinitions_withMultiObjects() throws IOException {59 PageSpec pageSpec = readPageSpec("speclang2/object-definitions-multi-objects.gspec",60 new SeleniumBrowser(new MockedDriver("/speclang2/mocks/menu-items.json")).getPage(), asList("mobile"), EMPTY_TAGS);61 assertThat(pageSpec.getObjects(), is((Map<String, Locator>)new HashMap<String, Locator>(){{62 put("menu-item-1", new Locator("css", "#menu li", 1));63 put("menu-item-2", new Locator("css", "#menu li", 2));64 put("menu-item-3", new Locator("css", "#menu li", 3));65 put("menu-item-4", new Locator("css", "#menu li", 4));66 }}));67 }68 @Test69 public void shouldRead_objectDefinitions_withMultiLevelObjects() throws IOException {70 PageSpec pageSpec = readPageSpec("speclang2/object-definitions-multi-level-objects.gspec",71 new SeleniumBrowser(new MockedDriver("/speclang2/mocks/multi-level-objects.json")).getPage(), asList("mobile"), EMPTY_TAGS);72 assertThat(pageSpec.getObjects(), is((Map<String, Locator>)new HashMap<String, Locator>(){{73 put("header", new Locator("css", "#header"));74 put("header.icon", new Locator("css", "img")75 .withParent(new Locator("css", "#header")));76 put("header.item-1", new Locator("css", "li", 1).withParent(new Locator("css", "#header")));77 put("header.item-2", new Locator("css", "li", 2).withParent(new Locator("css", "#header")));78 put("box-1", new Locator("css", ".box", 1));79 put("box-1.caption", new Locator("css", ".caption")80 .withParent(new Locator("css", ".box", 1)));81 put("box-2", new Locator("css", ".box", 2));82 put("box-2.caption", new Locator("css", ".caption")83 .withParent(new Locator("css", ".box", 2)));84 put("box-3", new Locator("css", ".box", 3));85 put("box-3.caption", new Locator("css", ".caption")86 .withParent(new Locator("css", ".box", 3)));87 }}));88 }89 @Test90 public void shouldRead_objectDefinitions_withJsBlocks() throws IOException {91 PageSpec pageSpec = readPageSpec("speclang2/objects-with-js-blocks.gspec");92 assertThat(pageSpec.getObjects(), is((Map<String, Locator>)new HashMap<String, Locator>(){{93 put("header_caption", new Locator("css", ".some-header h1"));94 }}));95 }96 @Test97 public void shouldRead_sectionsWithObjectSpecs() throws IOException {98 PageSpec pageSpec = readPageSpec("speclang2/sections-with-object-specs.gspec");99 assertThat(pageSpec.getSections().size(), is(2));100 PageSection section1 = pageSpec.getSections().get(0);101 assertThat(section1.getObjects().size(), is(1));102 assertThat(section1.getObjects().get(0).getObjectName(), is("header"));103 assertThat(section1.getObjects().get(0).getSpecs().size(), is(1));104 assertThat(section1.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("height 100px"));105 assertThat(section1.getSections().size(), is(1));106 PageSection subSection = section1.getSections().get(0);107 assertThat(subSection.getObjects().size(), is(2));108 assertThat(subSection.getObjects().get(0).getObjectName(), is("login-link"));109 assertThat(subSection.getObjects().get(0).getSpecs().size(), is(1));110 assertThat(subSection.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("height 30px"));111 assertThat(subSection.getObjects().get(1).getObjectName(), is("register-link"));112 assertThat(subSection.getObjects().get(1).getSpecs().size(), is(1));113 assertThat(subSection.getObjects().get(1).getSpecs().get(0).getOriginalText(), is("right-of login-link 10 to 30px"));114 PageSection section2 = pageSpec.getSections().get(1);115 assertThat(section2.getName(), is("Main section"));116 assertThat(section2.getObjects().size(), is(1));117 assertThat(section2.getObjects().get(0).getObjectName(), is("main-section"));118 assertThat(section2.getObjects().get(0).getSpecs().size(), is(2));119 assertThat(section2.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("below header 0 to 5px"));120 assertThat(section2.getObjects().get(0).getSpecs().get(1).getOriginalText(), is("inside screen 0px left right"));121 }122 @Test123 public void shouldProcess_complexObjectExpressions_insideSections() throws IOException {124 PageSpec pageSpec = readPageSpec("speclang2/complex-object-expressions.gspec");125 PageSection section = pageSpec.getSections().get(0);126 assertThat(section.getName(), is("Main section"));127 assertThat(section.getObjects().size(), is(6));128 assertThat(section.getPlace(), is(new Place("speclang2/complex-object-expressions.gspec", 16)));129 assertThat(section.getObjects().get(0).getObjectName(), is("header"));130 assertThat(section.getObjects().get(0).getSpecs().size(), is(1));131 assertThat(section.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("inside screen 0px left right"));132 assertThat(section.getObjects().get(1).getObjectName(), is("menu"));133 assertThat(section.getObjects().get(1).getSpecs().size(), is(1));134 assertThat(section.getObjects().get(1).getSpecs().get(0).getOriginalText(), is("inside screen 0px left right"));135 assertThat(section.getObjects().get(2).getObjectName(), is("main"));136 assertThat(section.getObjects().get(2).getSpecs().size(), is(1));137 assertThat(section.getObjects().get(2).getSpecs().get(0).getOriginalText(), is("inside screen 0px left right"));138 assertThat(section.getObjects().get(3).getObjectName(), is("menu-item-1"));139 assertThat(section.getObjects().get(3).getSpecs().size(), is(1));140 assertThat(section.getObjects().get(3).getSpecs().get(0).getOriginalText(), is("height 30px"));141 assertThat(section.getObjects().get(4).getObjectName(), is("menu-item-2"));142 assertThat(section.getObjects().get(4).getSpecs().size(), is(1));143 assertThat(section.getObjects().get(4).getSpecs().get(0).getOriginalText(), is("height 30px"));144 assertThat(section.getObjects().get(5).getObjectName(), is("menu-item-3"));145 assertThat(section.getObjects().get(5).getSpecs().size(), is(1));146 assertThat(section.getObjects().get(5).getSpecs().get(0).getOriginalText(), is("height 30px"));147 }148 @Test149 public void shouldProcess_hashInObjectPattern_asDigits() throws IOException {150 PageSpec pageSpec = readPageSpec("speclang2/hash-in-object-name.gspec");151 PageSection section = pageSpec.getSections().get(0);152 assertThat(section.getObjects().size(), is(2));153 assertThat(section.getObjects().get(0).getObjectName(), is("item-1"));154 assertThat(section.getObjects().get(1).getObjectName(), is("item-342"));155 }156 /**157 * Purpose of this test is to check that "${}" expressions could be processed everywhere158 */159 @Test160 public void shouldRead_variablesDefinition_andProcessThem() throws IOException {161 PageSpec pageSpec = readPageSpec("speclang2/variables-and-processing.gspec");162 assertThat(pageSpec.getSections().size(), is(1));163 assertThat(pageSpec.getSections().get(0).getName(), is("Section for user Johny"));164 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getObjectName(), is("welcome-message"));165 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().get(0).getOriginalText(), is("text is \"Welcome, Johny\""));166 }167 @Test168 public void shouldRead_simpleForLoop_andProcessIt() throws IOException {169 PageSpec pageSpec = readPageSpec("speclang2/for-loop.gspec");170 assertThat(pageSpec.getSections().size(), is(1));171 assertThat(pageSpec.getSections().get(0).getName(), is("Main section"));172 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(13));173 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();174 int objectIndex = 0;175 for (int i = 1; i <= 3; i++) {176 for (Integer j : asList(5, 7, 9)) {177 assertThat("Object #" + objectIndex + " name should be",178 objects.get(objectIndex).getObjectName(),179 is("box-" + i + "-" + j));180 assertThat("Object #" + objectIndex + " spec should be",181 objects.get(objectIndex).getSpecs().get(0).getOriginalText(),182 is("text is \"" + i + " and " + j + "\""));183 objectIndex++;184 }185 assertThat("Object #" + objectIndex + " name should be",186 objects.get(objectIndex).getObjectName(),187 is("label-" + i));188 assertThat("Object #" + objectIndex + " spec should be",189 objects.get(objectIndex).getSpecs().get(0).getOriginalText(),190 is("height 10px"));191 objectIndex++;192 }193 assertThat("Object #11 name should be",194 objects.get(objectIndex).getObjectName(),195 is("caption"));196 assertThat("Object #11 spec should be",197 objects.get(objectIndex).getSpecs().get(0).getOriginalText(),198 is("width 50px"));199 }200 @Test201 public void shouldRead_eachLoop_andProcessIt() throws IOException {202 PageSpec pageSpec = readPageSpec("speclang2/foreach-loop.gspec");203 assertThat(pageSpec.getSections().size(), is(3));204 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();205 assertThat(objects.size(), is(4));206 for (int i = 0; i < 4; i++) {207 assertThat("Section 1. Object #" + i + " name should be", objects.get(i).getObjectName(),208 is("menu-item-" + (i+1)));209 assertThat("Section 1. Object #" + i + " spec should be", objects.get(i).getSpecs().get(0).getOriginalText(),210 is("width 100px"));211 }212 List<ObjectSpecs> objects2 = pageSpec.getSections().get(1).getObjects();213 assertThat(objects2.size(), is(3));214 for (int i = 0; i < 3; i++) {215 assertThat("Section 2. Object #" + i + " name should be", objects2.get(i).getObjectName(),216 is("menu-item-" + (i+2)));217 assertThat("Section 2. Object #" + i + " spec should be", objects2.get(i).getSpecs().get(0).getOriginalText(),218 is("right-of menu-item-" + (i+1) + " 10px"));219 }220 List<ObjectSpecs> objects3 = pageSpec.getSections().get(2).getObjects();221 assertThat(objects3.size(), is(3));222 for (int i = 0; i < 3; i++) {223 assertThat("Section 3. Object #" + i + " name should be", objects3.get(i).getObjectName(),224 is("menu-item-" + (i+1)));225 assertThat("Section 3. Object #" + i + " spec should be", objects3.get(i).getSpecs().get(0).getOriginalText(),226 is("left-of menu-item-" + (i + 2) + " 10px"));227 }228 }229 /**230 * Comes from https://github.com/galenframework/galen/issues/303231 */232 @Test233 public void shouldRead_emptyLoops_withoutException() throws IOException {234 PageSpec pageSpec = readPageSpec("speclang2/empty-for-loops.gspec", EMPTY_PAGE, EMPTY_TAGS, EMPTY_TAGS);235 assertThat(pageSpec.getSections().size(), is(0));236 }237 @Test238 public void shouldLoopOver_existingAndNonExisting_objects() throws IOException {239 PageSpec pageSpec = readPageSpec("speclang2/foreach-loop-with-nonexisting-objects.gspec");240 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();241 assertThat(objects.size(), is(6));242 assertThat(objects.get(0).getObjectName(), is("menu-item-1"));243 assertThat(objects.get(1).getObjectName(), is("menu-item-2"));244 assertThat(objects.get(2).getObjectName(), is("menu-item-3"));245 assertThat(objects.get(3).getObjectName(), is("header"));246 assertThat(objects.get(4).getObjectName(), is("toolbar"));247 assertThat(objects.get(5).getObjectName(), is("popup"));248 }249 @Test250 public void shouldRead_taggedSections_andProcessOnlyThose_thatMatchGivenTags_1() throws IOException {251 PageSpec pageSpec = readPageSpec("speclang2/tagged-sections.gspec", EMPTY_PAGE, asList("mobile"), EMPTY_TAGS);252 assertThat(pageSpec.getSections().size(), is(1));253 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();254 assertThat(objects.size(), is(2));255 assertThat(objects.get(0).getObjectName(), is("header"));256 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("height 100px"));257 assertThat(objects.get(1).getObjectName(), is("header-icon"));258 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("inside header 5px top left"));259 }260 @Test261 public void shouldRead_taggedSections_andProcessOnlyThose_thatMatchGivenTags_2() throws IOException {262 PageSpec pageSpec = readPageSpec("speclang2/tagged-sections.gspec", EMPTY_PAGE, asList("tablet"), EMPTY_TAGS);263 assertThat(pageSpec.getSections().size(), is(1));264 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();265 assertThat(objects.size(), is(2));266 assertThat(objects.get(0).getObjectName(), is("header"));267 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("height 100px"));268 assertThat(objects.get(1).getObjectName(), is("header-icon"));269 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("inside header 5px top left"));270 }271 @Test272 public void shouldRead_taggedSections_andProcessOnlyThose_thatMatchGivenTags_3() throws IOException {273 PageSpec pageSpec = readPageSpec("speclang2/tagged-sections.gspec", EMPTY_PAGE, asList("desktop"), EMPTY_TAGS);274 assertThat(pageSpec.getSections().size(), is(1));275 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();276 assertThat(objects.size(), is(2));277 assertThat(objects.get(0).getObjectName(), is("header"));278 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("height 200px"));279 assertThat(objects.get(1).getObjectName(), is("header-icon"));280 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("inside header 5px top left"));281 }282 @Test283 public void shouldRead_taggedSections_andExcludeTags() throws IOException {284 PageSpec pageSpec = readPageSpec("speclang2/tagged-sections.gspec", EMPTY_PAGE, asList("mobile", "desktop"), asList("tablet"));285 assertThat(pageSpec.getSections().size(), is(1));286 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();287 assertThat(objects.size(), is(2));288 assertThat(objects.get(0).getObjectName(), is("header"));289 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("height 200px"));290 assertThat(objects.get(1).getObjectName(), is("header-icon"));291 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("inside header 5px top left"));292 }293 @Test294 public void should_importOtherPageSpecs_onlyOnce_andMergeSectionsAndObjects() throws IOException {295 PageSpec pageSpec = readPageSpec("speclang2/import-other-pagespecs.gspec");296 assertThat(pageSpec.getObjects(), is((Map<String, Locator>) new HashMap<String, Locator>() {{297 put("header", new Locator("css", "#header"));298 put("main-container", new Locator("css", "#main"));299 }}));300 assertThat(pageSpec.getSections().size(), is(2));301 assertThat(pageSpec.getSections().get(0).getName(), is("Header section"));302 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(1));303 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getObjectName(), is("header"));304 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().size(), is(2));305 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().get(0).getOriginalText(), is("inside screen 0px top left right"));306 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().get(1).getOriginalText(), is("height 100px"));307 assertThat(pageSpec.getSections().get(1).getName(), is("Main section"));308 assertThat(pageSpec.getSections().get(1).getObjects().size(), is(1));309 assertThat(pageSpec.getSections().get(1).getObjects().get(0).getObjectName(), is("main-container"));310 assertThat(pageSpec.getSections().get(1).getObjects().get(0).getSpecs().size(), is(1));311 assertThat(pageSpec.getSections().get(1).getObjects().get(0).getSpecs().get(0).getOriginalText(), is("below header 0px"));312 }313 @Test314 public void shouldImportOtherSpecs_whenMainSpecIsLoaded_fromAbsolutePath() throws IOException {315 PageSpec pageSpec = readPageSpec(new File(getClass().getResource("/speclang2/import-other-pagespecs.gspec").getFile()).getAbsolutePath());316 assertThat(pageSpec.getObjects(), is((Map<String, Locator>) new HashMap<String, Locator>() {{317 put("header", new Locator("css", "#header"));318 put("main-container", new Locator("css", "#main"));319 }}));320 }321 @Test322 public void shouldExecute_customJavaScript_fromSeparateFile() throws IOException {323 PageSpec pageSpec = readPageSpec("speclang2/script-importing.gspec");324 assertThat(pageSpec.getSections().size(), is(1));325 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();326 assertThat(objects.size(), is(2));327 assertThat(objects.get(0).getObjectName(), is("caption"));328 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("text is \"Awesome website!\""));329 assertThat(objects.get(1).getObjectName(), is("caption-2"));330 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("text is \"Welcome, Johny\""));331 }332 @Test333 public void scriptsPath_shouldBeResolved_whenSpecIsLoaded_fromAbsolutePath() throws IOException {334 String absolutePath = new File(getClass().getResource("/speclang2/script-importing.gspec").getFile()).getAbsolutePath();335 PageSpec pageSpec = readPageSpec(absolutePath);336 assertThat(pageSpec.getSections().size(), is(1));337 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();338 assertThat(objects.size(), is(2));339 assertThat(objects.get(0).getObjectName(), is("caption"));340 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("text is \"Awesome website!\""));341 assertThat(objects.get(1).getObjectName(), is("caption-2"));342 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("text is \"Welcome, Johny\""));343 }344 @Test345 public void shouldExecute_inPageJavaScript() throws IOException {346 PageSpec pageSpec = readPageSpec("speclang2/script-inpage.gspec");347 assertThat(pageSpec.getSections().size(), is(1));348 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();349 assertThat(objects.size(), is(2));350 assertThat(objects.get(0).getObjectName(), is("caption"));351 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("text is \"Awesome website!\""));352 assertThat(objects.get(1).getObjectName(), is("caption-2"));353 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("text is \"Welcome, Johny\""));354 }355 @Test(expectedExceptions = SyntaxException.class,356 expectedExceptionsMessageRegExp = "JavaScript error inside statement\n in speclang2/error-in-js-block.gspec:8"357 )358 public void shouldFail_whenThereIsError_inJavaScriptBlock() throws IOException {359 readPageSpec("speclang2/error-in-js-block.gspec",360 new MockedPage(new HashMap<String, PageElement>()),361 EMPTY_TAGS, EMPTY_TAGS);362 }363 @Test364 public void shouldRead_conditionsWithMultipleElseBlocks() throws IOException {365 PageSpec pageSpec = readPageSpec("speclang2/conditions.gspec",366 new MockedPage(new HashMap<String, PageElement>() {{367 put("header", element(0, 0, 100, 10));368 }}),369 EMPTY_TAGS, EMPTY_TAGS);370 assertThat(pageSpec.getSections().size(), is(1));371 PageSection section = pageSpec.getSections().get(0);372 assertThat(section.getObjects().size(), is(1));373 assertThat(section.getObjects().get(0).getObjectName(), is("header-icon"));374 assertThat(section.getObjects().get(0).getSpecs().size(), is(1));375 assertThat(section.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("inside header 10px top left"));376 }377 @Test378 public void shouldRead_conditionsWithMultipleElseBlocks_2() throws IOException {379 PageSpec pageSpec = readPageSpec("speclang2/conditions.gspec",380 new MockedPage(new HashMap<String, PageElement>(){{381 put("header", invisibleElement(0, 0, 100, 10));382 put("header2", element(0, 0, 100, 10));383 }}),384 EMPTY_TAGS, EMPTY_TAGS);385 assertThat(pageSpec.getSections().size(), is(1));386 PageSection section = pageSpec.getSections().get(0);387 assertThat(section.getObjects().size(), is(1));388 assertThat(section.getObjects().get(0).getObjectName(), is("header2-icon"));389 assertThat(section.getObjects().get(0).getSpecs().size(), is(1));390 assertThat(section.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("inside header2 5px top left"));391 }392 @Test393 public void shouldRead_conditionsWithMultipleElseBlocks_3() throws IOException {394 PageSpec pageSpec = readPageSpec("speclang2/conditions.gspec",395 new MockedPage(new HashMap<String, PageElement>(){{396 put("header", invisibleElement(0, 0, 100, 10));397 put("header2", invisibleElement(0, 0, 100, 10));398 }}),399 EMPTY_TAGS, EMPTY_TAGS);400 assertThat(pageSpec.getSections().size(), is(1));401 PageSection section = pageSpec.getSections().get(0);402 assertThat(section.getObjects().size(), is(1));403 assertThat(section.getObjects().get(0).getObjectName(), is("header3"));404 assertThat(section.getObjects().get(0).getSpecs().size(), is(1));405 assertThat(section.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("visible"));406 }407 @Test(expectedExceptions = SyntaxException.class,408 expectedExceptionsMessageRegExp = "JavaScript error inside statement\n in speclang2/condition-with-js-error.gspec:5"409 )410 public void shouldFail_whenThereIsAnError_insideIfStatement() throws IOException {411 readPageSpec("speclang2/condition-with-js-error.gspec",412 new MockedPage(new HashMap<String, PageElement>()),413 EMPTY_TAGS, EMPTY_TAGS);414 }415 @Test416 public void shouldAllow_toPassProperties() throws IOException {417 Properties properties = new Properties();418 properties.put("custom.user.name", "John");419 PageSpec pageSpec = new PageSpecReader().read("speclang2/properties.gspec", EMPTY_PAGE, new SectionFilter(EMPTY_TAGS, EMPTY_TAGS), properties, NO_VARS, EMPTY_OBJECTS);420 assertThat(pageSpec.getSections().get(0).getName(), is("Main section for user John"));421 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().get(0).getOriginalText(),422 is("text is \"Welcome, John!\""));423 }424 @Test(expectedExceptions = SyntaxException.class,425 expectedExceptionsMessageRegExp = "\\QExpecting \"px\", \"to\" or \"%\", got \"\"\n in \\E.*speclang2/syntax-error.gspec:9")426 public void shouldThrow_fileSyntaxException_ifThereIsAnErrorInSpec() throws IOException {427 readPageSpec("speclang2/syntax-error.gspec");428 }429 @Test430 public void shouldAllow_mathExpressions_onIntegerValues_onForLoopIndexes() throws IOException {431 PageSpec pageSpec = readPageSpec("speclang2/for-loop-math-expression.gspec");432 PageSection section = pageSpec.getSections().get(0);433 assertThat(section.getObjects().size(), is(4));434 assertThat(section.getObjects().get(0).getSpecs().get(0).getOriginalText(),435 is("right-of menu-item-3"));436 assertThat(section.getObjects().get(1).getSpecs().get(0).getOriginalText(),437 is("right-of menu-item-5"));438 assertThat(section.getObjects().get(2).getSpecs().get(0).getOriginalText(),439 is("right-of menu-item-7"));440 assertThat(section.getObjects().get(3).getSpecs().get(0).getOriginalText(),441 is("right-of menu-item-9"));442 }443 @Test444 public void shouldParse_forLoops_withIfStatements() throws IOException {445 PageSpec pageSpec = readPageSpec("speclang2/for-with-if.gspec");446 PageSection section = pageSpec.getSections().get(0);447 assertThat(section.getObjects().size(), is(1));448 assertThat(section.getObjects().get(0).getSpecs().size(), is(2));449 assertThat(section.getObjects().get(0).getObjectName(),450 is("button"));451 assertThat(section.getObjects().get(0).getSpecs().get(0).getOriginalText(),452 is("inside container1 10px top left"));453 assertThat(section.getObjects().get(0).getSpecs().get(1).getOriginalText(),454 is("inside container2 10px top left"));455 }456 @Test457 public void shouldRead_specsWithWarningLevel() throws IOException {458 PageSpec pageSpec = readPageSpec("speclang2/warning-level-in-specs.gspec");459 PageSection section = pageSpec.getSections().get(0);460 assertThat(section.getObjects().get(0).getSpecs().get(0).isOnlyWarn(), is(false));461 assertThat(section.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("width 100px"));462 assertThat(section.getObjects().get(0).getSpecs().get(1).isOnlyWarn(), is(true));463 assertThat(section.getObjects().get(0).getSpecs().get(1).getOriginalText(), is("height 100px"));464 }465 @Test466 public void shouldRead_specAliases_beforeActualSpecs() throws IOException {467 PageSpec pageSpec = readPageSpec("speclang2/spec-notes.gspec");468 PageSection section = pageSpec.getSections().get(0);469 assertThat(section.getObjects().size(), is(1));470 ObjectSpecs object = section.getObjects().get(0);471 assertThat(object.getSpecs().size(), is(3));472 assertThat(object.getSpecs().get(0).getAlias(), is(nullValue()));473 assertThat(object.getSpecs().get(0).getOriginalText(), is("height 100px"));474 assertThat(object.getSpecs().get(1).getAlias(), is("should be visible"));475 assertThat(object.getSpecs().get(1).getOriginalText(), is("visible"));476 assertThat(object.getSpecs().get(2).getAlias(), is("should be on top"));477 assertThat(object.getSpecs().get(2).getOriginalText(), is("inside screen 0px top"));478 }479 @Test480 public void shouldAllow_toPassCustomJsObjects() throws IOException {481 PageSpec pageSpec = new PageSpecReader().read(482 "speclang2/custom-js-variables.gspec",483 EMPTY_PAGE,484 new SectionFilter(EMPTY_TAGS, EMPTY_TAGS),485 NO_PROPERTIES,486 new HashMap<String, Object>() {{487 put("age", 29);488 put("userName", "John");489 }}, EMPTY_OBJECTS);490 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().get(0).getOriginalText(),491 is("text is \"Name: John, age: 29\""));492 }493 @Test494 public void shouldClean_emptySetions() throws IOException {495 PageSpec pageSpec = readPageSpec("speclang2/empty-sections.gspec");496 assertThat(pageSpec.getSections().size(), is(1));497 PageSection section = pageSpec.getSections().get(0);498 assertThat(section.getSections().size(), is(0));499 assertThat(section.getObjects().size(), is(1));500 }501 @Test502 public void countFunction_shouldCountAllMatchingObjects() throws IOException {503 PageSpec pageSpec = readPageSpec("speclang2/count.gspec");504 assertThat(pageSpec.getSections().size(), is(2));505 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(6));506 assertThat(pageSpec.getSections().get(1).getObjects().size(), is(3));507 }508 @Test509 public void forEachLoop_shouldOrderCorrectly_objectsWithNumbers() throws IOException {510 PageSpec pageSpec = readPageSpec("speclang2/foreach-sortorder.gspec");511 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();512 assertThat(objects.size(), is(4));513 assertThat(objects.get(0).getObjectName(), is("menu-item-1"));514 assertThat(objects.get(1).getObjectName(), is("menu-item-2"));515 assertThat(objects.get(2).getObjectName(), is("menu-item-12"));516 assertThat(objects.get(3).getObjectName(), is("menu-item-101"));517 }518 @Test519 public void forEachLoop_shouldAllow_toUseIndex() throws IOException {520 PageSpec pageSpec = readPageSpec("speclang2/forEach-loop-with-index.gspec");521 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();522 assertThat(objects.size(), is(3));523 assertThat(objects.get(0).getObjectName(), is("item-1"));524 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("inside screen 100px top"));525 assertThat(objects.get(1).getObjectName(), is("item-2"));526 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("inside screen 200px top"));527 assertThat(objects.get(2).getObjectName(), is("item-3"));528 assertThat(objects.get(2).getSpecs().get(0).getOriginalText(), is("inside screen 300px top"));529 }530 @Test531 public void shouldAllow_toProvideObjects_toPageSpec() throws IOException {532 Map<String, Locator> objects = new HashMap<>();533 objects.put("header", new Locator("css", "#header"));534 objects.put("menu", new Locator("id", "menu"));535 PageSpec pageSpec = new PageSpecReader().read("speclang2/provide-objects.gspec", EMPTY_PAGE, new SectionFilter(EMPTY_TAGS, EMPTY_TAGS), NO_PROPERTIES, NO_VARS, objects);536 assertThat(pageSpec.getObjects(), allOf(537 hasEntry("header", new Locator("css", "#header")),538 hasEntry("menu", new Locator("id", "menu")),539 hasEntry("button", new Locator("css", "#button"))540 ));541 }542 @Test543 public void customRules_shouldAllow_toUse_ruleBodies_inSpecs() throws IOException {544 PageSpec pageSpec = readPageSpec("speclang2/custom-rules-using-rule-body.gspec",545 new MockedPage(new HashMap<String, PageElement>(){{546 put("banner-1", element(0, 0, 100, 10));547 put("banner-2", invisibleElement(0, 0, 100, 10));548 }}),549 EMPTY_TAGS, EMPTY_TAGS);550 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(1));551 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().size(), is(1));552 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getSpecs().get(0).getOriginalText(), is("height 90px"));553 assertThat(pageSpec.getSections().get(0).getSections().size(), is(2));554 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getSections().get(0).getObjects();555 assertThat(objects.size(), is(1));556 assertThat(objects.get(0).getObjectName(), is("banner-1"));557 assertThat(objects.get(0).getSpecs().size(), is(1));558 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("width 145px"));559 objects = pageSpec.getSections().get(0).getSections().get(1).getObjects();560 assertThat(objects.size(), is(1));561 assertThat(objects.get(0).getObjectName(), is("banner-3"));562 assertThat(objects.get(0).getSpecs().size(), is(1));563 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("visible"));564 }565 @Test566 public void shouldRead_objectClasses_inObjectsSection() throws IOException {567 PageSpec pageSpec = readPageSpec("speclang2/object-groups-definition.gspec");568 assertThat(pageSpec.getObjectGroups(), hasEntry("image-validation", asList("menu.item-1", "button")));569 assertThat(pageSpec.getObjectGroups(), hasEntry("menu-stuff", asList("menu.item-1")));570 }571 @Test572 public void shouldApply_objectGroups_toAlreadyProcessedObjects() throws IOException {573 PageSpec pageSpec = readPageSpec("speclang2/object-groups-added.gspec");574 assertThat(pageSpec.getObjectGroups(), hasEntry("groupA", asList("obj1", "obj3")));575 assertThat(pageSpec.getObjectGroups(), hasEntry("groupB", asList("obj1", "obj3")));576 assertThat(pageSpec.getObjectGroups(), hasEntry("groupC", asList("obj1", "obj2", "obj3")));577 }578 @Test579 public void countFunction_shouldWorkWithGroups() throws IOException {580 PageSpec pageSpec = readPageSpec("speclang2/count-grouped-objects.gspec");581 assertThat(firstAppearingSpecIn(pageSpec), is("text is \"count is 4\""));582 }583 @Test584 public void findFunction_shouldWorkWithGroups() throws IOException {585 PageSpec pageSpec = readPageSpec("speclang2/find-grouped-object.gspec");586 assertThat(firstAppearingObjectIn(pageSpec).getObjectName(), is("menu_item-1"));587 }588 @Test589 public void firstFunction_shouldWorkWithGroups() throws IOException {590 PageSpec pageSpec = readPageSpec("speclang2/first-grouped-object.gspec");591 assertThat(firstAppearingObjectIn(pageSpec).getObjectName(), is("menu_item-1"));592 }593 @Test594 public void lastFunction_shouldWorkWithGroups() throws IOException {595 PageSpec pageSpec = readPageSpec("speclang2/last-grouped-object.gspec");596 assertThat(firstAppearingObjectIn(pageSpec).getObjectName(), is("menu_icon"));597 }598 @Test599 public void shouldFind_allObjects_forSpecifiedGroups_inRegularObjectStatement() throws IOException {600 PageSpec pageSpec = readPageSpec("speclang2/object-groups-search.gspec");601 assertSearchAndForEachGroupsElements(pageSpec);602 }603 @Test604 public void shouldFind_allObjects_forSpecifiedGroups_forEachLoop() throws IOException {605 PageSpec pageSpec = readPageSpec("speclang2/object-groups-foreach.gspec");606 assertSearchAndForEachGroupsElements(pageSpec);607 }608 private void assertSearchAndForEachGroupsElements(PageSpec pageSpec) {609 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();610 assertThat(objects.size(), is(2));611 assertThat(objects.get(0).getObjectName(), is("cancel-button"));612 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("height 30px"));613 assertThat(objects.get(1).getObjectName(), is("login-button"));614 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("height 30px"));615 }616 @Test617 public void shouldFind_allObjects_forSpecifiedGroups_inJavaScriptFindAllFunction() throws IOException {618 PageSpec pageSpec = readPageSpec("speclang2/object-groups-findAll.gspec",619 new MockedPage(new HashMap<String, PageElement>()),620 EMPTY_TAGS, EMPTY_TAGS);621 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();622 assertThat(objects.size(), is(2));623 assertThat(objects.get(0).getObjectName(), is("cancel-button"));624 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is("height 30px"));625 assertThat(objects.get(1).getObjectName(), is("login-button"));626 assertThat(objects.get(1).getSpecs().get(0).getOriginalText(), is("height 30px"));627 }628 /**629 * When nonexisting object is passed to findAll function - it should return an instance of JsPageElement that630 * will give 0 for any location related values like width, height, right etc. Also it should return false for631 * isVisible function.632 * @throws IOException633 */634 @Test635 public void findAll_andFind_functions_shouldHave_strictObjectProcessing_likeForEachLoop() throws IOException {636 PageSpec pageSpec = readPageSpec("speclang2/findAll-nonexisting-objects.gspec");637 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();638 assertThat(objects.size(), is(1));639 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is(640 "text is \"header[0, 0, 0, 0, false], menu[0, 0, 0, 0, false]\""641 ));642 assertThat(objects.get(0).getSpecs().get(1).getOriginalText(), is(643 "text is \"header[0, 0, 0, 0, false]\""644 ));645 }646 @Test647 public void screenAndViewportObjects_shouldBeAccessible_fromJavaScript_codeBlocks() throws IOException {648 MockedDriver driver = new MockedDriver();649 driver.setExpectedJavaScriptReturnValues(asList(650 (Object)asList(1000L, 700L),651 (Object)asList(900L, 700L)652 ));653 PageSpec pageSpec = readPageSpec("speclang2/screen-and-viewport-from-js.gspec", new SeleniumPage(driver));654 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();655 assertThat(objects.size(), is(1));656 assertThat(objects.get(0).getSpecs().get(0).getOriginalText(), is(657 "width 120 px"658 ));659 }660 @Test661 public void shouldAllowToInvoke_first_function() throws IOException {662 PageSpec pageSpec = readPageSpec("speclang2/first-function.gspec");663 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();664 assertThat(objects.size(), is(1));665 assertThat(objects.get(0).getObjectName(), is("menu_item-1"));666 }667 @Test668 public void shouldAllowToInvoke_last_function() throws IOException {669 PageSpec pageSpec = readPageSpec("speclang2/last-function.gspec");670 List<ObjectSpecs> objects = pageSpec.getSections().get(0).getObjects();671 assertThat(objects.size(), is(1));672 assertThat(objects.get(0).getObjectName(), is("menu_item-3"));673 }674 @Test675 public void ruleShouldAllows_toUseColon_atTheEnd() throws IOException {676 PageSpec pageSpec = readPageSpec("speclang2/rule-colon-at-end.gspec");677 assertThat(pageSpec.getSections().size(), is(1));678 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(0));679 assertThat(pageSpec.getSections().get(0).getSections().size(), is(1));680 assertThat(pageSpec.getSections().get(0).getSections().get(0).getObjects().size(), is(1));681 ObjectSpecs object = pageSpec.getSections().get(0).getSections().get(0).getObjects().get(0);682 assertThat(object.getObjectName(), is("menu_item-1"));683 assertThat(object.getSpecs().size(), is(1));684 assertThat(object.getSpecs().get(0).getOriginalText(), is("width 100px"));685 }686 @Test687 public void ruleShouldHave_priorityOverRules_thatWereDeclaredFirst() throws IOException {688 PageSpec pageSpec = readPageSpec("speclang2/rule-priority.gspec");689 assertThat(pageSpec.getSections().size(), is(1));690 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(1));691 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getObjectName(), is("cancel_button"));692 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().size(), is(1));693 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getSpecs().size(), is(1));694 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getSpecs().get(0).getOriginalText(), is("width 30px"));695 assertThat(pageSpec.getSections().get(0).getSections().size(), is(1));696 assertThat(pageSpec.getSections().get(0).getSections().get(0).getObjects().size(), is(1));697 ObjectSpecs object = pageSpec.getSections().get(0).getSections().get(0).getObjects().get(0);698 assertThat(object.getObjectName(), is("login_button"));699 assertThat(object.getSpecs().size(), is(1));700 assertThat(object.getSpecs().get(0).getOriginalText(), is("width 300px"));701 }702 @Test(expectedExceptions = SyntaxException.class,703 expectedExceptionsMessageRegExp = "\\QError processing rule: button is located at the left side inside main_container with 10px margin\\E\\s+\\Qin speclang2/rule-error.gspec:7\\E")704 public void shouldThrownInformativeError_whenThereIsProblemParsingTheRule() throws IOException {705 readPageSpec("speclang2/rule-error.gspec");706 }707 @Test(expectedExceptions = SyntaxException.class,708 expectedExceptionsMessageRegExp = "\\QError processing rule: is located at the left side inside main_container with 10px margin\\E\\s+\\Qin speclang2/rule-error-object-level.gspec:7\\E")709 public void shouldThrownInformativeError_whenThereIsProblemParsingTheRule_inObjectLevel() throws IOException {710 readPageSpec("speclang2/rule-error-object-level.gspec");711 }...

Full Screen

Full Screen

Source:PageSpecReaderRulesTest.java Github

copy

Full Screen

...31 assertThat(pageSpec.getSections().get(0).getName(), is("Main section"));32 assertThat(pageSpec.getSections().get(0).getSections().size(), is(1));33 PageSection subSection = pageSpec.getSections().get(0).getSections().get(0);34 assertThat(subSection.getName(), is("menu-item-* should be aligned horizontally"));35 assertThat(subSection.getObjects().size(), is(2));36 assertThat(subSection.getObjects().get(0).getObjectName(), is("menu-item-2"));37 assertThat(subSection.getObjects().get(0).getSpecs().size(), is(1));38 assertThat(subSection.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("aligned horizontally all menu-item-1"));39 assertThat(subSection.getObjects().get(1).getObjectName(), is("menu-item-3"));40 assertThat(subSection.getObjects().get(1).getSpecs().size(), is(1));41 assertThat(subSection.getObjects().get(1).getSpecs().get(0).getOriginalText(), is("aligned horizontally all menu-item-2"));42 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(1));43 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getObjectName(), is("menu-item-1"));44 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().size(), is(0));45 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().size(), is(1));46 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getSpecs().size(), is(1));47 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getName(), is("squared"));48 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getSpecs().get(0).getOriginalText(),49 is("width 100 % of menu-item-1/height"));50 }51 @Test52 public void shouldRead_customSpecRulesInSections_withoutOtherObjects_andProcessThem() throws IOException {53 PageSpec pageSpec = readPageSpec("speclang2/custom-rules-only-per-section.gspec");54 assertThat(pageSpec.getSections().size(), is(1));55 assertThat(pageSpec.getSections().get(0).getName(), is("Main section"));56 assertThat(pageSpec.getSections().get(0).getSections().size(), is(1));57 PageSection subSection = pageSpec.getSections().get(0).getSections().get(0);58 assertThat(subSection.getName(), is("menu-item-1 is squared"));59 assertThat(subSection.getObjects().size(), is(1));60 assertThat(subSection.getObjects().get(0).getObjectName(), is("menu-item-1"));61 assertThat(subSection.getObjects().get(0).getSpecs().size(), is(1));62 assertThat(subSection.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("width 100 % of menu-item-1/height"));63 }64 @Test65 public void shouldRead_customRulesFromJavaScript_andProcessThem() throws IOException {66 PageSpec pageSpec = readPageSpec("speclang2/custom-js-rules.gspec",67 new MockedPage(new HashMap<String, PageElement>()),68 EMPTY_TAGS, EMPTY_TAGS);69 assertThat(pageSpec.getSections().size(), is(1));70 assertThat(pageSpec.getSections().get(0).getName(), is("Main section"));71 assertThat(pageSpec.getSections().get(0).getSections().size(), is(1));72 PageSection subSection = pageSpec.getSections().get(0).getSections().get(0);73 assertThat(subSection.getName(), is("menu-item-* should be aligned horizontally"));74 assertThat(subSection.getObjects().size(), is(2));75 assertThat(subSection.getObjects().get(0).getObjectName(), is("menu-item-2"));76 assertThat(subSection.getObjects().get(0).getSpecs().size(), is(1));77 assertThat(subSection.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("aligned horizontally all menu-item-1"));78 assertThat(subSection.getObjects().get(1).getObjectName(), is("menu-item-3"));79 assertThat(subSection.getObjects().get(1).getSpecs().size(), is(1));80 assertThat(subSection.getObjects().get(1).getSpecs().get(0).getOriginalText(), is("aligned horizontally all menu-item-2"));81 assertThat(pageSpec.getSections().get(0).getObjects().size(), is(1));82 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getObjectName(), is("menu-item-1"));83 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecs().size(), is(0));84 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().size(), is(1));85 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getSpecs().size(), is(1));86 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getName(), is("squared"));87 assertThat(pageSpec.getSections().get(0).getObjects().get(0).getSpecGroups().get(0).getSpecs().get(0).getOriginalText(),88 is("width 100 % of menu-item-1/height"));89 }90 @Test91 public void shouldRead_customRules_andNotCare_aboutExtraWhiteSpace() throws IOException {92 PageSpec pageSpec = readPageSpec("speclang2/custom-rules-white-space.gspec",93 new MockedPage(new HashMap<String, PageElement>()),94 EMPTY_TAGS, EMPTY_TAGS);95 assertThat(pageSpec.getSections().size(), is(1));96 PageSection section = pageSpec.getSections().get(0);97 assertThat(section.getSections().size(), is(1));98 PageSection ruleSection = section.getSections().get(0);99 assertThat(ruleSection.getName(), is("login_panel should stretch to screen"));100 assertThat(ruleSection.getObjects().size(), is(1));101 assertThat(ruleSection.getObjects().get(0).getObjectName(), is("login_panel"));102 assertThat(ruleSection.getObjects().get(0).getSpecs().size(), is(1));103 assertThat(ruleSection.getObjects().get(0).getSpecs().get(0).getOriginalText(), is("inside screen 0px left right"));104 }105}...

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1import com.galenframework.reports.TestReport;2import com.galenframework.reports.model.LayoutReport;3import com.galenframework.specs.page.PageSpec;4import com.galenframework.specs.page.Locator;5import com.galenframework.specs.page.PageSection;6import com.galenframework.specs.page.StringLocator;7import com.galenframework.browser.SeleniumBrowser;8import com.galenframework.browser.Browser;9import java.util.List;10import java.util.ArrayList;11public class 1 {12 public static void main(String[] args) throws Exception {13 Browser browser = new SeleniumBrowser();14 TestReport testReport = new TestReport("1");15 PageSpec pageSpec = new PageSpec();16 PageSection pageSection = new PageSection();17 List<Locator> locators = new ArrayList<Locator>();18 pageSection.setLocators(locators);19 pageSpec.addSection("header & footer", pageSection);20 List<String> objects = pageSpec.getObjects("header & footer");21 System.out.println(objects);22 LayoutReport layoutReport = pageSpec.check(browser, "1", testReport);23 System.out.println(layoutReport.getErrorText());24 }25}

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1import com.galenframework.specs.page.PageSpec;2import com.galenframework.specs.page.Locator;3import com.galenframework.specs.page.PageSection;4import com.galenframework.specs.page.PageElement;5import com.galenframework.specs.page.PageSpec;6import com.galenframework.specs.page.Locator;7import com.galenframework.specs.page.PageSection;8import com.galenframework.specs.page.PageElement;9import java.util.List;10import java.util.ArrayList;11public class 1 {12 public static void main(String[] args) {13 PageSpec pageSpec = new PageSpec();14 Locator locator = new Locator();15 locator.setType("xpath");16 PageSection pageSection = new PageSection();17 pageSection.setLocator(locator);18 pageSection.setName("header");19 pageSpec.getSections().add(pageSection);20 locator = new Locator();21 locator.setType("xpath");22 pageSection = new PageSection();23 pageSection.setLocator(locator);24 pageSection.setName("footer");25 pageSpec.getSections().add(pageSection);26 locator = new Locator();27 locator.setType("xpath");28 pageSection = new PageSection();29 pageSection.setLocator(locator);30 pageSection.setName("content");31 pageSpec.getSections().add(pageSection);32 locator = new Locator();33 locator.setType("xpath");34 pageSection = new PageSection();35 pageSection.setLocator(locator);36 pageSection.setName("content1");37 pageSpec.getSections().add(pageSection);38 locator = new Locator();39 locator.setType("xpath");40 pageSection = new PageSection();41 pageSection.setLocator(locator);42 pageSection.setName("content2");43 pageSpec.getSections().add(pageSection);44 locator = new Locator();45 locator.setType("xpath");46 pageSection = new PageSection();47 pageSection.setLocator(locator);48 pageSection.setName("content3");49 pageSpec.getSections().add(pageSection);50 locator = new Locator();51 locator.setType("xpath");

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1import com.galenframework.specs.page.PageSpec;2import com.galenframework.specs.page.Locator;3import com.galenframework.specs.page.PageSection;4import java.util.List;5import java.util.ArrayList;6import java.util.Map;7import java.util.HashMap;8import java.util.Iterator;9import java.util.Set;10import java.util.HashSet;11import java.io.File;12import java.io.IOException;13import java.io.BufferedReader;14import java.io.FileReader;15import java.io.FileWriter;16import java.io.BufferedWriter;17import java.io.PrintWriter;18public class GalenTest {19 public static void main(String[] args) throws IOException {20 String spec = "C:\\Users\\admin\\Desktop\\test\\test.spec";21 String[] specArray = spec.split("\\\\");22 String specName = specArray[specArray.length - 1].split("\\.")[0];23 String specPath = spec.substring(0, spec.lastIndexOf("\\"));24 String report = specPath + "\\" + specName + ".html";25 String reportPath = specPath + "\\" + specName + "_report.txt";26 String logPath = specPath + "\\" + specName + "_log.txt";27 String page = "C:\\Users\\admin\\Desktop\\test\\test.page";28 String[] pageArray = page.split("\\\\");29 String pageName = pageArray[pageArray.length - 1].split("\\.")[0];30 String pagePath = page.substring(0, page.lastIndexOf("\\"));31 String pageReport = pagePath + "\\" + pageName + ".html";32 String pageReportPath = pagePath + "\\" + pageName + "_report.txt";33 String pageLogPath = pagePath + "\\" + pageName + "_log.txt";34 String[] specArray1 = spec.split("\\\\");35 String specName1 = specArray1[specArray1.length - 1].split("\\.")[0];36 String specPath1 = spec.substring(0, spec.lastIndexOf("\\"));37 String report1 = specPath1 + "\\" + specName1 + ".html";38 String reportPath1 = specPath1 + "\\" + specName1 + "_report.txt";39 String logPath1 = specPath1 + "\\" + specName1 + "_log.txt";40 String page1 = "C:\\Users\\admin\\Desktop\\test\\test.page";41 String[] pageArray1 = page1.split("\\\\");

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.sample;2import java.io.IOException;3import java.util.List;4import org.openqa.selenium.WebDriver;5import com.galenframework.browser.Browser;6import com.galenframework.browser.SeleniumBrowser;7import com.galenframework.components.JsErrorChecker;8import com.galenframework.specs.page.PageSpec;9import com.galenframework.specs.page.PageSpecReader;10public class GetObjectsMethod {11 public static void main(String[] args) throws IOException {12 WebDriver driver = new Browser().chromeDriver();13 new JsErrorChecker().checkForErrors(driver);14 PageSpecReader pageSpecReader = new PageSpecReader();15 PageSpec pageSpec = pageSpecReader.read("specs/1.spec");16 List<String> objects = pageSpec.getObjects();17 System.out.println("Objects in the spec file are: " + objects);18 driver.quit();19 }20}

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1import java.io.File;2import java.io.IOException;3import java.util.List;4import java.util.Map;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.chrome.ChromeOptions;8import org.openqa.selenium.remote.DesiredCapabilities;9import com.galenframework.api.Galen;10import com.galenframework.reports.TestReport;11import com.galenframework.reports.model.LayoutReport;12import com.galenframework.reports.model.LayoutReport.LayoutStatus;13import com.galenframework.reports.model.LayoutReport.LayoutStatus.Status;14import com.galenframework.reports.model.LayoutReport.LayoutStatus.StatusDetails;15import com.galenframework.reports.model.LayoutReport.LayoutStatus.StatusDetails.StatusDetail;16import com.galenframework.reports.model.LayoutReport.LayoutStatus.StatusDetails.StatusDetail.StatusType;17import com.galenframework.specs.page.PageSpec;18public class GalenTest {19 public static void main(String[] args) throws IOException {20 String specPath = "src/test/resources/specs/1.spec";21 String layoutSpecPath = "src/test/resources/specs/1.spec";22 String layoutSpecPath1 = "src/test/resources/specs/2.spec";23 String layoutSpecPath2 = "src/test/resources/specs/3.spec";24 String layoutSpecPath3 = "src/test/resources/specs/4.spec";25 String layoutSpecPath4 = "src/test/resources/specs/5.spec";26 String layoutSpecPath5 = "src/test/resources/specs/6.spec";27 String layoutSpecPath6 = "src/test/resources/specs/7.spec";28 String layoutSpecPath7 = "src/test/resources/specs/8.spec";

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1package com.galenframework.specs.page;2import java.util.List;3import com.galenframework.specs.Spec;4public class PageSpec {5 private final List<Spec> specs;6 public PageSpec(List<Spec> specs) {7 this.specs = specs;8 }9 public List<Spec> getObjects() {10 return specs;11 }12}13package com.galenframework.specs.page;14import java.util.List;15import com.galenframework.specs.Spec;16public class PageSpec {17 private final List<Spec> specs;18 public PageSpec(List<Spec> specs) {19 this.specs = specs;20 }21 public List<Spec> getObjects() {22 return specs;23 }24}25package com.galenframework.specs.page;26import java.util.List;27import com.galenframework.specs.Spec;28public class PageSpec {29 private final List<Spec> specs;30 public PageSpec(List<Spec> specs) {31 this.specs = specs;32 }33 public List<Spec> getObjects() {34 return specs;35 }36}37package com.galenframework.specs.page;38import java.util.List;39import com.galenframework.specs.Spec;40public class PageSpec {41 private final List<Spec> specs;42 public PageSpec(List<Spec> specs) {43 this.specs = specs;44 }45 public List<Spec> getObjects() {46 return specs;47 }48}49package com.galenframework.specs.page;50import java.util.List;51import com.galenframework.specs.Spec;52public class PageSpec {53 private final List<Spec> specs;54 public PageSpec(List<Spec> specs) {55 this.specs = specs;56 }57 public List<Spec> getObjects() {58 return specs;59 }60}

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1PageSpec pageSpec = new PageSpec("path to spec file");2List<Spec> specs = pageSpec.getObjects();3for(Spec spec : specs){4 System.out.println(spec);5}6PageSpec pageSpec = new PageSpec("path to spec file");7List<Spec> specs = pageSpec.getObjects();8for(Spec spec : specs){9 System.out.println(spec);10}11PageSpec pageSpec = new PageSpec("path to spec file");12List<Spec> specs = pageSpec.getObjects();13for(Spec spec : specs){14 System.out.println(spec);15}16PageSpec pageSpec = new PageSpec("path to spec file");17List<Spec> specs = pageSpec.getObjects();18for(Spec spec : specs){19 System.out.println(spec);20}21PageSpec pageSpec = new PageSpec("path to spec file");22List<Spec> specs = pageSpec.getObjects();23for(Spec spec : specs){24 System.out.println(spec);25}26PageSpec pageSpec = new PageSpec("path to spec file");27List<Spec> specs = pageSpec.getObjects();28for(Spec spec : specs){29 System.out.println(spec);30}31PageSpec pageSpec = new PageSpec("path to spec file");32List<Spec> specs = pageSpec.getObjects();33for(Spec spec : specs){34 System.out.println(spec);35}36PageSpec pageSpec = new PageSpec("path to spec file");37List<Spec> specs = pageSpec.getObjects();38for(Spec spec : specs){39 System.out.println(spec);40}

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1import com.galenframework.specs.page.PageSpec;2import com.galenframework.specs.page.ObjectSpec;3import java.io.File;4import java.io.IOException;5import java.util.List;6import java.util.ArrayList;7public class 1 {8public static void main(String[] args) throws IOException {9PageSpec spec = PageSpec.load(new File("specFile.spec"));10List<ObjectSpec> objects = spec.getObjects();11for (ObjectSpec object : objects) {

Full Screen

Full Screen

getObjects

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.official;2import java.io.IOException;3import java.util.List;4import com.galenframework.specs.page.PageSection;5import com.galenframework.specs.page.PageSpec;6import com.galenframework.specs.page.PageSpecReader;7public class GalenGetObjects {8 public static void main(String[] args) throws IOException {9 String specPath = "src/test/resources/specs/galenGetObjects.spec";10 PageSpec pageSpec = PageSpecReader.read(specPath);11 List<PageSection> pageSectionList = pageSpec.getObjects();12 System.out.println(pageSectionList);13 }14}

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