本文整理汇总了Java中org.openqa.selenium.Dimension.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Dimension.getWidth方法的具体用法?Java Dimension.getWidth怎么用?Java Dimension.getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.Dimension
的用法示例。
在下文中一共展示了Dimension.getWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: swipeTo
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
private TouchAction swipeTo (final SwipeDirection direction, final SwipeDistance distance) {
final Dimension size = this.driver.manage ()
.window ()
.getSize ();
final int startX = size.getWidth () / 2;
final int startY = size.getHeight () / 2;
final int endX = (int) (startX * direction.getX () * distance.getDistance ());
final int endY = (int) (startY * direction.getY () * distance.getDistance ());
final int beforeSwipe = this.device.getSetting ()
.getDelayBeforeSwipe ();
final int afterSwipe = this.device.getSetting ()
.getDelayAfterSwipe ();
final TouchAction returnAction = new TouchAction (this.driver);
returnAction.press (startX, startY)
.waitAction (ofSeconds (beforeSwipe))
.moveTo (endX, endY)
.waitAction (ofSeconds (afterSwipe))
.release ();
return returnAction;
}
示例2: get
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
public void get( String url )
{
setLastAction();
webDriver.get( url );
try
{
double outerHeight = Integer.parseInt( executeScript( "return window.outerHeight;" ) + "" );
double outerWidth = Integer.parseInt( executeScript( "return window.outerWidth;" ) + "" );
Dimension windowSize = manage().window().getSize();
Object f = executeScript( "return window.outerHeight;" );
heightModifier = (double) windowSize.getHeight() / outerHeight;
widthModifier = (double) windowSize.getWidth() / outerWidth;
}
catch( Exception e )
{
log.warn( "Could not extract height/width modifiers" );
heightModifier = 1;
widthModifier = 1;
}
}
示例3: pinch
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
/**
* Convenience method for pinching an element on the screen.
* "pinching" refers to the action of two appendages pressing the
* screen and sliding towards each other.
* NOTE:
* This convenience method places the initial touches around the element, if this would
* happen to place one of them off the screen, appium with return an outOfBounds error.
* In this case, revert to using the MultiTouchAction api instead of this method.
*
* @param el The element to pinch.
*/
public void pinch(WebElement el) {
MultiTouchAction multiTouch = new MultiTouchAction(this);
Dimension dimensions = el.getSize();
Point upperLeft = el.getLocation();
Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,
upperLeft.getY() + dimensions.getHeight() / 2);
int yOffset = center.getY() - upperLeft.getY();
TouchAction action0 =
new TouchAction(this).press(el, center.getX(), center.getY() - yOffset).moveTo(el)
.release();
TouchAction action1 =
new TouchAction(this).press(el, center.getX(), center.getY() + yOffset).moveTo(el)
.release();
multiTouch.add(action0).add(action1);
multiTouch.perform();
}
示例4: zoom
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
/**
* Convenience method for "zooming in" on an element on the screen.
* "zooming in" refers to the action of two appendages pressing the screen and sliding
* away from each other.
* NOTE:
* This convenience method slides touches away from the element, if this would happen
* to place one of them off the screen, appium will return an outOfBounds error.
* In this case, revert to using the MultiTouchAction api instead of this method.
*
* @param el The element to pinch.
*/
public void zoom(WebElement el) {
MultiTouchAction multiTouch = new MultiTouchAction(this);
Dimension dimensions = el.getSize();
Point upperLeft = el.getLocation();
Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,
upperLeft.getY() + dimensions.getHeight() / 2);
int yOffset = center.getY() - upperLeft.getY();
TouchAction action0 = new TouchAction(this).press(center.getX(), center.getY())
.moveTo(el, center.getX(), center.getY() - yOffset).release();
TouchAction action1 = new TouchAction(this).press(center.getX(), center.getY())
.moveTo(el, center.getX(), center.getY() + yOffset).release();
multiTouch.add(action0).add(action1);
multiTouch.perform();
}
示例5: childConcepts
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
private List<ImmutablePair<WebElement, Integer>> childConcepts(final int clusterIndex) {
//((lowestX,highestX),(lowestY,highestY))
final Double[][] boundariesOfChosenCluster = nthConceptCluster(clusterIndex).getBoundaries();
final Point mapCoordinates = map().getLocation();
//L:Concept; Y:Index
final List<ImmutablePair<WebElement, Integer>> childConceptsOfChosenCluster = new ArrayList<>();
int entityIndex = 0;
for(final WebElement concepts : concepts()) {
final Dimension entitySize = concepts.getSize();
final Point absolutePosition = concepts.getLocation();
final int centreX = absolutePosition.x - mapCoordinates.x + entitySize.getWidth() / 2;
final int centreY = absolutePosition.y - mapCoordinates.y + entitySize.getHeight() / 2;
final Point centre = new Point(centreX, centreY);
if(boundariesOfChosenCluster[0][0] <= centre.x && centre.x <= boundariesOfChosenCluster[0][1]
&& boundariesOfChosenCluster[1][0] <= centre.y && centre.y <= boundariesOfChosenCluster[1][1]) {
childConceptsOfChosenCluster.add(new ImmutablePair<>(concepts, entityIndex));
}
entityIndex++;
}
return childConceptsOfChosenCluster;
}
示例6: swipeUp
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
protected void swipeUp(Point rootLocation, Dimension rootSize, int duration, float topPad, float bottomPad) {
int offset = 1;
int topOffset = Math.round(rootSize.getHeight() * topPad);
int bottomOffset = Math.round(rootSize.getHeight() * bottomPad);
Point center = new Point(rootLocation.x + rootSize.getWidth() / 2, rootLocation.y + rootSize.getHeight() / 2);
logger.debug("Swiping up at" +
" x1: " + center.getX() +
" y1:" + (rootLocation.getY() + rootSize.getHeight() - bottomOffset + offset) +
" x2:" + center.getX() +
" y2:" + (rootLocation.getY() + topOffset));
driver.swipe(center.getX(),
rootLocation.getY() + rootSize.getHeight() - bottomOffset + offset,
center.getX(),
rootLocation.getY() + topOffset,
duration);
}
示例7: swipeDown
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
protected void swipeDown(Point rootLocation, Dimension rootSize, int duration, float topPad, float bottomPad) {
int offset = 1;
int topOffset = Math.round(rootSize.getHeight() * topPad);
int bottomOffset = Math.round(rootSize.getHeight() * bottomPad);
Point center = new Point(rootLocation.x + rootSize.getWidth() / 2, rootLocation.y + rootSize.getHeight() / 2);
logger.debug("Swiping down at" +
" x1: " + center.getX() +
" y1:" + (rootLocation.getY() + topOffset) +
" x2:" + center.getX() +
" y2:" + (rootLocation.getY() + rootSize.getHeight() - bottomOffset + offset));
driver.swipe(center.getX(),
(rootLocation.getY() + topOffset),
center.getX(),
(rootLocation.getY() + rootSize.getHeight() - bottomOffset + offset),
duration);
}
示例8: swipeLeft
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
protected void swipeLeft(Point rootLocation, Dimension rootSize, int duration, float leftPad, float rightPad) {
int offset = 1;
int leftOffset = Math.round(rootSize.getWidth() * leftPad);
int rightOffset = Math.round(rootSize.getWidth() * rightPad);
Point center = new Point(rootLocation.x + rootSize.getWidth() / 2, rootLocation.y + rootSize.getHeight() / 2);
logger.debug("Swiping left at" +
" x1: " + (rootLocation.getX() + rootSize.getWidth() - rightOffset + offset) +
" y1:" + center.getY() +
" x2:" + (rootLocation.getX() + leftOffset) +
" y2:" + center.getY());
driver.swipe((rootLocation.getX() + rootSize.getWidth() - rightOffset + offset),
center.getY(),
(rootLocation.getX() + leftOffset),
center.getY(),
duration);
}
示例9: swipeRight
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
protected void swipeRight(Point rootLocation, Dimension rootSize, int duration, float leftPad, float rightPad) {
int offset = 1;
int leftOffset = Math.round(rootSize.getWidth() * leftPad);
int rightOffset = Math.round(rootSize.getWidth() * rightPad);
Point center = new Point(rootLocation.x + rootSize.getWidth() / 2, rootLocation.y + rootSize.getHeight() / 2);
logger.debug("Swiping right at" +
" x1: " + (rootLocation.getX() + leftOffset) +
" y1:" + center.getY() +
" x2:" + (rootLocation.getX() + rootSize.getWidth() - rightOffset + offset) +
" y2:" + center.getY());
driver.swipe((rootLocation.getX() + leftOffset),
center.getY(),
(rootLocation.getX() + rootSize.getWidth() - rightOffset + offset),
center.getY(),
duration);
}
示例10: tapAtCoordinates
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
public void tapAtCoordinates(int x, int y) throws Exception {
if (automationName.equalsIgnoreCase("selendroid")) {
selendroidTapAtCoordinate(x, y, 1);
} else if (platform.equals(PlatformType.ANDROID)){
Dimension size = driver.manage().window().getSize();
if(y > size.getHeight() || x > size.getWidth()){
log("using adb tap at " + x + ", " + y);
try{
//run eclipse from commandline to get path variable correct and find adb
Process p = Runtime.getRuntime().exec("adb -s " + udid + " shell input tap " + x + " " + y);
p.waitFor();
} catch (Exception e) {
log(e.toString());
}
} else {
driver.tap(1, x, y, 1);
}
} else {
driver.tap(1, x, y, 1);
}
}
示例11: swipeHorizontally
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
public void swipeHorizontally(double x_offset, double y_offset, int distance, int swipes, double frequency) throws Exception {
Dimension size = driver.manage().window().getSize();
Point middle = new Point(size.getWidth(), size.getHeight());
Point middleWithOffset = new Point(middle.x * x_offset, middle.y * y_offset);
int startX = (int) middleWithOffset.x;
int startY = (int) middleWithOffset.y;
int endX = startX + distance;
int endY = startY;
for (int i = 0; i < swipes; i++) {
if (PlatformType.IOS.equals(PlatformType.IOS)) {
iOSSwipe(startX, startY, endX, endY);
} else {
androidSwipe(startX, startY, endX, endY);
}
sleep(frequency);
}
log("Finished executing swipes");
}
示例12: swipeVertically
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
public void swipeVertically(double x_offset, double y_offset, int distance, int swipes, double frequency) throws Exception {
Dimension size = driver.manage().window().getSize();
Point middle = new Point(size.getWidth(), size.getHeight());
Point middleWithOffset = new Point(middle.x * x_offset, middle.y * y_offset);
int startX = (int) middleWithOffset.x;
int startY = (int) middleWithOffset.y;
int endX = startX;
int endY = startY + distance;
for (int i = 0; i < swipes; i++) {
if (PlatformType.IOS.equals(PlatformType.IOS)) {
iOSSwipe(startX, startY, endX, endY);
} else {
androidSwipe(startX, startY, endX, endY);
}
sleep(frequency);
}
log("Finished executing swipes");
}
示例13: dragImageToMiddle
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
public void dragImageToMiddle(String object) throws Exception {
Dimension size = driver.manage().window().getSize();
Point middle = new Point(size.getWidth() / 2 - 20, size.getHeight() / 2 + 20);
ImageRecognitionSettings settings = new ImageRecognitionSettings();
settings.setRetries(10);
ImageSearchResult object_image = findImageOnScreen(object, settings);
assert(object_image.isFound());
ImageLocation object_image_location = object_image.getImageLocation();
int startX = (int) object_image_location.getCenter().x;
int startY = (int) object_image_location.getCenter().y;
int endX = (int) middle.x;
int endY = (int) middle.y;
if (automationName.equalsIgnoreCase("selendroid")) {
androidSwipe(startX, startY, endX, endY);
} else {
iOSSwipe(startX, startY, endX, endY);
}
}
示例14: dragImageToCoordinates
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
public void dragImageToCoordinates(String object, double x_offset, double y_offset) throws Exception {
Dimension size = driver.manage().window().getSize();
Point screen = new Point(size.getWidth(), size.getHeight());
Point swipe_end = new Point(screen.x * x_offset, screen.y * y_offset);
ImageRecognitionSettings settings = new ImageRecognitionSettings();
settings.setRetries(10);
ImageSearchResult object_image = findImageOnScreen(object, settings);
assert(object_image.isFound());
ImageLocation object_image_location = object_image.getImageLocation();
int startX = (int) object_image_location.getCenter().x;
int startY = (int) object_image_location.getCenter().y;
int endX = (int) swipe_end.x;
int endY = (int) swipe_end.y;
if (automationName.equalsIgnoreCase("selendroid")) {
androidSwipe(startX, startY, endX, endY);
} else {
iOSSwipe(startX, startY, endX, endY);
}
}
示例15: correctAndroidCoordinates
import org.openqa.selenium.Dimension; //导入方法依赖的package包/类
/**
* ======================================================================================
* OTHER UTILITIES
* ======================================================================================
*/
//TODO: experimental method
public Point correctAndroidCoordinates(Point appium_coord) throws Exception {
Dimension appium_dimensions = driver.manage().window().getSize();
int appium_screenWidth = appium_dimensions.getWidth();
int appium_screenHeight = appium_dimensions.getHeight();
Dimension adb_dimension = getScreenSizeADB();
int adb_screenWidth = adb_dimension.getWidth();
int adb_screenHeight = adb_dimension.getHeight();
double x_offset = appium_coord.x / appium_screenWidth;
double y_offset = appium_coord.y / appium_screenHeight;
log("x_offset is : " + x_offset);
log("y_offset is : " + y_offset);
return new Point(x_offset * adb_screenWidth, y_offset * adb_screenHeight);
}