AndroidWebDriver class missing in Selenium-Java library - android

I tried a example provided in the, Android app testing through Selenium, i have included the selenium-java library and android-webdriver apk also installed in emulator, but when try with the sample code provide in the forum i got error in AnroidWebDriver import, in selenium library only AndroidDriver class is available, so where could i get the AdroidWebDriver jar. Plz assit.
Note: Selenium library is very latest one.
import android.test.ActivityInstrumentationTestCase2;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidWebDriver;
import simple.app.SimpleAppActivity;
public class SimpleGoogleTest extends ActivityInstrumentationTestCase2<SimpleAppActivity> {
private WebDriver driver;
private WebDriver googledriver;
public SimpleGoogleTest() {
super("simple.app", SimpleAppActivity.class);
}
#Override
protected void setUp() throws Exception {
driver = new AndroidWebDriver(getActivity());
}
........................,,,,,
}

There are two variations of the Android Driver:
AndroidDriver() which you use on your Personal Computer e.g. your
laptop, workstation, etc. which provides the richest and most
complete set of capabilities for your tests.
AndroidWebDriver() which runs on your Android device, this wraps a WebView component to provide the basic core functionality.
The example code that comes with the Android SDK and the optional support for Selenium/WebDriver runs some basic tests on the device. The tests are compiled as an Android program which extend ActivityInstrumentationTestCase2. AndroidWebDriver() is contained in sdk/extras/google/webdriver/android_webdriver_library.jar (and the Javadocs are in sdk/extras/google/webdriver/android_webdriver_library-srcs.jar
So, if you want to run your tests on your Android device, then you need to include android-webdriver-library.jar in your project. Perhaps the simplest way is to copy this jar into your test project's libs folder.
However, if you would like to run your tests on your Personal Computer you can modify the example code to use AndroidDriver instead of AndroidWebDriver. You also need to change your base class e.g. to use Junit 3 or Junit 4. I have posted a sample test as an answer to another question on Stack Overflow here Having difficulty in finding Elements using Xpath and CSS in Selenium Android Webdriver Testing

Related

Access methods from .jar file in react native

I am trying to connect postek EM 210 Bluetooth printer using my react native mobile app. I have SDK/ .jar file but need help for implementing its methods in react native
Postek has provided android SDK for use in android studio. Since my project is in react-native, I have included the .jar file in my project but have no clue how to use this file in react-native and access methods and functions that are available inside .jar file.
package com.postek.coyote.cdfptkbluetooth;
..
..
import com.postek.cdf.CDFPTKAndroid;
import com.postek.cdf.CDFPTKAndroidImpl;
public class BluetoothActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
...
public static CDFPTKAndroid cdf = null;
...
}
So how do I convert these lines to react-native -
import com.postek.cdf.CDFPTKAndroid;
import com.postek.cdf.CDFPTKAndroidImpl;
..
public static CDFPTKAndroid cdf = null;
Alternatively, I want develop same app (using same SDK) with Bluetooth as here but in react-native.
Side note - We will even make react-native version of this app available on git for other developer who may be looking for this.

how to use Instrumentation under the uiautomator project?

I'm working on a uiautomator project recently and then the UiObject.getFromParent turn out a wrong element to me and I look into the source code of uiautomator and found out the answer is because by the UiSelector I used.
I found that the uiautomator is using the Instrumentation to get the UI element stuff just like :
getInstrumentation().getUiAutomation().getRootInActiveWindow();
I just want to get a AccessibilityNodeInfo node just like what uiautomator do but the uiautomator didn't exposed this.
I’m trying this way by a new class extends InstrumentationTestCase,by the getInstrumentation() always return a null to me.
i found an answer on
android instrumentation test case - getinstrumentation() returning null
that needs injectInstrumentation(InstrumentationRegistry.getInstrumentation());
and told InstrumentationRegistry is from the official Android testing-support-lib:0.1
I have download the Android Support Repository and import the testing-support-lib-0.1-source.jar into my project but I still can't see InstrumentationRegistry.
Anyone have any idea about my cast?
I'm using an extension of InstrumentationTestCase and it works just fine like this:
#Override
public void setUp() throws Exception{
super.setUp();
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
AccessibilityNodeInfo root = instrumentation.getUiAutomation().getRootInActiveWindow();
}
I imported
import android.test.InstrumentationTestCase;
import android.support.test.InstrumentationRegistry;
import android.view.accessibility.AccessibilityNodeInfo;
and installed
Android Support Repository (15)
Android Support Library (22.2)
Hope it helps.
well,this question has beep solved by
unpack testing-support-lib-0.1.aar and get the classes.jar instead of
testing-support-lib-0.1-source.jar
.and now the eclipse will not saying can't resolved anymore.By the way,u have to
add this lib to Ant's javac classpath by edit build.xml
or else u will get a lib not found while u trying ant build.
but now the NEW question has turns out
INSTRUMENTATION_STATUS: stack=java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/test/InstrumentationRegistry;
maybe it's another question so i am going to find out via google and i will update this if figure it out or i will post a new question.
Frist tried:
i have noticed that the point of this question is the uiautomator didn't expose the api i want,and when i look into the source and found the UiDevice.dumpWindowHierarchy that has these code:
AccessibilityNodeInfo root =getAutomatorBridge().getQueryController().getAccessibilityRootNode();
the getAutomatorBridge was implemented by UiDevice:
UiAutomatorBridge getAutomatorBridge() {
if (mUiAutomationBridge == null) {
throw new RuntimeException("UiDevice not initialized");
}
return mUiAutomationBridge;
}
the point is there is no modifier on it,so what i have done is modified it's modifier to public ,modified the byte code of
/system/framework/uiautomator.jar
and the other one in sdk(sorry i don't,ya it worked!i can use it like this.
AccessibilityNodeInfo root =getUidevice().getAutomatorBridge().getQueryController().getAccessibilityRootNode();
but there is a compatibility issue isn't it?
Second tried:
Let's think about the default modifier of java,we can access it under the same package,so why don't we just implement a class has the same Package name ?then we can call it without any unnomal patch.
that's what i have done and it really works well:
package com.android.uiautomator.core;
import android.view.Display;
import android.view.accessibility.AccessibilityNodeInfo;
public class AutomationUltilites
{
public AutomationUltilites()
{
}
public static AccessibilityNodeInfo getRootNode()
{
return UiDevice.getInstance().getAutomatorBridge().getRootInActiveWindow();
}
public static Display getDisplay()
{
return UiDevice.getInstance().getAutomatorBridge().getDefaultDisplay();
}
}
Hope it helps.

Android Testing with Robolectric: not recognizing Facebook SDK

We are trying to use the Robolectric testing framework in Android Studio in order to test the Facebook API. The Facebook Login button works so the Facebook API is working. However, the following test fails:
package com.airportapp.test.Models;
import android.app.Activity;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.Robolectric;
import com.airportapp.test.MyRobolectricTestRunner;
import com.airportapp.LoginActivity;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
#RunWith(MyRobolectricTestRunner.class)
public class LoginActivityTest {
#Before
public void setup() {
//do whatever is necessary before every test
}
#Test
public void testActivityFound() {
Activity activity = Robolectric.buildActivity(LoginActivity.class).create().get();
Assert.assertNotNull(activity);
}
}
And the error is that Android Studio could not find the android.support file when we run the tests. You can see the error here:
The other error that shows up is:
android.view.InflateException: XML file app/src/main/res/layout/activity_login.xml line #-1 (sorry, not yet implemented): Error inflating class com.facebook.widget.LoginButton
So Android Studio is not happy with the facebook login button as well :( But it works... We think that we need to import something, but we don't know where to put it.
The InflateException is because Robolectric cannot find the resources from the Facebook SDK. To solve this, the project.properties file has to be updated to point to the Facebook SDK project. Do this by adding the following line to it:
android.library.reference.1={Path}
{Path} should be a relative path, from the project.properties file to the folder containing the AndroidManifest.xml of the Facebook SDK project. In my case that is ../../build/intermediates/exploded-aar/com.facebook.android/facebook/3.21.0.
Note that this works for all Android Library Projects which contain resources that aren't found by Robolectric. Further reading: here and here. Also, more documentation about project.properties can be found here. Note that in my project the Robolectric tests are located in the Android app project itself. So you could also try placing the project.properties file in the same directory as the AndroidManifest.xml used for testing.
As for your first problem; I have no personal experience with it. But it appears to be because Gradle cannot find the support libraries when compiling the unit tests. The answer from this question should fix it.

Run UiAutomator API from Android Studio (v0.8)

When I work with tests - I add class in special module and run test configuration. Class extend (for example) TestCase and work well.
But when I extend UiAutomatorTestCase - I get error
java.lang.RuntimeException: Stub!
at com.android.uiautomator.testrunner.UiAutomatorTestCase.<init> (UiAutomatorTestCase.java:5) ...
My simple class:
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class AutoTest extends UiAutomatorTestCase {
public void testSome() throws UiObjectNotFoundException {
getUiDevice().pressHome();
}
}
How to run it in Android Studio IDE?
Well, if you'd be interested in giving it another try....I was able to get a UIAutomator project started in Android Studio with the following [Github project] (https://github.com/wiliamsouza/bluetooth)
Clone the project locally.
Edit the gradle.properties file to point to your sdk, target and build tools
Import into Android Studio, if prompted be sure to select Gradle.
The accompanying [blog post] (http://wiliamsouza.github.io/#/2013/10/30/android-uiautomator-gradle-build-system) has more details.
I modified with my own test cases and is working well.

How to setup alljoyn sdk in android?

I am trying to setup two android devices to communicate with each other through wifi. Some of the links I have gone through suggest alljoyn sdk in order to accomplish this.
There is an sdk download but there is no documentation for how to setup environment.
Here is how to set up an AllJoyn SDK development environment with android studio:
Download the SDK from this page. Go for Android Core SDK - release (or debug).
Create a new blank android project.
Create directory <project>/app/src/main/jniLibs and <project>/app/src/main/jniLibs/armeabi.
From alljoyn-15.09.00-rel/java/jar copy alljoyn.jar and from alljoyn-15.09.00-rel/java/lib copy liballjoyn_java.so. The directory to copy from might differ depending on the current version and your release/debug choice.
Put alljoyn.jar in /jniLibs and put liballjoyn_java.so in /jniLibs/armeabi. Should look like this
Right click project -> Open Module Settings -> app -> Dependencies.
With the green [+] button, add a file dependency.
Navigate to <project>/app/src/main/jniLibs/alljoyn.jar and select that jar.
This will add a line in your gradle (compile files('src/main/jniLibs/alljoyn.jar')) that will allow for code completion etc.
In the file where you want to use alljoyn code, include this snippet
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
for example:
public class MainActivity extends AppCompatActivity {
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
#Override
public void onCreate(Bundle savedInstanceState) {
...
}
}
You can now use the alljoyn SDK. Import classes with
import org.alljoyn.bus.BusAttachment;
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.BusListener;
etc.
If you're more of an eclipse guy, check this official documentation page on how to setup an eclipse environment.

Categories

Resources