-
-
Notifications
You must be signed in to change notification settings - Fork 756
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
#228 fix: The extension of the Page Object design pattern #267
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5fa7e2e
#228 fix: Current functionality was redesigned
TikhomirovSergey cf89ce2
#228 fix: some improvements + the new annotation
TikhomirovSergey 34b9bdf
#228 fix: Drafts of a new framework
TikhomirovSergey 661d490
#228 fix: The widget overriding was implemented
TikhomirovSergey 0e317f8
#228 fix: Everything is implemented
TikhomirovSergey 7388d41
#228 fix: Some bugs are fixed
TikhomirovSergey 5efbae3
#228 fix: android app for demonstration
TikhomirovSergey e9223cf
#228 fix: test iOS app for the demonstration
TikhomirovSergey 8f69b8c
#228 fix: Android and Html cases were covered with tests.
TikhomirovSergey 3875c22
#228 fix: Test on a single crossplatform object
TikhomirovSergey 26cad60
#228 fix: drafts for the iOS testing
TikhomirovSergey 57ddaa6
#228 fix: Test coverage has been finished
TikhomirovSergey aea510a
#228 fix: code of iOS tests was improved
TikhomirovSergey a584c66
README updated
TikhomirovSergey fd86f83
#228 fix: format issue fix
TikhomirovSergey 5c9c438
#228 fix: typo fixe (test scope)
TikhomirovSergey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
#228 fix: Drafts of a new framework
- Loading branch information
commit 34b9bdf4a48a33cf7806595be2404d445a2c8fd3
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,23 +26,19 @@ | |
import org.openqa.selenium.support.pagefactory.ElementLocatorFactory; | ||
|
||
class AppiumElementLocatorFactory implements ElementLocatorFactory { | ||
protected final SearchContext searchContext; | ||
protected final TimeOutDuration timeOutDuration; | ||
protected final String platform; | ||
protected final String automation; | ||
protected final WebDriver originalWebDriver; | ||
protected final AppiumByBuilder byBuilder; | ||
private final SearchContext searchContext; | ||
private final TimeOutDuration timeOutDuration; | ||
private final WebDriver originalWebDriver; | ||
private final AppiumByBuilder builder; | ||
|
||
public AppiumElementLocatorFactory(SearchContext searchContext, | ||
String platform, String automation, | ||
TimeOutDuration timeOutDuration, | ||
WebDriver originalWebDriver) { | ||
WebDriver originalWebDriver, | ||
AppiumByBuilder builder) { | ||
this.searchContext = searchContext; | ||
this.originalWebDriver = originalWebDriver; | ||
this.timeOutDuration = timeOutDuration; | ||
this.platform = platform; | ||
this.automation = automation; | ||
byBuilder = new DefaultElementByBuilder(platform, automation); | ||
this.builder = builder; | ||
} | ||
|
||
public ElementLocator createLocator(Field field) { | ||
|
@@ -53,10 +49,12 @@ public ElementLocator createLocator(Field field) { | |
} | ||
else | ||
customDuration = timeOutDuration; | ||
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. spacing is weird, your IDE should be able to auto format the Java files |
||
byBuilder.setAnnotated(field); | ||
By by = byBuilder.buildBy(); | ||
builder.setAnnotated(field); | ||
By by = builder.buildBy(); | ||
if (by != null) | ||
return new AppiumElementLocator(searchContext, by, byBuilder.isLookupCached(), customDuration, originalWebDriver); | ||
return new AppiumElementLocator(searchContext, by, builder.isLookupCached(), customDuration, originalWebDriver); | ||
return null; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/io/appium/java_client/pagefactory/OverrideWidgetReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.pagefactory; | ||
|
||
|
||
import io.appium.java_client.pagefactory.bys.ContentType; | ||
|
||
import java.lang.reflect.AnnotatedElement; | ||
import java.util.Map; | ||
|
||
class OverrideWidgetReader { | ||
|
||
Map<ContentType, Class<? extends Widget>> read(Class<? extends Widget> declaredClass, AnnotatedElement annotatedElement, | ||
String platform, String automation){ | ||
//TODO | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/io/appium/java_client/pagefactory/WidgetByBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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.pagefactory; | ||
|
||
import org.openqa.selenium.By; | ||
import java.lang.reflect.AnnotatedElement; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
class WidgetByBuilder extends DefaultElementByBuilder { | ||
|
||
private enum WhatIsNeeded { | ||
DEFAULT_OR_HTML, | ||
MOBILE_NATIVE | ||
} | ||
|
||
protected WidgetByBuilder(String platform, String automation) { | ||
super(platform, automation); | ||
} | ||
|
||
private static Class<?> getClassFromAListField(Field field){ | ||
Type genericType = field.getGenericType(); | ||
if (!(genericType instanceof ParameterizedType)) { | ||
return null; | ||
} | ||
|
||
Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0]; | ||
if (ParameterizedType.class.isAssignableFrom(listType.getClass())) | ||
listType = ((ParameterizedType) listType).getRawType(); | ||
|
||
return (Class<?>) listType; | ||
} | ||
|
||
private By getByFromDeclaredClass(WhatIsNeeded whatIsNeeded){ | ||
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated(); | ||
By result = null; | ||
Field field = null; | ||
try { | ||
Class<?> declaredClass; | ||
if (Field.class.isAssignableFrom(annotatedElement.getClass())) { | ||
field = Field.class.cast(annotatedElement); | ||
if (List.class.isAssignableFrom(field.getType())) | ||
declaredClass = getClassFromAListField(field); | ||
else | ||
declaredClass = field.getType(); | ||
} else { | ||
declaredClass = Class.class.cast(annotatedElement); | ||
} | ||
|
||
while (result == null && !declaredClass.equals(Object.class)) { | ||
setAnnotated(declaredClass); | ||
if (whatIsNeeded.equals(WhatIsNeeded.DEFAULT_OR_HTML)) | ||
result = super.buildDefaultBy(); | ||
else | ||
result = super.buildMobileNativeBy(); | ||
declaredClass = declaredClass.getSuperclass(); | ||
} | ||
return result; | ||
} | ||
finally { | ||
if (field != null) | ||
setAnnotated(field); | ||
} | ||
} | ||
|
||
@Override | ||
protected By buildDefaultBy() { | ||
By defaultBy = super.buildDefaultBy(); | ||
|
||
if (defaultBy != null) | ||
return defaultBy; | ||
else | ||
return getByFromDeclaredClass(WhatIsNeeded.DEFAULT_OR_HTML); | ||
} | ||
|
||
@Override | ||
protected By buildMobileNativeBy() { | ||
By mobileBy = super.buildMobileNativeBy(); | ||
|
||
if (mobileBy != null) | ||
return mobileBy; | ||
else | ||
return getByFromDeclaredClass(WhatIsNeeded.MOBILE_NATIVE); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/io/appium/java_client/pagefactory/WidgetInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.pagefactory; | ||
|
||
import io.appium.java_client.pagefactory.bys.ContentType; | ||
import net.sf.cglib.proxy.MethodInterceptor; | ||
import net.sf.cglib.proxy.MethodProxy; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
class WidgetInterceptor implements MethodInterceptor{ | ||
|
||
private final WebElement element; | ||
private final Map<ContentType, Class<? extends Widget>> instantiationMap; | ||
private final Map<ContentType, Widget> cachedInstances = new HashMap<>(); | ||
private final AppiumFieldDecorator decorator; | ||
|
||
WidgetInterceptor(WebElement element, Map<ContentType, Class<? extends Widget>> instantiationMap, | ||
AppiumFieldDecorator decorator) { | ||
this.element = element; | ||
this.instantiationMap = instantiationMap; | ||
this.decorator = decorator; | ||
} | ||
|
||
@Override | ||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { | ||
//TODO | ||
return null; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/io/appium/java_client/pagefactory/WidgetListInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.pagefactory; | ||
|
||
import io.appium.java_client.pagefactory.bys.ContentType; | ||
import net.sf.cglib.proxy.MethodInterceptor; | ||
import net.sf.cglib.proxy.MethodProxy; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
class WidgetListInterceptor implements MethodInterceptor{ | ||
|
||
private final List<WebElement> elements; | ||
private final Map<ContentType, Class<? extends Widget>> instantiationMap; | ||
private final List<WebElement> cachedElements = new ArrayList<>(); | ||
private final List<Widget> cachedWidgets = new ArrayList<>(); | ||
private final Class<? extends Widget> declaredType; | ||
private final AppiumFieldDecorator decorator; | ||
|
||
WidgetListInterceptor(List<WebElement> elements, Map<ContentType, Class<? extends Widget>> instantiationMap, | ||
Class<? extends Widget> declaredType, AppiumFieldDecorator decorator) { | ||
this.elements = elements; | ||
this.instantiationMap = instantiationMap; | ||
this.declaredType = declaredType; | ||
this.decorator = decorator; | ||
} | ||
|
||
|
||
@Override | ||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { | ||
//TODO | ||
return null; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think if/else should always use braces, even for single lines. This is a style suggestion.