Skip to content
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

Add uiautomator configurations #131

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.appium.uiautomator2.handler;

import android.support.annotation.Nullable;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -12,13 +9,17 @@
import io.appium.uiautomator2.http.AppiumResponse;
import io.appium.uiautomator2.http.IHttpRequest;
import io.appium.uiautomator2.model.Session;
import io.appium.uiautomator2.model.settings.ActionAcknowledgmentTimeout;
import io.appium.uiautomator2.model.settings.AllowInvisibleElements;
import io.appium.uiautomator2.model.settings.ElementResponseFields;
import io.appium.uiautomator2.model.settings.EnableNotificationListener;
import io.appium.uiautomator2.model.settings.CompressedLayoutHierarchy;
import io.appium.uiautomator2.model.settings.ISetting;
import io.appium.uiautomator2.model.settings.KeyInjectionDelay;
import io.appium.uiautomator2.model.settings.ScrollAcknowledgmentTimeout;
import io.appium.uiautomator2.model.settings.ShouldUseCompactResponses;
import io.appium.uiautomator2.model.settings.WaitForIdleTimeout;
import io.appium.uiautomator2.model.settings.WaitForSelectorTimeout;
import io.appium.uiautomator2.server.WDStatus;
import io.appium.uiautomator2.utils.Logger;

Expand All @@ -30,6 +31,10 @@ public class UpdateSettings extends SafeRequestHandler {
put(CompressedLayoutHierarchy.SETTING_NAME, CompressedLayoutHierarchy.class);
put(WaitForIdleTimeout.SETTING_NAME, WaitForIdleTimeout.class);
put(EnableNotificationListener.SETTING_NAME, EnableNotificationListener.class);
put(WaitForSelectorTimeout.SETTING_NAME, WaitForSelectorTimeout.class);
put(KeyInjectionDelay.SETTING_NAME, KeyInjectionDelay.class);
put(ActionAcknowledgmentTimeout.SETTING_NAME, ActionAcknowledgmentTimeout.class);
put(ScrollAcknowledgmentTimeout.SETTING_NAME, ScrollAcknowledgmentTimeout.class);
put(ElementResponseFields.SETTING_NAME, ElementResponseFields.class);
put(ShouldUseCompactResponses.SETTING_NAME, ShouldUseCompactResponses.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.uiautomator2.model.settings;

import android.support.test.uiautomator.Configurator;

public class ActionAcknowledgmentTimeout extends AbstractSetting<Integer> {

public static final String SETTING_NAME = "actionAcknowledgmentTimeout";

public ActionAcknowledgmentTimeout() {
super(Integer.class);
}

@Override
public String getSettingName() {
return SETTING_NAME;
}

@Override
protected void apply(Integer timeout) {
Configurator.getInstance().setActionAcknowledgmentTimeout(timeout);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.uiautomator2.model.settings;

import android.support.test.uiautomator.Configurator;

public class KeyInjectionDelay extends AbstractSetting<Integer> {

public static final String SETTING_NAME = "keyInjectionDelay";

public KeyInjectionDelay() {
super(Integer.class);
}

@Override
public String getSettingName() {
return SETTING_NAME;
}

@Override
protected void apply(Integer timeout) {
Configurator.getInstance().setKeyInjectionDelay(timeout);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.uiautomator2.model.settings;

import android.support.test.uiautomator.Configurator;

public class ScrollAcknowledgmentTimeout extends AbstractSetting<Integer> {

public static final String SETTING_NAME = "scrollAcknowledgmentTimeout";

public ScrollAcknowledgmentTimeout() {
super(Integer.class);
}

@Override
public String getSettingName() {
return SETTING_NAME;
}

@Override
protected void apply(Integer timeout) {
Configurator.getInstance().setScrollAcknowledgmentTimeout(timeout);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.uiautomator2.model.settings;

import android.support.test.uiautomator.Configurator;

public class WaitForSelectorTimeout extends AbstractSetting<Integer> {

public static final String SETTING_NAME = "waitForSelectorTimeout";

public WaitForSelectorTimeout() {
super(Integer.class);
}

@Override
public String getSettingName() {
return SETTING_NAME;
}

@Override
protected void apply(Integer timeout) {
Configurator.getInstance().setWaitForSelectorTimeout(timeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import org.json.JSONException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
Expand All @@ -35,20 +33,22 @@
import io.appium.uiautomator2.http.IHttpRequest;
import io.appium.uiautomator2.model.Session;
import io.appium.uiautomator2.model.settings.AbstractSetting;
import io.appium.uiautomator2.model.settings.ActionAcknowledgmentTimeout;
import io.appium.uiautomator2.model.settings.AllowInvisibleElements;
import io.appium.uiautomator2.model.settings.CompressedLayoutHierarchy;
import io.appium.uiautomator2.model.settings.ElementResponseFields;
import io.appium.uiautomator2.model.settings.EnableNotificationListener;
import io.appium.uiautomator2.model.settings.KeyInjectionDelay;
import io.appium.uiautomator2.model.settings.ScrollAcknowledgmentTimeout;
import io.appium.uiautomator2.model.settings.ShouldUseCompactResponses;
import io.appium.uiautomator2.model.settings.WaitForIdleTimeout;
import io.appium.uiautomator2.model.settings.WaitForSelectorTimeout;
import io.appium.uiautomator2.server.WDStatus;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
Expand Down Expand Up @@ -102,6 +102,26 @@ public void shouldBeAbleToReturnWaitForIdleTimeoutSetting() throws Instantiation
verifySettingIsAvailable(WaitForIdleTimeout.SETTING_NAME, WaitForIdleTimeout.class);
}

@Test
public void shouldBeAbleToReturnWaitForSelectorTimeoutSetting() throws InstantiationException, IllegalAccessException {
verifySettingIsAvailable(WaitForSelectorTimeout.SETTING_NAME, WaitForSelectorTimeout.class);
}

@Test
public void shouldBeAbleToReturnActionAcknowledgmentTimeout() throws InstantiationException, IllegalAccessException {
verifySettingIsAvailable(ActionAcknowledgmentTimeout.SETTING_NAME, ActionAcknowledgmentTimeout.class);
}

@Test
public void shouldBeAbleToReturnKeyInjectionDelay() throws InstantiationException, IllegalAccessException {
verifySettingIsAvailable(KeyInjectionDelay.SETTING_NAME, KeyInjectionDelay.class);
}

@Test
public void shouldBeAbleToReturnScrollAcknowledgmentTimeout() throws InstantiationException, IllegalAccessException {
verifySettingIsAvailable(ScrollAcknowledgmentTimeout.SETTING_NAME, ScrollAcknowledgmentTimeout.class);
}

@Test
public void shouldBeAbleToReturnElementResponseFieldsSetting() throws InstantiationException, IllegalAccessException {
verifySettingIsAvailable(ElementResponseFields.SETTING_NAME, ElementResponseFields.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.uiautomator2.model.settings;

import android.support.test.uiautomator.Configurator;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Configurator.class})
public class ActionAcknowledgmentTimeoutTests {

private ActionAcknowledgmentTimeout actionAcknowledgmentTimeout;

@Mock
private Configurator configurator;

@Before
public void setup() {
actionAcknowledgmentTimeout = new ActionAcknowledgmentTimeout();
PowerMockito.mockStatic(Configurator.class);
when(Configurator.getInstance()).thenReturn(configurator);
when(configurator.setActionAcknowledgmentTimeout(anyLong())).thenReturn(configurator);
}

@Test
public void shouldBeInteger() {
Assert.assertEquals(Integer.class, actionAcknowledgmentTimeout.getValueType());
}

@Test
public void shouldReturnValidSettingName() {
Assert.assertEquals("actionAcknowledgmentTimeout", actionAcknowledgmentTimeout.getSettingName());
}

@Test
public void shouldBeAbleToSetIdleTimeout() {
actionAcknowledgmentTimeout.updateSetting(123);
verify(configurator).setActionAcknowledgmentTimeout(123);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.uiautomator2.model.settings;

import android.support.test.uiautomator.Configurator;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Configurator.class})
public class KeyInjectionDelayTests {

private KeyInjectionDelay keyInjectionDelay;

@Mock
private Configurator configurator;

@Before
public void setup() {
keyInjectionDelay = new KeyInjectionDelay();
PowerMockito.mockStatic(Configurator.class);
when(Configurator.getInstance()).thenReturn(configurator);
when(configurator.setKeyInjectionDelay(anyLong())).thenReturn(configurator);
}

@Test
public void shouldBeInteger() {
Assert.assertEquals(Integer.class, keyInjectionDelay.getValueType());
}

@Test
public void shouldReturnValidSettingName() {
Assert.assertEquals("keyInjectionDelay", keyInjectionDelay.getSettingName());
}

@Test
public void shouldBeAbleToSetIdleTimeout() {
keyInjectionDelay.updateSetting(123);
verify(configurator).setKeyInjectionDelay(123);
}
}
Loading