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

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

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.

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();

Getting date and time from a NTPUDPClient fails sometimes

I've been working on this program using NetBeans for 6 months and I've never experienced such an issue. It has began when I added org.apache.commons library (I needed it to get time from a online server) , when I run the program ,sometimes everything goes fine and sometimes it hangs on running state creating a process in the background. Here's the Class with the main method.
package samplefx.ctrl;
import java.io.IOException;
import java.net.InetAddress;
import java.sql.Date;
import java.text.ParseException;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.commons.net.ntp.NTPUDPClient;
import org.apache.commons.net.ntp.TimeInfo;
public class Optilight extends Application {
public static EntityManagerFactory emf;
EntityManager em;
#Override
public void start(Stage primaryStage) throws IOException, ParseException {
emf = Persistence.createEntityManagerFactory("SampleFXPU");
String TIME_SERVER = "time-a.nist.gov";
NTPUDPClient timeClient = new NTPUDPClient();
InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
TimeInfo timeInfo = timeClient.getTime(inetAddress);
long returnTime = timeInfo.getMessage().getTransmitTimeStamp().getTime();
Date time = new Date(returnTime);
Access access = new Access();
String fix = "XC193283R";
String var = access.Y();
Date start = Date.valueOf("2016-08-23");
Date end = Date.valueOf("2016-08-31");
Boolean j = false;
if (start.before(time) && time.before(end)) {
j = true;
}
boolean i = false;
if (fix.equals(var)) {
i = true;
}
if (!j || !i) {
System.exit(0);
}
// load main form in to VBox (Root)
BorderPane mainPane = (BorderPane) FXMLLoader.load(getClass().getResource("/samplefx/view/Login.fxml"));
// add main form into the scene
Scene scene = new Scene(mainPane);
//primaryStage.setTitle("Optilight 2.2.1");
primaryStage.setScene(scene);
primaryStage.initStyle(StageStyle.UNDECORATED);
//primaryStage.setMaximized(true); // make the main form fit to the screen
primaryStage.show();
primaryStage.setOnCloseRequest(e -> {
emf.close();
Platform.exit();
System.exit(0);
});
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
I finally found the answer to this, it's a server timeout issue . I added these two lines :
timeClient.open();
timeClient.setSoTimeout(5000);
after this line :
NTPUDPClient timeClient = new NTPUDPClient();

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();
}
}

how to work with hybrid mobile application using appium?

Can anybody help me,
I have been try to test hybrid application (developed in kony ide) using appiumbut the coding not executed .then using UIautomator viewer I didn't get "resource id " so im using by.name method. is der any possibility to get resource id?? then how to make work with hybrid application .
My coding
package com.appium.testcase;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver
public class AppiumTest
{
WebDriver driver=null;
#BeforeClass
public void setup()
{
File appDir = new File("E:/Automation/adt-bundle-windows-x86_64-20130514/sdk");
File app = new File(appDir, "WatsCooking.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "5.1");// motoe
//capabilities.setCapability(CapabilityType.VERSION, "4.2.1");//lava
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
capabilities.setCapability("app-Package","com.truetech.watcooking");
//Here we mention the activity name, which is invoked initially as app's first page.
capabilities.setCapability("app-Activity","com.truetech.watscooking.SplashActivity");
capabilities.setCapability("deviceName", "ZX1B328HPW");//motoe
//capabilities.setCapability("deviceName", "0123456789ABCDEF");//lava
capabilities.setCapability("app", app.getAbsolutePath());
try {
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
#Test
public void loginTest() throws Exception {
try{
System.out.println("call");
List <WebElement> loginbt =driver.findElements(By.id("btnlogin" ));
loginbt.get(1).click();
}
catch(NullPointerException ex1)
{
//System.out.println( "Value not found in Dropdown to Select");
}
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
You need to expose widget IDs. Do the following:
On the File menu, click Settings. The Project Settings dialog box displays.
Click the Native tab.
On the Common sub-tab, click Expose Widget IDs for Test Automation, and then click Finish.
For the Android platform, when you select to expose widget IDs, an xml file is generated during the build containing the widget IDs of the app. This is explained in detail under Android Limitations.
See the docs for more information.