Failed to instantiate class in selenium-cucumber framework - selenium

I am using cucumber 3.0.2.My testrunner code is given below.
package futurerx_testrunner_pkg;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(features="features/login.feature",glue= {"stepdefinition"})
public class testrunner {
}
I have created 2 packages in src(futurerx_testrunner_pkg and stepdefinition).I have testrunner.java in futurerx_testrunner_pkg package and Basedefinition.java in stepdefinition package.
But when i am running the code,it gives an error "Failed to instantiate class stepdefinition.Basedefinition at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:47) at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:33) at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)".
I am new to this cucumber-selenium framework and not understanding where i am going wrong.Thanks in Advance.

Related

MobileElement library cannot be found in java-client-8.2.1-all.jar

How can I add MobileElement libary? I am using java-client-8.2.1-all.jar and I have imported io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
I also added the dependency in app > build.gradle
implementation files('libs/java-client-8.2.1-all.jar')
Any idea?
Thanks

Getting org.junit.runner.RunWith is not an annotation type with Cucumber

I'm trying to set-up a Selenium + Cucumber project in Java (I'm a beginner with Java) in Intellij. This is my class that uses the Cucumber JUnit runner:
package runtest;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions (
features = "C:\\Users\\my-feature.feature",
)
public class RunTest {
}
I'm getting these errors:
Error:(8, 1) java: annotation #org.junit.runner.RunWith is missing default values for elements annotationType,<init>
Error:(8, 2) java: org.junit.runner.RunWith is not an annotation type
I don't know how to resolve this or what is happening. Please help.
I had multiple RunWith classes in my project path. After pruning the project tree, it works as expected.
You don't have to provide the absolute path of the feature file if you opt to place it within your project space. The name of the feature file folder would be enough.
As an example, if you are having the following structure:
Package: Q43966680
Class: Runner
Feature File Folder: q43966680
Snapshot:
As per your usecase within #CucumberOptions you just need to mention:
#RunWith(Cucumber.class)
#Cucumber.Options (features="q43966680")
public class RunTest {
}

Unable to resolve class org.gradle.util.TestUtil in Gradle

This error means that class TestUtil is not on the classpath and the compiler can not find it. I came across such error hundred times before and there was missing Jar or wrong written class names, but now I just don't know what is wrong.
In my buildSrc dir I have custom Task and I made test for it:
package com.example.core.tasks;
import spock.lang.Specification
import org.gradle.api.Project
import org.gradle.util.TestUtil
public class GetInfoTaskTest extends Specification {
def "check files"(){
given:
def project = TestUtil.createRootProject()
when:
GetInfoTask getInfo = project.tasks.create("getInfo", GetInfoTask)
then:
getInfo instanceof GetInfoTask.class
}
}
In the build script in the buildSrc dir:
dependencies {
compile localGroovy()
testCompile 'org.spockframework:spock-core:0.7-groovy-1.8'
testCompile gradleApi()
}
Error:
GetInfoTaskTest.groovy: 4: unable to resolve class org.gradle.util.TestUtil
# line 3, column 1.
import org.gradle.util.TestUtil
^
I checked that this TestUtil is not internal. I still don't know why gradle can not find it.
TestUtil is an internal class. You can't use it in your own code.

Grails (JUnit) test suite

Do JUnit test suites work in Grails?
I am writing a Groovy/Grails(2.1.2) project using IntelliJ.
Is it possible to run Spock tests as a JUnit test suite? I have tried:
package com.foo
import com.foo.functional.SampleFunctionalSpec
import org.junit.experimental.categories.Categories
import org.junit.runner.RunWith
import org.junit.runners.Suite
#RunWith(Categories.class)
#Categories.IncludeCategory(Category1.class)
#Suite.SuiteClasses( {SampleFunctionalSpec.class} )
class SampleTestSuite {
}
and
package com.foo.functional
import com.foo.*
import org.junit.experimental.categories.Category;
#Category(Category1.class)
class SampleFunctionalSpec extends BloomGebSpecCase {
def "Sample test 1 with Category1"() {
given:
when:
println "when"
then:
println "Sample test 1 with Category1"
}
}
and
package com.foo
interface Category1 { }
and I get "Unable to attach test reporter to test framework..." when I run grails test-app functional SampleTestSuite from within IntelliJ.
EDIT: Also, just running a test suite with no categories gives same "Unattached" problem:
#RunWith(Suite.class)
#Suite.SuiteClasses( SampleFunctionalSpec.class )
class SampleTestSuite { }

Jar files required to access Selenium class functions

Currently I have included the following JAR files to playback selenium recordings using JAVA.
junit-4.10.jar
selenium-java-2.24.1.jar
selenium-server-standalone-2.24.1.jar
Also I have imported these packages
import com.thoughtworks.selenium.Selenium;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
But with just these, I am not able to access selenium class functions like getAlert() or getConfirmation().
So are there any library files or JAR files that I have missed out on?
You can download the Java Client driver package 2.25.0 from the Selenium HQ site and then add all the jars in your project's referenced libraries.
You didn't imported the DefaultSelenium class which is in com.thoughtworks.selenium package so add this line to your code and it will work.
import com.thoughtworks.selenium.DefaultSelenium;