Appium scrolling with TouchAction - appium-android

I am using the below code for scrolling:
There is no error from eclipse but during execution I am getting error as “java.lang.ClassCastException: java.lang.NoSuchMethodError cannot be cast to java.lang.Exception” at the first line itself. It did not execute the second line. Please help.
Appium version: 1.10.0
Java Client: 6.1.0
TouchAction action = new TouchAction((MobileDriver) driver.getWebDriver());
action.press(PointOption.point(startx,starty)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(50))).action.moveTo(PointOption.point(startx, endy)).release().perform();

This is my swipe method. It works with versions 6.1.0 and 7.0.0 of Appium.
You can use this codes.
public void swipeWithRatio(int startXRatio, int startYRatio, int endXRatio, int endYRatio, int durationMiliSec) {
Dimension d = getPhoneSize();
int height = d.height;
int width = d.width;
int swipeStartWidth = (width * startXRatio) / 100;
int swipeStartHeight = (height * startYRatio) / 100;
int swipeEndWidth = (width * endXRatio) / 100;
int swipeEndHeight = (height * endYRatio) / 100;
new TouchAction(driver)
.press(point(swipeStartWidth, swipeStartHeight))
.waitAction(waitOptions(Duration.ofMillis(durationMiliSec)))
.moveTo(point(swipeEndWidth, swipeEndHeight))
.release()
.perform();
}
// Swipe from up to down example
// It starts from 25 percent of the screen and continues to 75 percent.
swipeWithRatio(50,25,50,75,2000);
// Swipe from down to up example
// It starts from 75 percent of the screen and continues to 25 percent.
swipeWithRatio(50,75,50,25,2000);

Related

Angular9 Signature Pad issue: Signature drawn offset from pen touch

I implemented a signature pad using https://github.com/ramsatt/Angular9SignaturePad/tree/master/src/app/_componets/signature-pad and it works fine on smaller devices but on iPad or bigger devices like 7" upwards, it doesn't work properly.
When drawing on the screen, the resulting line has an offset from where the user touched (Signature drawn doesn't appear directly under the pen as user draws).
please how can I fix this.
So I fixed it by adding the below code and calling it in ngOnInit
resizeCanvas() {
var width = this.signaturePadElement.nativeElement.width;
var height = this.signaturePadElement.nativeElement.height;
var ratio = Math.max(window.devicePixelRatio || 1, 1);
if (ratio <= 2) {
this.signaturePadElement.nativeElement.width = width * ratio;
this.signaturePadElement.nativeElement.height = height * ratio;
this.signaturePadElement.nativeElement
.getContext("2d")
.scale(ratio, ratio);
}
then do
ngOnInit(){
this.resizeCanvas()
}
this.signaturePadElement is your Element gotten using ViewChild()

How do we add selectors/ids to Flutter widgets so they can be accessed from Appium

we want to use Appium/Selenium to do automated testing on a Flutter application. Some elements do not have selectors when viewed in Selenium. In Android we just add ids onto every element and they appear in Appium. How do we do this in a flutter environment?
I found an approach with a workaround which then lets you use Selenium reasonably naturally with Flutter Web (although not working with headless browser)
You need to find the offset of window x y coordinates from screen x y coordiantes. I found this idea in another thread
pageCallibrator.html:
<script>
window.coordinates = [];
document.addEventListener('click', function() {
window.coordinates = [event.pageX, event.pageY];
});
</script>
Then in Selenium setup before running tests (Java example)
int windowScreenOffsetX = 0;
int windowScreenOffsetY = 0;
void callibrateXY(WebDriver driver) {
driver.get("http://localhost:8080/pageCallibrator.html"); //TODO adjust host
Dimension size = driver.manage().window().getSize();
int x = size.width / 2;
int y = size.height / 2;
clickMouseAtXY(x, y);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
List<Object> coordinates = (List<Object>) ((JavascriptExecutor) driver).executeScript("return window.coordinates;");
windowScreenOffsetX = x - (int) (long) coordinates.get(0);
windowScreenOffsetY = y - (int) (long) coordinates.get(1);
}
Now in Selenium to press a Flutter button
WebElement continueToBankButtonElement = findElementWithText(driver, "My button text");
clickMouseAtElement(continueToBankButtonElement);
where you define
import org.openqa.selenium.*
Robot robot = new Robot();
Driver driver = new ChromeDriver(options); // TODO handler exceptions and options in a method
WebElement findElementWithText(WebDriver driver, String text) {
return driver.findElement(containsTextLocator(text));
}
By containsTextLocator(String text) {
return By.xpath("//*[contains(text(), '" + text + "')]");
}
void clickMouseAtElement(WebElement element) {
clickMouseAtXY(element.getLocation().getX() + element.getSize().width / 2, element.getLocation().getY() + element.getSize().height / 2);
}
void clickMouseAtXY(int x, int y) {
moveMouse(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
/**
* #param x
* #param y
*/
protected void moveMouse(int x, int y) {
robot.mouseMove(x + windowScreenOffsetX, y + windowScreenOffsetY); // Offset of page from screen
}
Prior to this morning I knew nothing of Flutter. A few hours later and I can safely say "you don't." While Flutter makes developing an application quick and easy, it removes a lot of the control you have, including the level of customization you're looking for.
There are hits on this on official Flutter message boards dating back a year or two, but there were no answers.
You could attempt locating everything by text? Kluge, difficult or impossible to maintain, but likely your only option at this point.

Visual Studio Extensibility: Rectange-s added to Children class of the ScrollbarMargin prevent mouse clicks on the scrollbar

I've developed an extension some time ago that allows to highlight a section of the scrollbar with the specified color, here is how I do it:
/// <summary>On layout changed analyze the regions and lines and highlight them on the scroll bar if needed.</summary>
private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
{
Children.Clear();
int n = AllAdornments.TextAdornment.Regions.Length;
for (int i = 0; i < n; i++)
{
if (AllAdornments.TextAdornment.Regions[i].Adornment != null
&& AllAdornments.TextAdornment.Regions[i].EndLine < e.NewSnapshot.LineCount)
{
var rect = new Rectangle();
var firstLine = e.NewSnapshot.GetLineFromLineNumber(AllAdornments.TextAdornment.Regions[i].StartLine);
var lastLine = e.NewSnapshot.GetLineFromLineNumber(AllAdornments.TextAdornment.Regions[i].EndLine);
double top, bottom;
double firstLineTop;
MapLineToPixels(firstLine, out firstLineTop, out bottom);
SetTop(rect, firstLineTop);
SetLeft(rect, ScrollBarLeftPadding);
MapLineToPixels(lastLine, out top, out bottom);
rect.Height = bottom - firstLineTop;
rect.Width = ScrollBarWidth;
Color color = Communicator.LerpColor(AllAdornments.TextAdornment.UserBackgroundCol,
AllAdornments.TextAdornment.Regions[i].Adornment.Color, ScrollBarIntensity
* AllAdornments.TextAdornment.Regions[i].Adornment.IntensityMult);
color.A = ScrollBarOpacity;
rect.Fill = new SolidColorBrush(color);
Children.Add(rect);
}
}
}
Here is how it looks in Visual Studio:
This worked perfectly for a long time (around 1,5 - 2 years), but when I updated VS four months ago a problem emerged: I can no longer click on the section of the scrollbar margin with the colored Rectangle - the mouse click simply does nothing as long as it is above the colored Rectangle. On the empty section of the scrollbar it works as usual. Before I could not only click on my Rectangle-s, but hold the mouse button down and drag the scrollbar. Is there any way I can bring back this functionality?
Can you try setting rect.IsHitTestVisible = false;

How can I determine the screen size using addon SDK?

How can I get the screen size using with addon SDK ?
var w = screen.width/2;
gives me an error : Message: ReferenceError: screen is not defined
You can use the window you have associated to your add-on; it's probably safer, because it will work even if the last visible window is closed but firefox is still opened (e.g. on OS X):
const { window: { screen }} = require("sdk/addon/window");
console.log(screen.width);
This will work:
var screen = require('sdk/window/utils').getMostRecentBrowserWindow().screen;
console.log(screen.width);
If you want multi monitor support I have a script but you have to understand it. It uses XPCOM, and it needs a range. This script only checks along the x axis, you should also check along the y axis.
So this is the script here that will detect all monitors in the x plane IF it falls in the y plane of 0-20 coordintates of primary screen, I don't recommend this method.
var sm = Cc['#mozilla.org/gfx/screenmanager;1'].getService(Ci.nsIScreenManager);
function getScreens() {
var screen = null;
var screens = [];
var screenManager = sm;
var min = 0;
var max = 0;
for (x = 0; x < 15000; x += 600) {
var s = screenManager.screenForRect(x, 20, 10, 10);
if (s != screen) {
screen = s;
var left = {},
top = {},
width = {},
height = {};
screenManager.primaryScreen.GetRect(left, top, width, height);
screens.push({
width: width.value,
height: height.value,
min: min,
max: min + width.value
});
min += width.value;
}
}
return screens;
}
var screens = getScreens();
console.log('screens:', screens);
This is the method I recommend
I needed to detect all monitor dimensons and had to resort to jsctypes, if you need that its here: https://github.com/Noitidart/NativeShot/blob/master/modules/workers/MainWorker.js#L853-L1523
That code is extremely long, thats because its getting all monitors and the taking screenshots of them. So you will want to extract just the monitors part. If you need help with it I can do it for you.

Set zoomlevels for gwt-openlayers and openstreetmap

I'm trying to make the zoom level bar show the same number of zoom levels as my offline cache and it is surprisingly hard with gwt-openlayers.
I tried with no success :
osmOptions.getJSObject().setProperty(
"minZoomLevel", 5);
osmOptions.getJSObject().setProperty(
"maxZoomLevel", 11);
The method below is doing the trick for me now:
/**
* #param options
* #param minZoomLevel the minimum for this is 3 for open streetmap
* #param maxZoomLevel
*/
private static void setZoomLevelRange(LayerOptions options,
int minZoomLevel, int maxZoomLevel) {
options.getJSObject().setProperty("zoomOffset", minZoomLevel);
int len = maxZoomLevel - minZoomLevel + 1;
double[] resolutions = new double[len];
double curRes = 78271.51695 / (Math.pow(2, minZoomLevel - 1));
for (int i = 0; i < len; i++) {
resolutions[i] = curRes;
curRes = curRes / 2;
}
options.setResolutions(resolutions);
}
// usage example:
OSMOptions osmOptions = new OSMOptions();
setZoomLevelRange(osmOptions, 5, 11);
OSM baseTileLayer = new OSM("Mapnik",
// for offline tiles:
GWT.getHostPageBaseURL()
+ "tiles/${z}/${x}/${y}.png",
osmOptions);
The keys are:
there is apparently a magic zoom level 1 resolution (I have not found how it is calculated).
you can add higher and lower resolutions by multiplying or dividing them by 2.
it is critical that you set the zoomOffset in accordance to what you use as your minimum zoom level.
Your welcome and yeah you may copy the code as you want.
References:
http://forum.openstreetmap.org/viewtopic.php?id=6444
http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/XYZ-js.html#OpenLayers.Layer.XYZ.zoomOffset
http://osgeo-org.1560.n6.nabble.com/Can-t-restrict-Openlayers-Layer-OSM-to-use-specific-zoom-levels-td3926546.html