I am experimenting on writing test automation for mobile app, and after going through numerous incompatibility issues, I thought I have sorted it out. However, this is not the case as I encounter this seemingly innocent yet devastating issue.
test class code
package com.example.test;
import io.appium.java_client.android.AndroidDriver;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Instrumented test, which will execute on an Android device.
*
* #see Testing documentation
*/
//#RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
private AndroidDriver driver;
#Before
public void setup() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "emulator-5444");
capabilities.setCapability("platFormName","Android");
capabilities.setCapability("appPackage","com.mol.molwallet.uat");
capabilities.setCapability("appActivity","com.mol.molwallet.start.SplashActivity");
capabilities.setCapability("noReset","true");
driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"),capabilities);
}
#Test
public void myFirstTest() {
// Context of the app under test.
driver.findElement(By.xpath("//*[#text='LOG IN']")).click();
//assertEquals("com.example.test", appContext.getPackageName());
}
}
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
//implementation 'com.android.support:appcompat-v7:29+'
//noinspection GradleDependency
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'androidx.annotation:annotation:1.1.0'
//androidTestImplementation 'com.android.support.test:runner:1.0.2'
//androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//androidTestImplementation 'com.android.support:support-annotations:24.0.0'
//implementation("com.android.support:support-v4:27.1.1")
//implementation project(':react-native-fast-image')
}
if(hasProperty('buildScan')){
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service';
termsOfServiceAgree = 'yes'
}
}
After executing, the result is as follow:
For the execution process, kindly refer to the video link
Why is it prompting "Class not found" error when I am actually executing from the said class ?
I had these kind of issues a lot. For me, the simplest way to fix it was to create tests by opening the class that needs testing and pressing Ctr+Shift+t(Windows) or Cmd+Shift+t(Mac). After that I press the "Create new test" option. This creates the test file where Android Studio wants it and everything is fine.
Related
When I try to use Configuration class android studio says "Cannot resolve symbol 'Configuration'". How can I use Configuration class appropriately?
Here is the class:
package android.example.com;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.runner.RunWith;
#RunWith(AndroidJUnit4.class)
public class ActivityInputOutputTest {
#Before
public void setup() {
Configuration config;
}
}
And Here's the build.gradle (Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "android.example.com"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation "androidx.work:work-testing:2.2.0"
// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'
// Optional -- Robolectric environment
testImplementation 'androidx.test:core:1.0.0'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:1.10.19'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compileOnly 'com.jakewharton.espresso:espresso:1.1-r2'
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r2') {
exclude group: 'com.squareup.dagger'
}
}
Add the following in your build.gradle
implementation "androidx.work:work-runtime:2.2.0"
I am sure there has been many posts about Gradle sync issue in INtelliJ, but usually with various types of errors.
I am trying to run a test automation on mobile app, but keep encountering the issues as follow, despite upgrading all possible libraries base on advices given by fellow StackOverflower.
Main code:
import io.appium.java_client.android.AndroidDriver;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Instrumented test, which will execute on an Android device.
*
* #see Testing documentation
*/
//#RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
private AndroidDriver driver;
#Before
public void setup() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "emulator-5444");
capabilities.setCapability("platFormName","Android");
capabilities.setCapability("appPackage","com.mol.molwallet.uat");
capabilities.setCapability("appActivity","com.mol.molwallet.start.SplashActivity");
capabilities.setCapability("noReset","true");
driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"),capabilities);
}
#Test
public void myFirstTest() {
// Context of the app under test.
driver.findElement(By.xpath("//*[#text='LOG IN']")).click();
//assertEquals("com.example.test", appContext.getPackageName());
}
}
App/build.gradle
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
noinspection GradleCompatible
//implementation 'com.android.support:appcompat-v7:29+'
implementation 'androidx.appcompat.appcompat:1.0.0'
//implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'androidx.annotation:annotation:1.1.0'
//androidTestImplementation 'com.android.support.test:runner:1.0.2'
//androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//androidTestImplementation 'com.android.support:support-annotations:24.0.0'
//implementation("com.android.support:support-v4:27.1.1")
implementation project(':react-native-fast-image')
}
if(hasProperty('buildScan')){
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service';
termsOfServiceAgree = 'yes'
}
}
And the error message is as follow when I try to run the main code
Hope to have advice on this issue which has been bugging me.
try this
//noinspection GradleCompatible
Hi there stackoverflow community, hope you can help!
Im using udacity to learn android development and I have ran into a problem. there are a few errors that have come up:
error: package android.v7.app does not exist
error: cannot find symbol class AppCompatActivity
error: method does not override or implement a method from a supertype
error: cannot find symbol variable super
error: cannot find symbol method setContentView(int)
error: cannot find symbol class openNumbersList
error: cannot find symbol method startActivity(Intent)
Everything was working fine but I was following a tutorial and noticed that my imports in my Main Activity didn't match with what was on the tutorial so I changed:
"import..."
to
import android.v7.app.AppCompatActivity;
import android.os.Bundle;
also even before this, "AppCompatActivity" was in red:
public class MainActivity extends AppCompatActivity {
Main Activity:
package com.example.android.miwok;
import android.content.Intent;
import android.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
}
public void openNumbersList(View view){
Intent i = new Intent(this, openNumbersList.class);
startActivity(i);
}
}
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:23.3.0'
implementation 'com.android.support:support-v4:23.3.0'
implementation 'com.android.support:design:23.3.0'
}
hope this helps.
Try your gradle as follow
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
I think that above code solve your issue
Anyone who faces this problem has to revise the coding of padding and alignment attributes.
The fault is simple.
All you have to do is to be careful with the attributes specifying.
This question already has answers here:
setsupportactionbar() throws error
(6 answers)
Closed 4 years ago.
I use Android studio 3.1.2. I get this error message. How can I solve this Issue?
error: cannot find symbol this.setSupportActionBar(toolbar);
My App build.gradle
apply plugin: 'com.android.application'
compileSdkVersion 27
buildToolsVersion '28.0.0 rc1'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.XXXX.XXXX"
manifestPlaceholders = [onesignal_app_id : "9dfhdfg-art455-3455-8dfgh45-fghe345340fh45",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "REMOTE"]
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
flavorDimensions "default"
productFlavors {
dev {
// Enable pre-dexing to produce an APK that can be tested on
// Android 5.0+ without the time-consuming DEX build processes.
dimension "default"
}
prod {
// The actual minSdkVersion for the production version.
minSdkVersion 16
dimension "default"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.android.support:support-core-utils:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'it.neokree:MaterialTabs:0.11'
implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation files('libs/picasso-2.4.0.jar')
implementation 'de.hdodenhof:circleimageview:1.3.0'
implementation 'com.onesignal:OneSignal:3.+#aar'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.android.gms:play-services-analytics:15.0.0'
implementation 'com.android.support:gridlayout-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
}
apply plugin: 'com.google.gms.google-services'
My error Java Page:
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
public class CategoryItem extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.category_item_grid);
toolbar = (Toolbar) this.findViewById(R.id.toolbar);
toolbar.setTitle(Constant.CATEGORY_TITLE);
this.setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
It also shows this error message:
Can not solve methed 'setSupportAcationBar'import
android.support.v7.widget.Toolbar;
How can i solve it?. What is the slovuation?. anyoney one
Use AppCompatActivity instead of ActionBarActivity
I started a new project on Android Studio, targeting API 26, and did nothing but to add the following line:
import android.util.MathUtils;
and got the error: Cannot resolve symbol MathUtils
Here's my MainActivity.java:
package com.example.HeyJude.test2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.MathUtils;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
And my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.HeyJude.test2"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
I tried using File > Invalidate Caches (with restart), but it didn't help. Any other ideas?
If you search for it, did you mean this?
android.support.v4.math.MathUtils