selenium 2.0 webdriver tests compilation errors - java

No matter which Selenium 2.xx version web-drivers I use, I get the same compilation errors
: error reading C:\Documents and
Settings\kondojis.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\2.0b3\selenium-firefox-driver-2.0b3.jar;
error in opening zip file
This is what I have in my POM file
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0rc2</version>
<type>pom</type> <i tried with and without type pom>
</dependency>
I am using jdk 1.6, Maven 3.0.1 M am using Maven compiler plugin 2.3.2 etc on Windows XP
package com.usps.mgo.icoa.UI;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.apache.log4j.Logger;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.util.List;
import java.util.Locale;
/**
* Created by IntelliJ IDEA.
* User: kondojis
* Date: 2/8/11
* Time: 5:02 PM
* To change this template use File | Settings | File Templates.
*/
public class SimulatorTests {
private static final Logger logger = Logger.getLogger(SimulatorTests.class);
private static WebDriver driver;
private ReloadableResourceBundleMessageSource messageSource;
private static ClassPathXmlApplicationContext springCtx;
/**
* Properties for Simulator tests
*/
#Before
public void setUp() {
// Bootstrap Spring Framework.
springCtx = new ClassPathXmlApplicationContext(
new String[]{"test-config.xml"});
//Make Sure that test_global.properties file is always in sync with the global.properties file from production.
messageSource = springCtx.getBean("messageSource", ReloadableResourceBundleMessageSource.class);
driver = new FirefoxDriver();
}

Error in opening zip file sounds like a corrupted jar in your local repo. Try deleting the "C:\Documents and Settings\kondojis.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\" directory and making maven re-download it.
edit: Noticed your selenium dependency and error output have different versions, I declare a manual dependency like
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.0rc2</version>
<scope>test</scope>
</dependency>

Related

How can I call test method from jar file to run mock script

I have a deployment of a spring-based corporate project, I did everything and now I just need to run the data seeding script, but I don’t understand how to do it at all
The instructions say:
Run test build io.groobit.utils.mock_data_init.ScenarioTest#scenario1
run mock-init.jar in folder (not used run test in "Itelij idea" To avoid such an error .. see image)
Run build mock-init.jar "java -jar mock-init.jar"
I have run tests many times in intelij idea by clicking the desired method in the test folder, but how to proceed here in the command to call it?
package io.groobit.utils.mock_data_init;
import io.groobit.api.client_api.dto.BusinessClientBasicInfo;
import io.groobit.api.client_api.dto.Payment;
import io.groobit.utils.mock_data_init.*;
import io.groobit.utils.mock_data_init.utils.AuthUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import java.math.BigDecimal;
import java.time.Instant;
#Slf4j
#Disabled
#SpringBootTest
#DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
#TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ScenarioTest {
#Test
public void scenario1() throws Exception {
//call this it
}
}
Path test: src/test/java/io/company/utils/mock_data_init/ScenarioTest.java
Any idea?

Glassfish & MongoDB connection error : NoClassDefFoundError

I am running a Glassfish server that is trying to connect to MongoDB. At first I created seperate projects for the server and MongoDB. So now I am trying to merge those projects but it appears anything I try to do it results in a faliure.
The current error I am getting is:
2018-07-05T19:54:36.249+0200|Severe: java.lang.NoClassDefFoundError: org/bson/conversions/Bson
I am well aware that the error happens in runtime and that the possible cause is my classpath.
Currently I copied all of my code from one project to another, added Maven dependencies and the following happens:
if I create a separate .java file for my MongoDB and run it in the same folder that the Glassfish server is, it works perfectly fine.
if I run the server and try to call methods from the other class (a little bit modified) the upper error appears
Simplified code example withouth error:
import org.bson.Document;
import org.bson.conversions.Bson;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoIterable;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
public class MyClass{
public static void main(String[]args){
String ip = "127.0.0.1";
int port = 27017;
MongoClient mongoClient = new MongoClient(ip,port);
/* Remaining code */
}
}
With error:
import org.bson.Document;
import org.bson.conversions.Bson;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoIterable;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
public class MyClass{
private MongoClient mongoClient;
public MyClass(String ip, int port){
mongoClient = new MongoClient(ip, port); // Error called here
}
/* Remaining code */
}
Called from the server.java file:
MyClass mc = new MyClass("127.0.0.1",27017);
I also tried to download all of the bson jar files separately and add them to the project but that had no effect...
The working solution for me was to delete the whole project and create it once more. Apparently there was a problem with Eclipse or I made a mistake before and forgot about it.

Cannot resolve symbol 'Before' - Intellij jUnit

I am new to Intellij IDEA. I'm trying to use jUnit annotations #Before and #After for my selenium tests. Even though I'm importing jUnit in my class, I 'm not able to use the annotations. Any help?
package Config;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
public class browserConfig {
public static WebDriver driver = null;
public static Properties config = new Properties();
public static FileInputStream fis;
#Before
public void initBrowser(){
if (driver ==null){
try{
fis = new FileInputStream(System.getProperty("user.dir") + "//src//main//java//Config//config.properties");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Your test should be in the test folder, otherwise idea will ignore the test annotations.
Make sure the class is placed in the src/test/ folder.
Also check in Project Settings -> Modules that your tests folder is present in the structure and has green color (marked as Tests). If it is missing - add it to the modules and mark as Tests.
If you are using gradle to build in Intellij, try adding this to build.gradle.
testCompile('org.springframework.boot:spring-boot-starter-test')
If you aren't using gradle do something similar with whatever controls your dependencies.

Do I need to install Apache Spark and/or Scala to run a jUnit?

I am very new to Apache Spark framework, trying to setup my first jUnit like follows:
package com.sample.ccspark;
import com.holdenkarau.spark.testing.SharedJavaSparkContext;
import org.apache.spark.api.java.JavaRDD;
import org.junit.Test;
import java.util.List;
import static java.util.Arrays.asList;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class SimpleTest extends SharedJavaSparkContext {
#Test
public void initializationWorks() {
List<Integer> list = asList(1, 2, 3, 4);
JavaRDD<Integer> rdd = jsc().parallelize(list);
assertThat(rdd.count(), is(list.size()));
}
}
with the following dependencies in the pom.xml
<dependency>
<groupId>com.holdenkarau</groupId>
<artifactId>spark-testing-base_2.11</artifactId>
<version>2.2.0_0.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>2.2.0</version>
</dependency>
everything happily compiles, however when running I am getting the following exception:
Exception in thread "dispatcher-event-loop-6" java.lang.NoClassDefFoundError:
scala/runtime/AbstractPartialFunction$mcVL$sp
I do not have Spark or Scala installed locally yet, was under impression that testing framework should take care of all dependencies. Is there something I am missing here?
In the artifacts names
<artifactId>spark-testing-base_2.11</artifactId>
<artifactId>spark-core_2.10</artifactId>
the last number is the version of Scala. I guess you should select only one for both cases.

Powermock with Mockito

Im trying to use PowerMock with Mockito, but PowerMock.replayAll(); and PowerMock.verifyAll(); is not found in my Eclipse environment. Used this download link:
http://code.google.com/p/powermock/downloads/detail?name=powermock-mockito-junit-1.5.zip&can=2&q=
And downloaded EasyMock here:
http://sourceforge.net/projects/easymock/files/EasyMock/3.1/easymock-3.1.zip/download
Added all the jars to my libs directory (removed it from my build path). Anyone? Thanks!
Source code Android project and test project:
https://github.com/powder366/test
https://github.com/powder366/testtest
example.
package com.test
import static org.junit.Assert.*;
import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.PowerMockUtils;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(Greeter.class)
public class MockStaticExampleTest {
#Test
public void mockStaticExample() throws Exception {
String expectedGreeting = "greeting";
String nameToGreet = "name";
PowerMockito.mockStatic(Greeter.class);
EasyMock.expect(Greeter.getGreeting(nameToGreet)).andReturn(expectedGreeting);
PowerMock.replayAll();
String actualGreeting = Greeter.getGreeting(nameToGreet);
PowerMock.verifyAll();
assertEquals("Expected and actual greeting did not match", expectedGreeting, actualGreeting);
}
}
You have not to add your jars to the Eclipse build path, but you have to place the jars inside the libs folder. ADT will do what takes to import it.
I finally downloaded:
http://code.google.com/p/powermock/downloads/detail?name=powermock-easymock-1.5-full.jar&can=2&q=
and it worked with PowerMock.replayAll(); and PowerMock.verifyAll();

Categories