Skip to content

Conversation

colinbut
Copy link
Contributor

I created a sample application sub-module which just contains the App.java driver class that runs the sample web app (which is just a simple web site really for demonstration purposes). App.java does nothing special apart from just tries to open up the web app in default web browser.Another sub-module test-automation is as the name suggest a test module which contains the page objects and the test classes that uses these page objects.

Normally, an automation framework/tool like Selenium will be used for test automation utilising the Page Objects but for the purpose of demonstrating this pattern implementation i've used a simple library HtmlUnit instead as Selenium is very heavyweight and i wanted the pattern example to focus on how the pattern is normally implemented.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 89.219% when pulling 0282d66 on colinbut:master into f57b94a on iluwatar:master.

@iluwatar
Copy link
Owner

iluwatar commented Jun 25, 2016

Review comments:

  • Page-object contains two submodules - is this necessary or could we implement the sample application in the src/main/java and the test code in src/test/java?
  • In general you should use final keyword for members when they are initialized in constructor

====

username - admin
password - password No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intention was for informational purpose only.
i'll remove this file

@iluwatar
Copy link
Owner

@colinbut you have my review remarks. Please comment once you've implemented the changes and I'll take another look.

@colinbut
Copy link
Contributor Author

Page-object contains two submodules - is this necessary or could we implement the sample application in the src/main/java and the test code in src/test/java?

on terms of whether it is necessary you could argue it both ways. The tests are not unit tests so my initial implementation was to put it in a separate module at least. Since, normally in real-world these are full end to end integration tests which normally resides in a separate project/module etc.

But on reflection maybe it is more sensible to put into one module since those are the only tests for this example.

I can certainly combine them together as you suggested.

@iluwatar would you like me to do that?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 88.474% when pulling 35c0942 on colinbut:master into e7bd3ca on iluwatar:master.

@iluwatar
Copy link
Owner

@iluwatar would you like me to do that?

Yes, please. I think it is better that way.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 88.985% when pulling ef2ada4 on colinbut:master into 5c26f46 on iluwatar:master.

@colinbut
Copy link
Contributor Author

colinbut commented Jul 6, 2016

@iluwatar done changes from your initial feedback

@iluwatar
Copy link
Owner

iluwatar commented Jul 9, 2016

I have problems running the example. In Eclipse when I run the App.java I get Exception in thread "main" java.lang.IllegalArgumentException: The file: /home/ilkka/java-design-patterns/page-object/page-object/src/main/resources/sample-ui/login.html doesn't exist. The same happens on the command line when I do mvn exec:java -Dexec.mainClass="com.iluwatar.pageobject.App" in the page-object folder.

In App.java should it be File applicationFile = new File(currentWorkingDir + "/src/main/resources/sample-ui/login.html");?

@iluwatar
Copy link
Owner

iluwatar commented Jul 9, 2016

The license headers are missing from two files:

[INFO] Updating license header in: /home/ilkka/java-design-patterns/page-object/src/main/resources/sample-ui/css/style.css
[INFO] Updating license header in: /home/ilkka/java-design-patterns/page-object/src/main/resources/sample-ui/css/album-list.css

@iluwatar
Copy link
Owner

iluwatar commented Jul 9, 2016

When running tests I get this nasty looking exception although the passes. Do you know what might cause this?

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.iluwatar.pageobject.AlbumListPageTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.339 sec - in com.iluwatar.pageobject.AlbumListPageTest
Running com.iluwatar.pageobject.LoginPageTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec - in com.iluwatar.pageobject.LoginPageTest
Running com.iluwatar.pageobject.AlbumPageTest
java.lang.instrument.IllegalClassFormatException: Error while instrumenting class com/steadystate/css/parser/SACParserCSS3TokenManager.
    at org.jacoco.agent.rt.internal_b0d6a23.CoverageTransformer.transform(CoverageTransformer.java:95)
    at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
    at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.steadystate.css.parser.SACParserCSS3.<init>(SACParserCSS3.java:3272)
    at com.steadystate.css.parser.SACParserCSS3.<init>(SACParserCSS3.java:33)
    at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet.parseCSS(CSSStyleSheet.java:929)
    at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet.<init>(CSSStyleSheet.java:199)
    at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet.loadStylesheet(CSSStyleSheet.java:367)
    at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement.getSheet(HTMLLinkElement.java:145)
    at com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList.item(StyleSheetList.java:182)
    at com.gargoylesoftware.htmlunit.javascript.host.Window.getComputedStyle(Window.java:1590)
    at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendNode(HtmlSerializer.java:276)
    at com.gargoylesoftware.htmlunit.html.HtmlSerializer.asText(HtmlSerializer.java:62)
    at com.gargoylesoftware.htmlunit.html.HtmlOption.getText(HtmlOption.java:395)
    at com.gargoylesoftware.htmlunit.html.HtmlOption.getValueAttribute(HtmlOption.java:226)
    at com.gargoylesoftware.htmlunit.html.HtmlSelect.getOptionByValue(HtmlSelect.java:471)
    at com.iluwatar.pageobject.pages.AlbumPage.changeAlbumYear(AlbumPage.java:112)
    at com.iluwatar.pageobject.AlbumPageTest.testSaveAlbum(AlbumPageTest.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:108)
    at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:78)
    at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:54)
    at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:144)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.io.IOException: Error while instrumenting class com/steadystate/css/parser/SACParserCSS3TokenManager.
    at org.jacoco.agent.rt.internal_b0d6a23.core.instr.Instrumenter.instrumentError(Instrumenter.java:152)
    at org.jacoco.agent.rt.internal_b0d6a23.core.instr.Instrumenter.instrument(Instrumenter.java:103)
    at org.jacoco.agent.rt.internal_b0d6a23.CoverageTransformer.transform(CoverageTransformer.java:93)
    ... 64 more
Caused by: java.lang.RuntimeException: Method code too large!
    at org.jacoco.agent.rt.internal_b0d6a23.asm.MethodWriter.getSize(MethodWriter.java:2036)
    at org.jacoco.agent.rt.internal_b0d6a23.asm.ClassWriter.toByteArray(ClassWriter.java:827)
    at org.jacoco.agent.rt.internal_b0d6a23.core.instr.Instrumenter.instrument(Instrumenter.java:84)
    at org.jacoco.agent.rt.internal_b0d6a23.core.instr.Instrumenter.instrument(Instrumenter.java:101)
    ... 65 more
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.25 sec - in com.iluwatar.pageobject.AlbumPageTest

@iluwatar
Copy link
Owner

iluwatar commented Jul 9, 2016

Those are my comments for now. @colinbut looking forward to your response.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 89.205% when pulling f182e87 on colinbut:master into 5c26f46 on iluwatar:master.

@colinbut
Copy link
Contributor Author

colinbut commented Jul 11, 2016

I use Intellij IDEA for development. Intellij and Eclipse handles multi-module project very differently from each other.

I've reworked that area. File applicationFile = new File(currentWorkingDir + "/src/main/resources/sample-ui/login.html"); would not be a good fix in my opinion. Since the sample app lives under resources i've let java to load it from interpretation now.

@colinbut
Copy link
Contributor Author

The license headers are missing from two files:

[INFO] Updating license header in: /home/ilkka/java-design-patterns/page-object/src/main/resources/sample-ui/css/style.css
[INFO] Updating license header in: /home/ilkka/java-design-patterns/page-object/src/main/resources/sample-ui/css/album-list.css

have now added the license headers to these 2 files

@colinbut
Copy link
Contributor Author

Ah, this is my oversight. The test actually passes despite the exception and the build passes.

This is actually caused by JaCoCo code coverage trying to instrument the underlying library class in the HtmlUnit library i'm using. This is causing a problem because that class in culprit has a massive over 4000+ lines of code in a single method.

I've added an exclusion to the list of exclusions already there since i don't believe this should be part of the code coverage

@colinbut
Copy link
Contributor Author

@iluwatar my responses are in comments above.

@iluwatar
Copy link
Owner

Thanks for the latest updates. Everything seems to work as expected. Good job @colinbut 👍

@iluwatar iluwatar merged commit b46d2de into iluwatar:master Jul 12, 2016
@iluwatar
Copy link
Owner

@all-contributors please add @colinbut for code

@allcontributors
Copy link
Contributor

@iluwatar

I've put up a pull request to add @colinbut! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants