Best Galen code snippet using com.galenframework.specs.page.ObjectSpecs.getObjectName
Source:PageSpecReaderTest.java
...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 }712 @Test(expectedExceptions = SyntaxException.class,...
Source:PageSectionProcessor.java
...109 private void processObjectLevelRule(ObjectSpecs objectSpecs, StructNode sourceNode) throws IOException {110 String ruleText = sourceNode.getName().substring(1).trim();111 Pair<PageRule, Map<String, String>> rule = findAndProcessRule(ruleText, sourceNode);112 try {113 pageSpecHandler.setGlobalVariable("objectName", objectSpecs.getObjectName(), sourceNode);114 List<StructNode> specNodes = rule.getKey().apply(pageSpecHandler, ruleText, objectSpecs.getObjectName(), rule.getValue(), sourceNode.getChildNodes());115 SpecGroup specGroup = new SpecGroup();116 specGroup.setName(ruleText);117 objectSpecs.addSpecGroup(specGroup);118 for (StructNode specNode : specNodes) {119 specGroup.addSpec(pageSpecHandler.getSpecReader().read(specNode.getName(), pageSpecHandler.getContextPath()));120 }121 } catch (Exception ex) {122 throw new SyntaxException(sourceNode, "Error processing rule: " + ruleText, ex);123 }124 }125 private boolean isRule(String nodeText) {126 return nodeText.startsWith("|");127 }128 private PageSection findSection(String sectionName) {129 if (parentSection != null) {130 return findSection(sectionName, parentSection.getSections());131 } else {132 return findSection(sectionName, pageSpecHandler.getPageSections());133 }134 }135 private PageSection findSection(String sectionName, List<PageSection> sections) {136 for (PageSection section : sections) {137 if (section.getName().equals(sectionName)) {138 return section;139 }140 }141 return null;142 }143 private void processObject(PageSection section, StructNode objectNode) throws IOException {144 String name = objectNode.getName();145 String objectExpression = name.substring(0, name.length() - 1).trim();146 List<String> objectNames = pageSpecHandler.findAllObjectsMatchingStrictStatements(objectExpression);147 for (String objectName : objectNames) {148 if (objectNode.getChildNodes() != null && objectNode.getChildNodes().size() > 0) {149 ObjectSpecs objectSpecs = findObjectSpecsInSection(section, objectName);150 if (objectSpecs == null) {151 objectSpecs = new ObjectSpecs(objectName);152 section.addObjects(objectSpecs);153 }154 for (StructNode specNode : objectNode.getChildNodes()) {155 if (isRule(specNode.getName())) {156 processObjectLevelRule(objectSpecs, specNode);157 } else {158 processSpec(objectSpecs, specNode);159 }160 }161 }162 }163 }164 private void processSpec(ObjectSpecs objectSpecs, StructNode specNode) {165 if (specNode.getChildNodes() != null && !specNode.getChildNodes().isEmpty()) {166 throw new SyntaxException(specNode, "Specs cannot have inner blocks");167 }168 String specText = specNode.getName();169 boolean onlyWarn = false;170 if (specText.startsWith("%")) {171 specText = specText.substring(1);172 onlyWarn = true;173 }174 String alias = null;175 StringCharReader reader = new StringCharReader(specText);176 if (reader.firstNonWhiteSpaceSymbol() == '"') {177 alias = Expectations.doubleQuotedText().read(reader);178 specText = reader.getTheRest();179 }180 Spec spec;181 try {182 spec = pageSpecHandler.getSpecReader().read(specText, pageSpecHandler.getContextPath());183 } catch (SyntaxException ex) {184 ex.setPlace(specNode.getPlace());185 throw ex;186 }187 spec.setOnlyWarn(onlyWarn);188 spec.setAlias(alias);189 if (specNode.getPlace() != null) {190 spec.setPlace(new Place(specNode.getPlace().getFilePath(), specNode.getPlace().getLineNumber()));191 }192 spec.setProperties(pageSpecHandler.getProperties());193 spec.setJsVariables(pageSpecHandler.getJsVariables());194 objectSpecs.getSpecs().add(spec);195 }196 private ObjectSpecs findObjectSpecsInSection(PageSection section, String objectName) {197 if (section.getObjects() != null) {198 for (ObjectSpecs objectSpecs : section.getObjects()) {199 if (objectSpecs.getObjectName().equals(objectName)) {200 return objectSpecs;201 }202 }203 }204 return null;205 }206 private boolean isObject(String childPlace) {207 return childPlace.endsWith(":");208 }209 public static boolean isSectionDefinition(String name) {210 return name.startsWith("=") && name.endsWith("=");211 }212}...
getObjectName
Using AI Code Generation
1import com.galenframework.api.Galen;2import com.galenframework.reports.model.LayoutReport;3import com.galenframework.specs.page.ObjectSpecs;4import com.galenframework.specs.page.PageSpec;5import com.galenframework.specs.page.PageSection;6import com.galenframework.specs.page.PageSectionSpec;7import com.galenframework.specs.page.PageSections;8import com.galenframework.specs.page.SectionFilter;9import com.galenframework.specs.page.SectionFilterType;10import com.galenframework.specs.page.SectionFilters;11import com.galenframework.specs.page.SectionSpec;12import com.galenframework.specs.page.StringCondition;13import com.galenframework.specs.page.StringConditions;14import com.galenframework.specs.page.StringSpec;15import com.galenframework.specs.page.StringSpecs;16import java.io.IOException;17import java.util.Arrays;18public class getObjectName {19 public static void main(String[] args) throws IOException {20 PageSectionSpec sectionSpec = new PageSectionSpec("sectionName");21 StringSpecs stringSpecs = new StringSpecs();22 stringSpecs.add(new StringSpec("objectName", new StringConditions(Arrays.asList(new StringCondition("contains", "objectName")))));23 PageSection section = new PageSection(stringSpecs, new ObjectSpecs());24 PageSections sections = new PageSections(Arrays.asList(section));25 SectionSpec sectionSpec = new SectionSpec(sections, new SectionFilters(Arrays.asList(new SectionFilter(SectionFilterType.TAG_NAME, "div"))));26 PageSpec pageSpec = new PageSpec(Arrays.asList(sectionSpec));27 System.out.println("layoutReport: " + layoutReport);28 System.out.println("Object Name: " + sectionSpec.getSections().get(0).getObjects().getObjectName());29 }30}
getObjectName
Using AI Code Generation
1import com.galenframework.specs.page.ObjectSpecs;2import com.galenframework.specs.page.Locator;3public class 1 {4 public static void main(String[] args) {5 ObjectSpecs objectSpecs = new ObjectSpecs();6 Locator locator = new Locator("id", "id");7 String objectName = objectSpecs.getObjectName(locator);8 System.out.println(objectName);9 }10}11import com.galenframework.specs.page.ObjectSpecs;12import com.galenframework.specs.page.Locator;13public class 2 {14 public static void main(String[] args) {15 ObjectSpecs objectSpecs = new ObjectSpecs();16 Locator locator = new Locator("css", "css");17 String objectName = objectSpecs.getObjectName(locator);18 System.out.println(objectName);19 }20}21import com.galenframework.specs.page.ObjectSpecs;22import com.galenframework.specs.page.Locator;23public class 3 {24 public static void main(String[] args) {25 ObjectSpecs objectSpecs = new ObjectSpecs();26 Locator locator = new Locator("xpath", "xpath");27 String objectName = objectSpecs.getObjectName(locator);28 System.out.println(objectName);29 }30}31import com.galenframework.specs.page.ObjectSpecs;32import com.galenframework.specs.page.Locator;33public class 4 {34 public static void main(String[] args) {35 ObjectSpecs objectSpecs = new ObjectSpecs();36 Locator locator = new Locator("name", "name");37 String objectName = objectSpecs.getObjectName(locator);38 System.out.println(objectName);39 }40}41import com.galenframework.specs.page.ObjectSpecs;42import com.galenframework.specs.page.Locator;43public class 5 {
getObjectName
Using AI Code Generation
1import com.galenframework.specs.page.ObjectSpecs;2import com.galenframework.specs.page.PageSpec;3import com.galenframework.specs.page.PageSpecReader;4import com.galenframework.specs.page.SectionSpec;5import com.galenframework.specs.page.Locator;6import java.io.File;7import java.io.IOException;8import java.util.List;9import java.util.ArrayList;10import java.util.Map;11import java.util.HashMap;12import java.util.Set;13import java.util.HashSet;14import java.util.Iterator;15import org.testng.annotations.Test;16import com.galenframework.specs.page.PageSection;17import com.galenframework.specs.page.Locator;18import com.galenframework.specs.page.ObjectSpecs;19import com.galenframework.specs.page.PageSpec;20import com.galenframework.specs.page.PageSpecReader;21import java.io.IOException;22import java.util.ArrayList;23import java.util.HashMap;24import java.util.List;25import java.util.Map;26import java.util.Set;27import java.util.HashSet;28import java.util.Iterator;29import org.testng.annotations.Test;30import com.galenframework.specs.page.PageSection;31import com.galenframework.specs.page.Locator;32import com.galenframework.specs.page.ObjectSpecs;33import com.galenframework.specs.page.PageSpec;34import com.galenframework.specs.page.PageSpecReader;35import java.io.IOException;36import java.util.ArrayList;37import java.util.HashMap;38import java.util.List;39import java.util.Map;40import java.util.Set;41import java.util.HashSet;42import java.util.Iterator;43import org.testng.annotations.Test;44import com.galenframework.specs.page.PageSection;45import com.galenframework.specs.page.Locator;46import com.galenframework.specs.page.ObjectSpecs;47import com.galenframework.specs.page.PageSpec;48import com.galenframework.specs.page.PageSpecReader;49import java.io.IOException;50import java.util.ArrayList;51import java.util.HashMap;52import java.util.List;53import java.util.Map;54import java.util.Set;55import java.util.HashSet;56import java.util.Iterator;57import org.testng.annotations.Test;58import com.galenframework.specs.page.PageSection;59import com.galenframework.specs.page.Locator;60import com.galenframework.specs.page.ObjectSpecs;61import com.galenframework.specs.page.PageSpec;62import com.galenframework.specs.page.PageSpecReader;63import java.io.IOException;64import java.util.ArrayList;65import java.util.HashMap;66import java.util.List;67import java.util.Map
getObjectName
Using AI Code Generation
1import com.galenframework.specs.page.ObjectSpecs;2import com.galenframework.specs.page.PageSpec;3import com.galenframework.specs.page.Locator;4import java.util.List;5import java.util.ArrayList;6public class 1 {7 public static void main(String[] args) {8 ObjectSpecs objectSpecs = new ObjectSpecs("username", locator);9 System.out.println("Object Name: " + objectSpecs.getObjectName());10 }11}12Example 2: Using getObjectName() method to get the object name of a PageSpec object13import com.galenframework.specs.page.PageSpec;14import com.galenframework.specs.page.ObjectSpecs;15import com.galenframework.specs.page.Locator;16import java.util.List;17import java.util.ArrayList;18public class 2 {19 public static void main(String[] args) {20 ObjectSpecs objectSpecs = new ObjectSpecs("username", locator);21 List<ObjectSpecs> objectSpecsList = new ArrayList<ObjectSpecs>();22 objectSpecsList.add(objectSpecs);23 PageSpec pageSpec = new PageSpec(objectSpecsList);24 System.out.println("Object Name: " + pageSpec.getObjectName());25 }26}27Example 3: Using getObjectName() method to get the object name of a Locator object28import com.galenframework.specs.page.Locator;29import java.util.List;30import java.util.ArrayList;31public class 3 {32 public static void main(String[] args) {33 System.out.println("Object Name: " + locator.getObjectName());34 }35}36How to get the object name using getObjectName() method in Galen Framework?37How to get the object name using getObjectName() method in
getObjectName
Using AI Code Generation
1import com.galenframework.specs.page.ObjectSpecs;2import com.galenframework.specs.page.PageSpec;3import com.galenframework.specs.page.PageSpecReader;4import com.galenframework.specs.page.PageSpecReaderException;5import java.io.IOException;6import java.util.List;7public class 1 {8 public static void main(String[] args) throws IOException, PageSpecReaderException {9 PageSpecReader pageSpecReader = new PageSpecReader();10 PageSpec pageSpec = pageSpecReader.read("test.spec");11 List<ObjectSpecs> objectSpecsList = pageSpec.getObjectSpecs();12 for (ObjectSpecs objectSpecs : objectSpecsList) {13 System.out.println(objectSpecs.getObjectName());14 }15 }16}
getObjectName
Using AI Code Generation
1package com.galenframework.tests;2import com.galenframework.specs.page.ObjectSpecs;3public class GalenTest {4 public static void main(String[] args) {5 ObjectSpecs objSpec = new ObjectSpecs("object name", "object type");6 System.out.println(objSpec.getObjectName());7 }8}9package com.galenframework.tests;10import com.galenframework.specs.page.ObjectSpecs;11public class GalenTest {12 public static void main(String[] args) {13 ObjectSpecs objSpec = new ObjectSpecs("object name", "object type");14 System.out.println(objSpec.getObjectType());15 }16}17package com.galenframework.tests;18import com.galenframework.specs.Spec;19import com.galenframework.specs.page.ObjectSpecs;20import java.util.List;21public class GalenTest {22 public static void main(String[] args) {23 ObjectSpecs objSpec = new ObjectSpecs("object name", "object type");24 List<Spec> specs = objSpec.getSpecs();25 System.out.println(specs);26 }27}28package com.galenframework.tests;29import com.galenframework.specs.Spec;30import com.galenframework.specs.page.ObjectSpecs;31import java.util.ArrayList;32import java.util.List;33public class GalenTest {34 public static void main(String[] args) {35 ObjectSpecs objSpec = new ObjectSpecs("object name", "object type");36 List<Spec> specs = new ArrayList<Spec>();37 objSpec.setSpecs(specs);38 System.out.println(objSpec.getSpecs());39 }40}
getObjectName
Using AI Code Generation
1import com.galenframework.specs.page.ObjectSpecs;2import com.galenframework.specs.page.PageSpec;3import com.galenframework.specs.page.PageSpecReader;4import java.io.File;5import java.io.IOException;6import java.util.List;7public class 1 {8 public static void main(String[] args) throws IOException {9 PageSpec pageSpec = new PageSpecReader().read(new File("src/test/resources/specs/1.spec"));10 List<ObjectSpecs> objectSpecs = pageSpec.getObjectSpecs();11 for (ObjectSpecs objectSpec : objectSpecs) {12 System.out.println(objectSpec.getObjectName());13 }14 }15}16import com.galenframework.specs.page.ObjectSpecs;17import com.galenframework.specs.page.PageSpec;18import com.galenframework.specs.page.PageSpecReader;19import java.io.File;20import java.io.IOException;21import java.util.List;22public class 2 {23 public static void main(String[] args) throws IOException {24 PageSpec pageSpec = new PageSpecReader().read(new File("src/test/resources/specs/2.spec"));25 List<ObjectSpecs> objectSpecs = pageSpec.getObjectSpecs();26 for (ObjectSpecs objectSpec : objectSpecs) {27 System.out.println(objectSpec.getObjectName());28 }29 }30}31import com.galenframework.specs.page.ObjectSpecs;32import com.galenframework.specs.page.PageSpec;33import com.galenframework.specs.page.PageSpecReader;34import java.io.File;35import java.io.IOException;36import java.util.List;37public class 3 {38 public static void main(String[] args) throws IOException {39 PageSpec pageSpec = new PageSpecReader().read(new File("src/test/resources/specs/3.spec"));40 List<ObjectSpecs> objectSpecs = pageSpec.getObjectSpecs();41 for (ObjectSpecs objectSpec : objectSpecs) {42 System.out.println(objectSpec.getObjectName());43 }44 }45}
getObjectName
Using AI Code Generation
1package com.galenframework.specs.page;2import com.galenframework.specs.page.ObjectSpecs;3import com.galenframework.specs.page.ObjectSpecs;4import java.io.IOException;5import java.util.List;6import com.galenframework.specs.page.ObjectSpecs;7import java.util.ArrayList;8public class ObjectSpecs {9 public static void main(String[] args) throws IOException {10 ObjectSpecs objectSpecs = new ObjectSpecs();11 objectSpecs.getObjectName();12 }13 public void getObjectName() throws IOException {14 List<ObjectSpecs> objectSpecs = new ArrayList<ObjectSpecs>();15 ObjectSpecs objectSpecs1 = new ObjectSpecs("object1", "object1");16 ObjectSpecs objectSpecs2 = new ObjectSpecs("object2", "object2");17 ObjectSpecs objectSpecs3 = new ObjectSpecs("object3", "object3");18 objectSpecs.add(objectSpecs1);19 objectSpecs.add(objectSpecs2);20 objectSpecs.add(objectSpecs3);21 System.out.println("Object Name: " + objectSpecs.get(0).getName());22 }23}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!