Java – Android testing using appium and gradle
•
Java
I recently started to think about doing some functional tests with appium I want to run appium test through Android studio and gradle
Has anyone tried to do this? If you can, you can give me some information about the settings, such as what kind of tasks to use, etc
I included the necessary dependencies in the build file:
I have an example test below. I only need one way to run through gradle:)
package com.appium.trial; import junit.framework.Assert; import io.appium.java_client.AppiumDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; public class TrialTest { private static WebDriver wd; @Before public void setUp() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("appium-version","1.0"); capabilities.setCapability("platformName","Android"); capabilities.setCapability("platformVersion","4.4"); capabilities.setCapability("deviceName","Samsung Galaxy S4 - 4.2.2 - API 17 - 1080x1920"); capabilities.setCapability("app","/Users/chuckster/Documents/Dev/AppiumTrial/appium-trial.apk"); capabilities.setCapability("appPackage","com.appium.trial"); capabilities.setCapability("appActivity","com.appium.trial.TrialTest"); try { wd = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"),capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } wd.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS); } @Test public static void testThatClickingTheMotorSectionLeadsToSubSection(){ wd.findElement(By.xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[5]/android.widget.TextView[1]")).click(); wd.close(); } @After public void tearDown() { if (wd != null) { wd.quit(); } } }
Solution
Running it on the command line should look at a class called trialtest of all the classes in the project and run only those tests
gradle -Dtest.single=TrialTest
You must have a graduate called a test Make sure your build This is in the gradle file
test { testLogging{ events 'started','passed' } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码