Can't run Geb tests using HtmlUnitDriver under Maven - selenium-webdriver

I am running the example Google spec, i.e:
class GoogleHomePageSpec extends GebReportingSpec {
def "first result for wikipedia search should be wikipedia"() {
given:
to GoogleHomePage
expect:
at GoogleHomePage
when:
search.field.value("wikipedia")
then:
waitFor { at GoogleResultsPage }
and:
firstResultLink.text().startsWith "Wikipedia"
when:
firstResultLink.click()
then:
waitFor { at WikipediaPage }
}
}
with the following GebSpec:
reportsDir = "target/geb-reports"
/* webdriver.*.driver system properties are set in the POM */
driver = {
new HtmlUnitDriver();
}
and the following relevant pom.xml excerpt:
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>0.7-groovy-2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>0.9.2</version>
<scope>test</scope>
</dependency>
and it fails with the message if I run it from CLI or IDE:
First result for wikipedia search should be wikipedia(scratch.GoogleHomePageSpec) Time elapsed: 0.96 sec <<< ERROR!
geb.driver.DriverCreationException: failed to create driver from callback 'GebConfig$_run_closure1#20fcbdaf'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/set/ListOrderedSet
at com.gargoylesoftware.htmlunit.CookieManager.<init>(CookieManager.java:59)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:131)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:289)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:144)
at GebConfig.run_closure1(GebConfig.groovy:10)
at GebConfig.run_closure1(GebConfig.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
I've checked and the commons-collection jar is present and contains the 'missing' class.
I don't get this error at all using ChromeDriver, FirefoxDriver and InternetExplorerDriver.
Unfortunately for environmental reasons I have to use HtmlUnitDriver so I'm really scratching my head about this one.
Would be grateful for any suggestions.
EDIT 1:
Have managed to run a portion of this test successfully on my Mac, the remainder times out.
But am not seeing the same errors as above (which were observed on Windows).

Resolved this problem by rebuilding the maven_repo i.e. moving the old one out of the way so maven is forced to rebuild it on the next run of the tests.
The exception no longer appears.

Related

java.lang.NoClassDefFoundError: feign/Request$Body in feign while adding support for multipart/form-data

I am trying to proxy multipart request via feign.
#PostMapping(value = "{pathUri1}/{pathUri2}",consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<BaseResponse<?>> uploadFileCall(#PathVariable(value = "pathUri1") String pathUri1, #PathVariable(value = "pathUri2") String pathUri2, #RequestPart(name = "file") MultipartFile file, #RequestParam Map<Object,Object> requestParam, #RequestHeader HttpHeaders httpHeaders);
this is service call.
#Configuration
class MultipartSupportConfig {
#Autowired
ObjectFactory<HttpMessageConverters> messageConverters;
#Bean
#Primary
#Scope("prototype")
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
added encoder config for multipart/form-data .
I have followed this
https://github.com/OpenFeign/feign-form
But I am getting hystrixRunTimeException which is caused because of
java.lang.NoClassDefFoundError: feign/Request$Body error.
Use feign-form-spring 3.4.1 version.
Gradle
compile(group: 'io.github.openfeign.form', name: 'feign-form-spring', version: '3.4.1')
Maven
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.4.1</version>
</dependency>
Check requirements https://github.com/OpenFeign/feign-form#requirements
According to the open-feign's github document, Please Note the feign-form's versions:
all feign-form releases before 3.5.0 works with OpenFeign 9.* versions;
starting from feign-form's version 3.5.0, the module works with OpenFeign 10.1.0 versions and greater.
The following config works for me:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>${feign.version}</version>
</dependency>
Where:
<feign.version>11.0</feign.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>

GcsServiceFactory.createGcsService leads to 500 server error

I am working on an app which uses GAE and GCS serverside. Among other things I can upload pictures and store their publicUrl in a google mysql database. Today I tried to use .secureUrl(true) when getting those publicUrls and since then I get a 500 server error when sending post requests.
I can break it down to the following code snippet:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
// create Writer for response
PrintWriter out = response.getWriter();
response.setContentType("application/json");
// create Database Connection url with name database, username and password
String mysqlUrl = System.getProperty("cloudsql");
// get 'operation' parameter to determine further action
String operation = request.getParameter("operation");
if (operation == null){ operation = "getFav"; }
GcsService gcsService = GcsServiceFactory.createGcsService();
When I dont comment out the last line where gcsService is set, every post request sent from my phone is answered with a 500 server error. If I make the line a comment, everything (except for the parts where gcs is used) works perfectly. Checking out the Google console, I get the following message:
java.lang.NoClassDefFoundError: com/google/appengine/api/utils/SystemProperty
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService (GcsServiceFactory.java:57)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService (GcsServiceFactory.java:44)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService (GcsServiceFactory.java:40)
at net.xyz.yzxI.HelloAppEngine.<init> (HelloAppEngine.java:69)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:423)
at java.lang.Class.newInstance (Class.java:443)
at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance (ContextHandler.java:2481)
at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet (ServletContextHandler.java:1327)
at org.eclipse.jetty.servlet.ServletHolder.newInstance (ServletHolder.java:1285)
at org.eclipse.jetty.servlet.ServletHolder.initServlet (ServletHolder.java:615)
at org.eclipse.jetty.servlet.ServletHolder.getServlet (ServletHolder.java:499)
at org.eclipse.jetty.servlet.ServletHolder.ensureInstance (ServletHolder.java:791)
at org.eclipse.jetty.servlet.ServletHolder.prepare (ServletHolder.java:776)
at org.eclipse.jetty.servlet.ServletHandler.doHandle (ServletHandler.java:579)
at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle (SecurityHandler.java:524)
at org.eclipse.jetty.server.session.SessionHandler.doHandle (SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle (ContextHandler.java:1180)
at org.eclipse.jetty.servlet.ServletHandler.doScope (ServletHandler.java:512)
at org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope (ContextHandler.java:1112)
at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.handle (AppVersionHandlerMap.java:297)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle (Server.java:534)
at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:320)
at com.google.apphosting.runtime.jetty9.RpcConnection.handle (RpcConnection.java:202)
at com.google.apphosting.runtime.jetty9.RpcConnector.serviceRequest (RpcConnector.java:81)
at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest (JettyServletEngineAdapter.java:108)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest (JavaRuntime.java:680)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest (JavaRuntime.java:642)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run (JavaRuntime.java:612)
at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run (JavaRuntime.java:806)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run (ThreadGroupPool.java:274)
at java.lang.Thread.run (Thread.java:745)
It drives me crazy: Even if I dont use the gcs at all, just trying to set it up breaks the app. I have like no clue where to look at, so hopefully someone else has had similar experiences or knows what to check.
Thanks in advance
If you are using Maven to handle dependencies this error may be due to a "provided" in the com.google.appengine dependency. Remove that line in pom.xml so Maven will include app engine sdk in the compiled project.
Before:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.63</version>
<scope>provided</scope>
</dependency>
After:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.63</version>
</dependency>

Spring AOP No visible constructors in class

Error: java.lang.IllegalArgumentException: No visible constructors in class org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$DefaultObjectMapperCustomizer
Mostly, I used example given in link, and the following code can be found at github repository
Annotation:
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.TYPE)
public #interface NeedTestClass {
}
Aspect:
#After("#args(NeedTestClass)")
public void afterReturningAtArgs() {
log.info("aspect: after #args {}");
}
Service:
#Slf4j
#Component
public class BusinessService {
public void logicWithAnnotatedArgs1(Child c) {
log.info("service");
}
}
Pojo (top class, not sub class):
#NoArgsConstructor // tried with or without
#NeedTestClass
public class Child {}
Test:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration
#WebAppConfiguration
#SpringBootTest
public class AopTest {
#Autowired
private BusinessService myBusinessService;
#Test
public void testAtArgsPCD() {
myBusinessService.logicWithAnnotatedArgs1(new Child());
}
I attempted to examine aop and annotated class inheritance, but it seems the first step could not be ok. I have tried #annotation() and this() PCD both ok.
EDIT:
So far I am wondering maybe the error is related with the bean loading sequence.
Your GitHub project does not even compile. Have you even tested it? First by trial and error I had to add all of these dependencies:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.alibaba.druid</groupId>
<artifactId>druid-wrapper</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
Next, I noticed that the Maven build does not seem to start the local (127.0.0.1) database because Spring Boot says this at start-up:
(...)
2018-01-02 17:57:18.882 INFO 14480 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
2018-01-02 17:57:20.007 ERROR 14480 --- [tionPool-Create] com.alibaba.druid.pool.DruidDataSource : create connection error
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:590) ~[mysql-connector-java-6.0.6.jar:6.0.6]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:57) ~[mysql-connector-java-6.0.6.jar:6.0.6]
(...)
Would you mind refactoring your GitHub project into an MCVE first before I can check on your actual problem? This way the error is not reproducible.
But having said this, I did notice something in your POM and Java files: Maybe the problem is not where you think it is. I can see that you want to use Lombok in combination with Spring AOP. According to my answer here, there are compatibility problems between AspectJ and Lombok. Maybe they also affect Spring AOP. So can you temporarily test without #Slf4j and other Lombok stuff? As soon as you will have fixed your project I can also test by myself.
Update after GitHub repo project has been repaired:
Now I can build and run your program, thanks. It seems that the parameter is somehow passed through to internal Spring classes you do not wish to target. So just modify your pointcut like this:
#After("#args(com.example.demosm.my.aop.NeedTestClass) && within(com.example.demosm..*)")

How to use org.scalatest.Suite

I'm trying to use scalatest suite using intellij idea like this :
class SampleTest extends org.scalatest.Suite {
def myTest() {
assert(true)
}
}
(new SampleTest).execute()
I have added scalactic_2.11 and scalactic_2.11 to my pom file.The problem is that the SDK still cant resolve it.
Well it seems the problem is due to versioning. using the following version resolved the issue :
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest</artifactId>
<version>0.9.5</version>
</dependency>

Where did the execute call go in BigQuery Requests?

I am following the Code lab here https://developers.google.com/bigquery/articles/gettingstartedwithjava to make requests to big query. One of the code samples here says:
Datasets.List datasetRequest = bigquery.datasets().list(projectId);
DatasetList datasetList = datasetRequest.execute();
But I am getting a "The method execute() is undefined for the type Bigquery.Datasets.List" error.
Any idea whats going on?
I am on version google-api-services-bigquery-v2-rev42-1.12.0-beta if that matters.
You need to explicitly add this dependency to get it working. The dependency in the pom for google-api-services-bigquery seem to be wrong. Which causes this exception.
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.12.0-beta</version>
</dependency>

Resources