-
-
Notifications
You must be signed in to change notification settings - Fork 764
Mykola mokhnach's actions params: The addition to the #756 #760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
55039ab
5fdf0e1
95e4042
c817ac4
f525ae3
42f4a96
cbd9f5d
0b185e0
c8185da
c892098
483ba5a
ee55d22
6ddbd2e
92ab4c6
52492ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.android; | ||
|
||
import io.appium.java_client.PerformsTouchActions; | ||
import io.appium.java_client.TouchAction; | ||
|
||
|
||
public class AndroidTouchAction extends TouchAction<AndroidTouchAction> { | ||
|
||
public AndroidTouchAction(PerformsTouchActions performsTouchActions) { | ||
super(performsTouchActions); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.touch; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import org.openqa.selenium.Point; | ||
|
||
import java.util.Map; | ||
|
||
public class AbsoluteOffsetOption extends ActionOptions<AbsoluteOffsetOption> { | ||
private Point absoluteOffset = null; | ||
|
||
/** | ||
* It creates an instance of {@link AbsoluteOffsetOption } which takes absolute | ||
* x and y offsets. | ||
* | ||
* @param xOffset the absolute distance from the left screen corner. | ||
* @param yOffset the absolute distance from the top screen corner. | ||
* @return a built option | ||
*/ | ||
public static AbsoluteOffsetOption useAbsolute(int xOffset, int yOffset) { | ||
return new AbsoluteOffsetOption().withAbsoluteOffset(xOffset, yOffset); | ||
} | ||
|
||
/** | ||
* Set the absolute offset for the corresponding action. | ||
* | ||
* @param xOffset the absolute distance from the left screen corner. | ||
* @param yOffset the absolute distance from the top screen corner. | ||
* @return this instance for chaining. | ||
*/ | ||
public AbsoluteOffsetOption withAbsoluteOffset(int xOffset, int yOffset) { | ||
this.absoluteOffset = new Point(xOffset, yOffset); | ||
//noinspection unchecked | ||
return this; | ||
} | ||
|
||
@Override | ||
protected void verify() { | ||
ofNullable(absoluteOffset).orElseThrow(() -> new IllegalArgumentException( | ||
"Absolute offset must not be defined")); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> build() { | ||
final Map<String, Object> result = super.build(); | ||
ofNullable(absoluteOffset).ifPresent(point -> { | ||
result.put("x", point.x); | ||
result.put("y", point.y); | ||
}); | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.touch; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public abstract class ActionOptions<T extends ActionOptions<T>> { | ||
/** | ||
* This method is automatically called before building | ||
* options map to verify the consistency of the instance. | ||
* | ||
* @throws IllegalArgumentException if there are problems with this options map. | ||
*/ | ||
protected abstract void verify(); | ||
|
||
/** | ||
* Creates a map based on the provided options. | ||
* | ||
* @return options mapping. | ||
*/ | ||
public Map<String, Object> build() { | ||
verify(); | ||
return new HashMap<>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.touch; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static java.util.Optional.ofNullable; | ||
|
||
import java.time.Duration; | ||
import java.util.Map; | ||
|
||
public class LongPressOptions extends OptionsCombinedWithOffset<LongPressOptions> { | ||
protected Duration duration = null; | ||
|
||
/** | ||
* It creates an empty instance of {@link LongPressOptions}. | ||
* | ||
* @return an empty instance of {@link LongPressOptions} | ||
*/ | ||
public static LongPressOptions longPressOptions() { | ||
return new LongPressOptions(); | ||
} | ||
|
||
/** | ||
* Set the long press duration. | ||
* | ||
* @param duration the value to set. | ||
* Time resolution unit is 1 ms. | ||
* @return this instance for chaining. | ||
*/ | ||
public LongPressOptions withDuration(Duration duration) { | ||
checkNotNull(duration); | ||
checkArgument(duration.toMillis() >= 0, | ||
"Duration value should be greater or equal to zero"); | ||
this.duration = duration; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> build() { | ||
final Map<String, Object> result = super.build(); | ||
ofNullable(duration).ifPresent(durationParam -> | ||
result.put("duration", durationParam.toMillis())); | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.appium.java_client.touch; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class OptionsCombinedWithOffset<T extends OptionsCombinedWithOffset> | ||
extends ActionOptions<OptionsCombinedWithOffset<T>> { | ||
private ActionOptions<?> offsetOption; | ||
|
||
/** | ||
* Some actions may require some absolute offset value to be performed. | ||
* Invocation of this method replaces the result of previous invocation of | ||
* the {@link #withOffset(RelativeOffsetOption)} | ||
* | ||
* @param offset is the values of required absolute offset from the left corner of a screen. * | ||
* @return self-reference | ||
*/ | ||
public T withOffset(AbsoluteOffsetOption offset) { | ||
offsetOption = offset; | ||
return (T) this; | ||
} | ||
|
||
/** | ||
* Some actions may require some relative offset value to be performed. | ||
* Invocation of this method replaces the result of previous invocation of | ||
* the {@link #withOffset(AbsoluteOffsetOption)} | ||
* | ||
* @param offset is the values of required offset from the left corner of an element. * | ||
* @return self-reference | ||
*/ | ||
public T withOffset(RelativeOffsetOption offset) { | ||
offsetOption = offset; | ||
return (T) this; | ||
} | ||
|
||
protected void verify() { | ||
ofNullable(offsetOption).orElseThrow(() -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should consider here, that useRelative(x,y) won't work as expected for press/tap/longTap. I think the best way to avoid it would be to extract element parameter from RelativeOffset into withElement like we discussed before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the main reason of this is that we anyway translate both relative and absolute offset into |
||
new IllegalArgumentException("Some relative or absolute offset should " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ->Either relative or absolute |
||
+ "be defined. Use one of withOffset methods")); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> build() { | ||
final Map<String, Object> result = super.build(); | ||
result.putAll(offsetOption.build()); | ||
return result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why must not?