Skip to content

Commit

Permalink
Avoid NPE on getting session details (appium#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored and rajdeepv committed Feb 15, 2019
1 parent 81df291 commit 9a4fbd1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.handler;

import org.json.JSONException;
Expand All @@ -20,12 +36,12 @@ public GetSessionDetails(String mappedUri) {
protected AppiumResponse safeHandle(IHttpRequest request) throws JSONException {
Session session = AppiumUiAutomatorDriver.getInstance().getSession();
JSONObject result = new JSONObject();
AccessibilityScrollData scrollData = session.getLastScrollData();
JSONObject lastScrollData = null;
if (scrollData != null) {
lastScrollData = new JSONObject(scrollData.getAsMap());
if (session != null) {
AccessibilityScrollData scrollData = session.getLastScrollData();
if (scrollData != null) {
result.put("lastScrollData", new JSONObject(scrollData.getAsMap()));
}
}
result.put("lastScrollData", lastScrollData);
return new AppiumResponse(getSessionId(request), WDStatus.SUCCESS, result);
}
}
17 changes: 16 additions & 1 deletion app/src/main/java/io/appium/uiautomator2/handler/NewSession.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package io.appium.uiautomator2.handler;
/*
* 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.handler;

import org.json.JSONException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package io.appium.uiautomator2.model;
/*
* 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;

import java.util.UUID;

import androidx.annotation.Nullable;

public class AppiumUiAutomatorDriver {

Expand All @@ -20,7 +36,6 @@ public static synchronized AppiumUiAutomatorDriver getInstance() {
}

public String initializeSession() {

if (this.session != null) {
session.getKnownElements().clear();
return session.getSessionId();
Expand All @@ -29,6 +44,7 @@ public String initializeSession() {
return session.getSessionId();
}

@Nullable
public Session getSession() {
return session;
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/io/appium/uiautomator2/model/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import androidx.annotation.Nullable;

import static io.appium.uiautomator2.model.settings.Settings.ELEMENT_RESPONSE_ATTRIBUTES;
import static io.appium.uiautomator2.model.settings.Settings.SHOULD_USE_COMPACT_RESPONSES;

Expand Down Expand Up @@ -63,6 +65,7 @@ public JSONObject getCommandConfiguration(String command) {
return commandConfiguration.get(command);
}

@Nullable
public AccessibilityScrollData getLastScrollData() {
return lastScrollData;
}
Expand Down

0 comments on commit 9a4fbd1

Please sign in to comment.