forked from github/cordova-android
Adding the WebDriver Tests
This commit is contained in:
parent
cdaf620f92
commit
dbe65f1d35
78
test/src/org/apache/cordova/test/CordovaDriverAction.java
Normal file
78
test/src/org/apache/cordova/test/CordovaDriverAction.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. 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 org.apache.cordova.test;
|
||||||
|
|
||||||
|
import org.apache.cordova.api.CordovaInterface;
|
||||||
|
import org.apache.cordova.api.IPlugin;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
|
||||||
|
public class CordovaDriverAction extends Activity implements CordovaInterface {
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindBackButton(boolean arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelLoadUrl() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity getActivity() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBackButtonBound() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object onMessage(String arg0, Object arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setActivityResultCallback(IPlugin arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startActivityForResult(IPlugin arg0, Intent arg1, int arg2) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
37
test/src/org/apache/cordova/test/CordovaViewFactory.java
Normal file
37
test/src/org/apache/cordova/test/CordovaViewFactory.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. 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 org.apache.cordova.test;
|
||||||
|
|
||||||
|
import org.openqa.selenium.android.library.ViewAdapter;
|
||||||
|
import org.openqa.selenium.android.library.ViewFactory;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
public class CordovaViewFactory implements ViewFactory {
|
||||||
|
|
||||||
|
public ViewAdapter createNewView(Activity arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return new ViewAdapter("org.apache.cordova.CordovaWebView", new CordovaWebView(arg0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
90
test/src/org/apache/cordova/test/WebDriverTest.java
Normal file
90
test/src/org/apache/cordova/test/WebDriverTest.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. 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 org.apache.cordova.test;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebViewClient;
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
|
import org.apache.cordova.CordovaChromeClient;
|
||||||
|
|
||||||
|
import org.apache.cordova.test.CordovaViewFactory;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.android.library.AndroidWebDriver;
|
||||||
|
import org.openqa.selenium.android.library.ChromeClientWrapper;
|
||||||
|
import org.openqa.selenium.android.library.ViewClientWrapper;
|
||||||
|
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
|
||||||
|
public class WebDriverTest extends ActivityInstrumentationTestCase2<CordovaDriverAction> {
|
||||||
|
|
||||||
|
private static final long TIMEOUT = 5000;
|
||||||
|
private CordovaDriverAction testActivity;
|
||||||
|
private CordovaWebView testView;
|
||||||
|
private CordovaViewFactory viewFactory;
|
||||||
|
private CordovaChromeClient appCode;
|
||||||
|
private CordovaWebViewClient viewHandler;
|
||||||
|
private AndroidWebDriver testDriver;
|
||||||
|
private ViewClientWrapper viewClientWrapper;
|
||||||
|
private ChromeClientWrapper chromeClientWrapper;
|
||||||
|
|
||||||
|
public WebDriverTest() {
|
||||||
|
super("com.phonegap.test.activities",CordovaDriverAction.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUp() throws Exception{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
testActivity = this.getActivity();
|
||||||
|
viewFactory = new CordovaViewFactory();
|
||||||
|
appCode = new CordovaChromeClient(testActivity);
|
||||||
|
viewHandler = new CordovaWebViewClient(testActivity);
|
||||||
|
viewClientWrapper = new ViewClientWrapper("org.apache.cordova.CordovaWebViewClient", viewHandler);
|
||||||
|
chromeClientWrapper = new ChromeClientWrapper("org.apache.cordova.CordovaChromeClient", appCode);
|
||||||
|
testDriver = new AndroidWebDriver(testActivity, viewFactory, viewClientWrapper, chromeClientWrapper);
|
||||||
|
testView = (CordovaWebView) testDriver.getWebView();
|
||||||
|
viewHandler.setWebView(testView);
|
||||||
|
appCode.setWebView(testView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPreconditions(){
|
||||||
|
assertNotNull(testView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWebLoad() {
|
||||||
|
testDriver.get("file:///android_asset/www/index.html");
|
||||||
|
sleep();
|
||||||
|
String url = testView.getUrl();
|
||||||
|
//Check the sanity!
|
||||||
|
boolean result = url.equals("file:///android_asset/www/index.html");
|
||||||
|
assertTrue(result);
|
||||||
|
WebElement platformSpan = testDriver.findElement(By.id("platform"));
|
||||||
|
String text = platformSpan.getText();
|
||||||
|
assertTrue(text.equals("Android"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void sleep() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(TIMEOUT);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
fail("Unexpected Timeout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user