package runnerFile;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(
features= {"src/test/resources/features"},glue= {"stepDefination"},
dryRun=false,
monochrome=true,strict=true
)
public class TestRunner extends AbstractTestNGCucumberTests{
}
Related
I am new to selenium cucumber. I am getting an error on the feature file "no definitions found ..". But I have written the definitions. I also can execute the cucumber tests just fine.
Feature:
Feature: LOGIN_FEATURE
Scenario: login scenario
Given User is already on login page
When title is crom
Then user enters un and pw
Step definition:
package stepDefinition;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.Assert.*;
//import org.junit.Assert;
import static org.testng.Assert.assertTrue;
//import cucumber.api.java.en.Given;
public class loginStepDef {
WebDriver driver;
//#Then"^login should be unsuccessful$"
#Given ("^User is already on login page$")
public void User_already_on_login_page(){
System.out.println("givenM method started");
System.setProperty("webdriver.chrome.driver","C:\\src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://web.bettylist.com/user");
System.out.println("---Navigated to the URL.");
}
//#SuppressWarnings("deprecation")
#When("^title is crom$")
public void title_is_crom(){
System.out.println("whenM started.");
String title = driver.getTitle();
System.out.println("title" + title);
//Assert.assertEquals("Ff", title);
assertEquals("Log in | bettylist", title);
System.out.println("---validated the title before logging in.");
}
Runner:
package MyRunner;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
//import cucumber.junit.Cucumber;
//import cucumber.api.CucumberOptions;
//import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "workspace/Cucumber3/src/main/java/Features",
glue="stepDefinition"
//format = {"pretty", "html:target/Destination"}
//plugin = {"pretty","html:test-outout"},
//plugin = {"json:Folder_Name1/cucumber.json"},
//plugin = {"junit:Folder_Name/cucumber.xml"},
//dryRun = false
//monochrome = false,
//strict = false
)
public class TestRunner {
}
I am using ecliipse IDE. I also installed Natural plugin. How can I fix the no definitions found in the feature file?
Feature File:
Feature: Claims Regression suit scenarios using BDD
#Test
Scenario: Log in to AUT as ClaimAssistant with valid credential.
Given Browser is launched successfully
Step Definition File :
#Given("^Browser is launched successfully$")
public void Browser_is_launched_successfully() throws InterruptedException, IOException
{
System.setProperty("webdriver.chrome.driver", "U:\\Claims Jar\\ChromeDriver\\chromedriver_win32\\chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://www.google.com");
driver.manage().window().maximize();
}
Test Runner Class File :
package Runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features="Feature",
glue={"stepDefn"},
plugin = { "pretty", "html:target/cucumber-reports"},
tags="#CO_Login_Test_ClaimAssistant" ,
dryRun= true ,
monochrome = true
)public class TestRunner {}
mockito-1.10.19
powermock-mockito-1.7.1
powermock-1.7.4
junit 4.12
I have a class that has multiple constructors (java). Once constructor calls the other. I want to mock only 1 of the constructors (the one that is called from the other). I cannot change the code unfortunately - I am just testing it. Here is the class to be tested:
import java.io.File;
import java.sql.connection;
public class Foo {
public Foo (Connection connection){
this(connection, new File ());
}
public Foo (Connection connection, File file){
// do stuff
}
// other methods
}
Here is the test class I have written:
import java.io.File;
import java.sql.connection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.legacy.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(Foo.class)
#PowerMockIgnore("javax.management.*")
public class FooTest {
#Test
public void testFoo() throws Exception {
Connection mockConnection = Mockito.mock(Connection.class);
Foo fooObj = Mockito.mock(Foo.class);
PowerMockito.whenNew(Foo.class).withArguments(Matchers.notNull(), Matchers.notNull()).thenReturn(fooObj);
Foo newFooObj = new Foo (mockConnection);
assertNotNull ("newFooObj should not be null", newFooObj);
}
}
The problem is that Foo(Connection) is not being entered. Is there something I am missing?
I tried your code with the latest 1.7.x version of Powermock (1.7.4) and it works as you wanted it to. So you might just need to upgrade a few minor versions.
I executed this command to compile my program
java -Xms16m -Xmx64m -cp ".:boilerpipe-1.2.0.jar:lib/nekohtml-1.9.13.jar:lib/xerces-2.9.1.jar:lib/langdetect.jar:lib/jsonic-1.2.8.jar" ExampleProgram.java
It reports this error:
Error: Could not find or load main class ExampleProgram.java
Here is ExampleProgram.java:
import java.io.InputStream;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import org.xml.sax.InputSource;
import de.l3s.boilerpipe.document.TextDocument;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
import de.l3s.boilerpipe.sax.BoilerpipeSAXInput;
// Language detect librarys
import com.cybozu.labs.langdetect.*;
import net.arnx.jsonic.JSON;
import net.arnx.jsonic.JSONException;
import java.io.*;
import java.net.*;
import java.util.concurrent.Executors;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class ExampleProgram {
public static void main(String[] args) throws Exception {
EveryDetector evr = new EveryDetector();
InetSocketAddress addr = new InetSocketAddress("127.0.0.1",8080);
HttpServer server = HttpServer.create(addr, 0);
MyHandler hndl = new MyHandler();
hndl.setDetector(evr);
MyHandlerExtractContent hnd2 = new MyHandlerExtractContent();
hnd2.setDetector(evr);
MyHandlerDetectLanguage hnd3 = new MyHandlerDetectLanguage();
hnd3.setDetector(evr);
server.createContext("/",hndl);
server.createContext("/extractcontent",hnd2);
server.createContext("/detectlanguage",hnd3);
server.setExecutor(Executors.newCachedThreadPool());
server.start();
System.out.println("Server is listening on port 8080" );
}
}
Source: https://github.com/remdex/boilerpipe-and-language-detect-api-server
How can I solve my problem?
For me, in Windows environment this worked (My class location : C:/MyFolder/MyClass.java) :
cd C:/MyFolder/MyClass.java
Compiling:
C:/MyFolder/MyClass.java> javac MyClass.java
Executing:
C:/MyFolder/MyClass.java> java -classpath C:/external.jar;. MyClass
package org.openbravo.erpCommon.utility;
import java.sql.*;
import org.apache.log4j.Logger;
import javax.servlet.ServletException;
import org.openbravo.data.FieldProvider;
import org.openbravo.database.ConnectionProvider;
import org.openbravo.data.UtilSql;
import org.openbravo.service.db.QueryTimeOutUtil;
import org.openbravo.database.SessionInfo;
import java.util.*;
class MessageBDData implements FieldProvider {
static Logger log4j = Logger.getLogger(MessageBDData.class);
private String InitRecordNumber="0";
public String msgtype;
public String msgtip;
public String msgtext;
Above is a source code of class MessageBDData found in /opt/OpenbravoERP-3.0/openbravo-erp/build/javasqlc/src/org/openbravo/erpCommon/utility
Well, I need to find source code of Logger import org.apache.log4j.Logger;which is imported in above code.
you cannot directly the source code of import org.apache.log4j.Logger because it is coming from the log4j jar file
for more info on org.apache.log4j.Logger visit this manual.