Cannot resolve method 'getLifecycle' in 'Allure' - java

I have project in java and i am using Allure for generating a test report.
I found this question and I need to rename my test using the below code:
AllureLifecycle lifecycle = Allure.getLifecycle();
//change test name to "CHANGED_NAME"
lifecycle.updateTestCase(testResult -> testResult.setName("CHANGED_NAME"));
I have imported the AllureLifecycle from below:
import io.qameta.allure.AllureLifecycle;
and using the below dependency:
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-java-commons</artifactId>
<version>2.13.3</version>
</dependency>
But, in the line Allure.getLifecycle() it is complaining with Cannot resolve method 'getLifecycle' in 'Allure'.
How can fix the error?

You need to add import of io.qameta.allure.Allure class

Related

Sample routine uisng JAVA APIs for T24

Can I have a sample routine (that has been tested) on latest T24/Transact release using Temenos Java APIs?
As per Temenos, Infobasic routines cannot be used anymore if EXTENSIBLE.CUSTOMISATION flag is set to Y in SPF.
Here is an actual, working sample that works in R20 - it is a sample of ENQUIRY build routine:
package com.bank;
import java.util.List;
import com.temenos.api.TStructure;
import com.temenos.t24.api.complex.eb.enquiryhook.FilterCriteria;
import com.temenos.t24.api.complex.eb.enquiryhook.EnquiryContext;
import com.temenos.t24.api.hook.system.Enquiry;
public class EnqBuildRoutineTest extends Enquiry {
#Override
public List<FilterCriteria> setFilterCriteria(List<FilterCriteria> filterCriteria, EnquiryContext enquiryContext) {
FilterCriteria criteria = new FilterCriteria();
criteria.setFieldname("SECTOR.CODE");
criteria.setOperand("LK");
criteria.setValue("2...");
filterCriteria.add(criteria);
return filterCriteria;
}
}
In case you are using maven, you can use these dependencies in pom.xml:
<dependency>
<groupId>com.temenos</groupId>
<artifactId>api</artifactId>
<scope>system</scope>
<systemPath>c:/Temenos/R20_MB/TAFJ/lib/TAFJClient.jar</systemPath>
<version>1</version>
</dependency>
<dependency>
<groupId>com.temenos</groupId>
<artifactId>EnquiryHook</artifactId>
<scope>system</scope>
<systemPath>c:/Temenos/R20_MB/bnk/t24lib/EB_EnquiryHook.jar</systemPath>
<version>1</version>
</dependency>
Once you have packaged it inside JAR and placed in your Classpath, you need to create EB.API record with "Source Type = Method" and specify the overriden setFilterCriteria as the method inside EB.API record. You also need to specify Class name (EnqBuildRoutineTest in this case) and package name (com.bank).

Cucumber on IntelliJ: getting errors as soon as I set up new project

I've been stuck for hours and I'm a bit confused, as I've tried to follow quite a few tutorials to set up Cucumber (Java version) + Selenium using IntelliJ as an IDE but I always end up getting errors from the very beginning, so I'm guessing there either is something the tutorials don't mention or some misconfiguration on my IDE.
This is something of what I've tried:
First, created a Maven project in IntelliJ IDEA and added dependencies for cucumber, junit and selenium to my pom.xml:
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
Then I created some structure for my project:
a folder named "resources" within src/test.
a folder named "features" within src/test/resources.
a package named "step_definitions" within src/test/java.
a file called MyTest.feature in the src/test/resources/features folder
In my MyTest.feature I added a simple test like this:
Feature: Check addition in Google calculator
Scenario: Addition
Given I open google
When I enter "2+2" in search textbox
Then I should get the result as "4"
Then from my feature file I auto-generated step definitions by using the IDE functionality (alt+enter > create step definitions), and I got a new file: MyStepDefs.java which I placed in src/test/java/step_definitions (leaving it in just src/test/java makes no difference), with the following contents:
package step_definitions;
import cucumber.api.PendingException;
public class MyStepdefs {
public MyStepdefs() {
Given("^I open google$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});}
}
The thing is, this is already showing errors. The "Given" keyword is not recognized: Cannot resolve method 'Given(java.lang.String)'
And on "new PendingException()" I get: Incompatible types. Required: java.lang.Throwable. Found: cucumber.api.PendingException
This sounds fishy, as it's auto-generated code so I assume it should be error-free (but it's not).
So I tried replacing this auto-generated code with something I got from this tutorial but then I get a "not applicable to method" error on #Before, #After, #Given, #When, #Then keywords.
package step_definitions;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class googleCalcStepDefinition {
protected WebDriver driver;
#Before
public void setup() {
driver = new FirefoxDriver();
}
#Given("^I open google$")
public void I_open_google() {
//Set implicit wait of 10 seconds and launch google
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.google.co.in");
}
#When("^I enter \"([^\"]*)\" in search textbox$")
public void I_enter_in_search_textbox(String additionTerms) {
//Write term in google textbox
WebElement googleTextBox = driver.findElement(By.id("gbqfq"));
googleTextBox.sendKeys(additionTerms);
//Click on searchButton
WebElement searchButton = driver.findElement(By.id("gbqfb"));
searchButton.click();
}
#Then("^I should get result as \"([^\"]*)\"$")
public void I_should_get_correct_result(String expectedResult) {
//Get result from calculator
WebElement calculatorTextBox = driver.findElement(By.id("cwos"));
String result = calculatorTextBox.getText();
//Verify that result of 2+2 is 4
Assert.assertEquals(result, expectedResult);
driver.close();
}
#After
public void closeBrowser() {
driver.quit();
}
}
What am I missing? Is there any way I can set up a fresh new project that uses Cucumber (Java) + Selenium on the IntelliJ IDE? Or is it just not possible at all?
Thanks!
Apparently, the Java JDK 9 that I had recently downloaded was the culprit. I went back to square 1 and started the project with JDK 8 and everything works as expected now.

Eclipse:I cannot import javax.json (or javax.json.stream)

Trying to use GSON and JSON-api. No issues with importing GSON into my code.
Getting error ("cannot find symbol" message in Eclipse compiler) when importing JSON-api.
The end result is that I want to use "JsonParser" which according to an Oracle page (click here for link) is inside javax.json.
Here's a snippet of my java code:
package com.myorg.core.impl.view.tools;
import com.google.gson.Gson; //no error
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.json; // error
//also tried import javax.json.stream same results.
I have the following lines in my pom.xml
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.2</version>
</dependency>
<!-- I also tried version 1.0. same result -->
In both dependencies, I can see the jar files in my Eclipse .m2 repository
myuser#myusers-MacBook-Pro : repository
=> find ~/.m2 -iname "*gson*" -type f
/Users/myuser/.m2/repository/com/google/code/gson/gson/2.7/gson-2.7.jar
/Users/myuser/.m2/repository/com/google/code/gson/gson/2.7/gson-2.7.jar.lastUpdated
/Users/myuser/.m2/repository/com/google/code/gson/gson/2.7/gson-2.7.jar.sha1
/Users/myuser/.m2/repository/com/google/code/gson/gson/2.7/gson-2.7.pom
/Users/myuser/.m2/repository/com/google/code/gson/gson/2.7/gson-2.7.pom.lastUpdated
/Users/myuser/.m2/repository/com/google/code/gson/gson/2.7/gson-2.7.pom.sha1
/Users/myuser/.m2/repository/com/google/code/gson/gson-parent/2.7/gson-parent-2.7.pom
/Users/myuser/.m2/repository/com/google/code/gson/gson-parent/2.7/gson-parent-2.7.pom.lastUpdated
/Users/myuser/.m2/repository/com/google/code/gson/gson-parent/2.7/gson-parent-2.7.pom.sha1
11:54:03 Thu Nov 16
myuser#myusers-MacBook-Pro : repository
=> find ~/.m2 -iname "*json-api*" -type f
/Users/myuser/.m2/repository/javax/json/javax.json-api/1.1.2/javax.json-api-1.1.2.jar
/Users/myuser/.m2/repository/javax/json/javax.json-api/1.1.2/javax.json-api-1.1.2.jar.lastUpdated
/Users/myuser/.m2/repository/javax/json/javax.json-api/1.1.2/javax.json-api-1.1.2.jar.sha1
/Users/myuser/.m2/repository/javax/json/javax.json-api/1.1.2/javax.json-api-1.1.2.pom
/Users/myuser/.m2/repository/javax/json/javax.json-api/1.1.2/javax.json-api-1.1.2.pom.lastUpdated
/Users/myuser/.m2/repository/javax/json/javax.json-api/1.1.2/javax.json-api-1.1.2.pom.sha1
Firstly about your import
import javax.json; // error, sure it will be an error
Above should tell you something like
Only a type can be imported. javax.json resolves to a package
So import type or types with a wildcard:
import javax.json.*;
import javax.json.stream.*;
or just the JsonParser
import javax.json.stream.JsonParser;
The end result is that I want to use "JsonParser"
You have dependency for javax.json-api in your pom.
It is just an API having only
package javax.json.stream;
interface JsonParser { ...
On the other hand GSON does not implement that but has its own
package com.google.gson;
public final class JsonParser // not implementing above mentioned
I am not an expert with all the JSON libraries available but at a very quick glance could not find any JsonParser implementations strictly implementing that interface in that package.
Maybe you manage with com.google.gson.JsonParser only?

Truth.assertAbout and JavaSourceSubjectFactory.javaSource()

I'm writing an annotation processor and want to write some unit tests for it by using google-compile-testing and truth:
So I want to write a very simple unit test.
import static com.google.common.truth.Truth.assertAbout;
import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
#Test
public void componentOnConcreteClass() {
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.NotAClass",
"package test;",
"",
"import my.annotation.MyAnnotation;",
"",
"#MyAnnotation",
"interface NotAComponent {}");
assertAbout(javaSource()).that(componentFile)
.processedWith(new MyProcessor())
.failsToCompile()
.withErrorContaining("interface");
}
So basically I have copy an pasted a simple test from google's dagger2 repo and replaced the relevant data with my annotation processor.
I'm using maven, and I'm using the same dependencies as dagger2:
<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
<version>0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
But I can't compile the code. I guess there is an generics param problem, but can't figure out what the problem is.
Compilation failure:
[ERROR] ProcessorTest.java:[46,5] method assertAbout in class com.google.common.truth.Truth cannot be applied to given types;
[ERROR] required: com.google.common.truth.SubjectFactory<S,T>
[ERROR] found: com.google.testing.compile.JavaSourceSubjectFactory
[ERROR] reason: no instance(s) of type variable(s) S,T exist so that argument type com.google.testing.compile.JavaSourceSubjectFactory conforms to formal parameter type com.google.common.truth.SubjectFactory<S,T>
Any hint what I'm doing wrong? I can't find any difference to google dagger2 tests (which by the way compiles on my machine)
The artifact com.google.testing.compile:compile-testing:0.5 depends on org.truth0:truth:0.15 which is the old location of Truth. Try using version 0.6 of compile-testing instead.

IDEA, Hamcrest and static imports

My maven project includes
186 <dependency>
187 <groupId>org.hamcrest</groupId>
188 <artifactId>hamcrest-all</artifactId>
189 <version>1.3</version>
190 </dependency>
When i type assertThat ..
I'd like for IDEA to figure out that the following is needed
import static org.hamcrest.MatcherAssert.assertThat;
Instead i get this.
How can this corrected? How can i get IDEA to perform a static import?
Open the parentheses and you will get a prompt for statically importing the method. IntelliJ won't understand it's a method you're trying to reference until you add the parenthesis.
In other words, type assertThat( and then ALT-ENTER.

Categories