Last active
February 22, 2023 00:05
-
-
Save makolesnik/d1fb3dca2e66146f519f to your computer and use it in GitHub Desktop.
Selenide + Appium for Android Calculator app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import org.openqa.selenium.By; | |
import org.testng.annotations.*; | |
import utilits.TestBase; | |
import static com.codeborne.selenide.Selenide.$; | |
import static com.codeborne.selenide.Condition.text; | |
public class CalculatorTest extends TestBase { | |
@Test | |
public void testCalculator(){ | |
$(By.name("2")).click(); | |
$(By.name("+")).click(); | |
$(By.name("4")).click(); | |
$(By.name("=")).click(); | |
$(By.className("android.widget.EditText")).shouldHave(text("6")); | |
// assert $(By.className("android.widget.EditText")).getText().equals("6"):"Actual value is : "+$(By.className("android.widget.EditText")).getText()+" did not match with expected value: 6"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utilits; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import io.appium.java_client.android.AndroidDriver; | |
import io.appium.java_client.remote.MobileCapabilityType; | |
public class AndroidDriverProvider { | |
public static WebDriver getAndroidDriver() throws MalformedURLException{ | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2"); | |
capabilities.setCapability("automationName", "Appium"); | |
capabilities.setCapability("platformName", "Android"); | |
capabilities.setCapability("deviceName", "0123456789ABCDEF"); | |
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator2"); // This is package name of your app (you can get it from apk info app | |
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app) | |
//Create AndroidDriver instance and connect to the Appium server. | |
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities | |
return new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utilits; | |
import java.net.MalformedURLException; | |
import org.testng.annotations.BeforeSuite; | |
import com.codeborne.selenide.WebDriverRunner; | |
public class TestBase { | |
@BeforeSuite | |
public void initTestSuite() throws MalformedURLException{ | |
WebDriverRunner.setWebDriver(AndroidDriverProvider.getAndroidDriver()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why?
versions: selenide 4.2.1 appium 1.4.16 selenium 2.47 把selenium换成2.53的,跑成功了
FAILED CONFIGURATION: @BeforeSuite initTestSuite
java.lang.NoClassDefFoundError: org/openqa/selenium/NoSuchSessionException
at com.codeborne.selenide.WebDriverRunner.(WebDriverRunner.java:13)
at selenide.TestBase.initTestSuite(TestBase.java:14)