when() not working in RestAssured using eclipse - eclipse

I am trying to run the following code with eclipse but it will give me the error: "The method when() is undefined for the type LastLabTest". I have imported the libraries but still it gives me that error. I am using eclipse with junit5.
import io.restassured.RestAssured;
import io.restassured.RestAssured.*;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.http.ContentType;
import io.restassured.matcher.RestAssuredMatchers.*;
import io.restassured.specification.RequestSpecification;
import org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.jupiter.api.Test;
class LastLabTest {
private RequestSpecification specification;
#BeforeClass
public void inItSpec() {
specification = new RequestSpecBuilder()
.setContentType(ContentType.JSON)
.setBaseUri("http://openlibrary.org/")
.addFilter(new RequestLoggingFilter())
.addFilter(new ResponseLoggingFilter())
.build();
}
#Test
public void getByName() {
when().get("https://swapi.co/api/people/1")
.then().log().all()
.statusCode(200)
.and()
.body("name", equals("Luke Skywalker"));
}
}

The keyword static is missing in the line
import io.restassured.RestAssured.*;
=>
import static io.restassured.RestAssured.*;

keyword static is missing in import io.restassured.RestAssured.;
correct : import static io.restassured.RestAssured.;

Related

No Results are shown on Eclipse Console when Karate Runner file is run as Junit Test but when file called in Command line using mvn test it works

I have the below Karate Runner File Content. When I executed this file on Eclipse, nothing is shownup on Console. Can Someone please help on this issue for me.
package com.accounting.apirunner;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import com.intuit.karate.junit5.Karate;
import cucumber.api.CucumberOptions;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
#CucumberOptions(features = { "classpath:Accountspayables", "classpath:Accountsreceivables", "classpath:company",
"classpath:generalLedger", "classpath: SpendManagement" }, tags = {
"~#ignore" }, plugin = { "pretty", "html:target/cucumber-html-reports" }, monochrome = true)
public class TestCaseRunner {
#BeforeClass
public static void beforeClass() throws Exception {
System.setProperty("karate.env", "SAT");
#Test
public void testParallel() {
Results results = Runner.path("classpath:Accountspayables", "classpath:Accountsreceivables",
"classpath:company", "classpath:generalLedger", "classpath: SpendManagement").tags("~#ignore")
.parallel(1);
generateReport(results.getReportDir());
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
String karateOutputPath = "target/surefire-reports";
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] { "json" }, true);
List<String> jsonPaths = new ArrayList(jsonFiles.size());
for (File file : jsonFiles) {
jsonPaths.add(file.getAbsolutePath());
}
Configuration config = new Configuration(new File("target"), "Accounting XMLGW Regression Test Suite");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
And no Executions shown up on Junit Explorer.

How to fix bellow mentioned code into eclipse to scroll mobile application?

I'm writing script to scroll mobile application up and down but Appium studio code with testng framework not working in Eclipse.
I'm new with this kind of script and testing please help to fix it.
I tried Appium studio code.
but it need to fix to run script.
//package <set your test package>;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.TouchAction;
import java.time.Duration;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.testng.annotations.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.logging.Level;
public class scrollandsave {
private String reportDirectory = "reports";
private String reportFormat = "xml";
private String testName = "scrollandsave";
protected AndroidDriver<AndroidElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
#BeforeMethod
public void setUp() throws MalformedURLException {
dc.setCapability("reportDirectory", reportDirectory);
dc.setCapability("reportFormat", reportFormat);
dc.setCapability("testName", testName);
dc.setCapability(MobileCapabilityType.UDID, "330033acecf394bd");
driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
driver.setLogLevel(Level.INFO);
}
#Test
public void testscrollandsave() {
new TouchAction(driver).press(480, 1348).waitAction(Duration.ofMillis(624)).moveTo(338, 312).release().perform();
new TouchAction(driver).press(591, 1376).waitAction(Duration.ofMillis(592)).moveTo(421, 138).release().perform();
driver.findElement(By.xpath("(//*[#id='listAllImgByCat']/*/*/*/*[#id='icPlayVideo'])[1]")).click();
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#text='EDIT']")));
driver.findElement(By.xpath("//*[#text='EDIT']")).click();
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#text='SAVE']")));
driver.findElement(By.xpath("//*[#text='SAVE']")).click();
driver.findElement(By.xpath("//*[#text='Export as GIF']")).click();
driver.findElement(By.xpath("//*[#id='btnHome']")).click();
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
I expect screen should scroll down whenever I execute above code.
you can try this code driver.executeScript("seetest:client.swipe(\"Down\", 1000, 500)");
. This code would swipe from Down, from the offset 1000 for 500ms.
Visit here for more information

Incompatible types. Required: GoogleApiClient Found: GoogleApiClient.Builder

I am trying to get the last known location using Google API client, but I have an issue with it being incompatible. Can anyone point out what did I miss?
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, OnConnectionFailedListener,
ConnectionCallbacks{
private GoogleMap mMap;
private GoogleApiClient mGoogleApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// getting incompatible issue in below line
mGoogleApiClient = new GoogleApiClient.Builder(this);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
Try this.
mGoogleApiClient = new GoogleApiClient.Builder(this).build();

View resolving does not always work

I have a Spring Boot (V 1.3.5) Web Application with JSPs packaged as jar. The views are located in src/main/resources/META-INF/resources/WEB-INF/views.
See http://hillert.blogspot.lu/2016/03/spring-boot-with-jsp-in-executable-jar.html on that subject.
This works well on my Fedora dev. workstation, and as well on a colleague's with Windows 7, both using Eclipse Mars.
But on another Windows 8 PC, the same sourcecode run in Eclipse or STS, produces a 404 because no view can be found, and this starts aching my head seriously.
I append my configuration class here, maybe someone has an idea what could go wrong here.
package our.base.package;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
#Configuration
#EnableScheduling
#EnableCaching
//#EnableWebMvc
#ComponentScan(basePackages = { "our.base.package" })
public class SpringConfigRootApplication extends WebMvcConfigurerAdapter {
#Bean
public LocaleResolver localeResolver() {
final CookieLocaleResolver slr = new CookieLocaleResolver();
slr.setCookieMaxAge(86400 * 365 * 5);
slr.setCookieName("lang");
slr.setDefaultLocale(Locale.GERMAN);
return slr;
}
#Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
final LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
lci.setIgnoreInvalidLocale(true);
return lci;
}
#Override
public void addInterceptors(final InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
#Override
public void addViewControllers(final ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
#Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setRequestContextAttribute("requestContext");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
#Bean(initMethod = "init", destroyMethod = "shutdown")
#Order(value = Ordered.LOWEST_PRECEDENCE)
public Application application() {
return new Application();
}
}

AEM Workflow: getModel() method is throwing null value

I've created a new workflow model in the workflow console and trying to access it using a service. From the jsp I'm passing the workflow name as /etc/workflow/models/DeleteNode/jcr:content/model, followed the format mentioned in the AEM docs. But the WorkFlowModel is throwing null value while I try to get the model from the path that I've passed.
below is the service that I've written:
package com.aem.sample.workflow;
import java.util.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.io.InputStream;
import javax.jcr.Repository;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.jackrabbit.commons.JcrUtils;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
import javax.jcr.Session;
import javax.jcr.Node;
//Adobe CQ Workflow APIs
import com.day.cq.workflow.model.WorkflowModel ;
import com.day.cq.workflow.WorkflowService ;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkflowData;
//Sling Imports
import org.apache.sling.api.resource.ResourceResolverFactory ;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.Resource;
//This is a component so it can provide or consume services
#Component
#Service
public class InvokeAEMWorkflowImp implements InvokeAEMWorkflow {
#Reference
private WorkflowService workflowService;
private Session session;
#Reference
private ResourceResolverFactory resolverFactory;
#Override
public String StartWorkflow(String workflowName, String workflowContent) {
try
{
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
//Create a workflow session
WorkflowSession wfSession = workflowService.getWorkflowSession(session);
// Get the workflow model
WorkflowModel wfModel = wfSession.getModel(workflowName);
// Get the workflow data
// The first param in the newWorkflowData method is the payloadType. Just a fancy name to let it know what type of workflow it is working with.
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", workflowContent);
// Run the Workflow.
wfSession.startWorkflow(wfModel, wfData);
return workflowName +" has been successfully invoked on this content: "+workflowContent ;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
}