{"id":798,"date":"2023-02-28T11:31:28","date_gmt":"2023-02-28T03:31:28","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=798"},"modified":"2023-04-05T17:43:19","modified_gmt":"2023-04-05T09:43:19","slug":"appium-java-client-get-phone-model","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/28\/appium-java-client-get-phone-model\/","title":{"rendered":"Appium java-client\u83b7\u53d6\u624b\u673a\u578b\u53f7"},"content":{"rendered":"<p>Appium java-client\u83b7\u53d6\u624b\u673a\u578b\u53f7<\/p>\n<p>\u6d4b\u8bd5\u5e73\u53f0\uff1a\u7ea2\u7c73 Note 4X<br \/>\n\u64cd\u4f5c\u7cfb\u7edf\uff1aAndroid 7.0<\/p>\n<p><!-- more --><\/p>\n<p>AppiumTest.java<\/p>\n<pre><code class=\"language-java\">import io.appium.java_client.android.AndroidDriver;\nimport io.appium.java_client.android.AndroidElement;\nimport org.openqa.selenium.remote.DesiredCapabilities;\nimport org.testng.annotations.AfterTest;\nimport org.testng.annotations.BeforeTest;\nimport java.net.URL;\n\nimport java.net.MalformedURLException;\n\npublic class AppiumTest {\n    protected AndroidDriver&lt;AndroidElement&gt; driver = null;\n\n    \/** \u7528\u4f8b\u662f\u5426\u6267\u884c\u6210\u529f\u6807\u8bc6 *\/\n    public boolean isPassed = false;\n\n    \/** \u8bbe\u5907\u7684deviceName *\/\n    private final String DEVICE_NAME = &quot;Redmi Note 4X&quot;;\n\n    private final String URL = &quot;http:\/\/127.0.0.1:4723\/wd\/hub&quot;;\n\n    @BeforeTest\n    public void beforeTest() throws MalformedURLException {\n        DesiredCapabilities capabilities = new DesiredCapabilities();\n        capabilities.setCapability(&quot;automationName&quot;, &quot;Appium&quot;);\n        capabilities.setCapability(&quot;platformName&quot;, &quot;Android&quot;);\n        capabilities.setCapability(&quot;deviceName&quot;, DEVICE_NAME);\n        \/\/ capabilities.setCapability(&quot;appPackage&quot;,&quot;com.miui.home&quot;);\n        \/\/ capabilities.setCapability(&quot;appActivity&quot;,&quot;.launcher.Launcher&quot;);\n        capabilities.setCapability(&quot;appPackage&quot;,&quot;com.android.settings&quot;);\n        capabilities.setCapability(&quot;appActivity&quot;,&quot;.Settings&quot;);\n        capabilities.setCapability(&quot;newCommandTimeout&quot;, 5000);\n        driver = new AndroidDriver&lt;AndroidElement&gt;(new URL(URL), capabilities);\n    }\n\n    @AfterTest\n    public void AfterTest() {\n        driver.quit();\n    }\n}<\/code><\/pre>\n<p>SettingsTest.java<\/p>\n<pre><code>import io.appium.java_client.android.AndroidKeyCode;\nimport org.openqa.selenium.By;\nimport org.testng.annotations.Test;\n\npublic class SettingsTest extends AppiumTest {\n\n    @Test\n    public void testDeviceInfo() throws InterruptedException {\n        \/\/driver.findElementByXPath(&quot;\/\/android.widget.TextView[@text=&#039;\u6211\u7684\u8bbe\u5907&#039;]&quot;).click();  \/\/\u9519\u8bef\n        \/\/driver.findElementByXPath(&quot;\/\/android.widget.TextView[contains(@text, \u6211\u7684\u8bbe\u5907)]&quot;).click();\n        \/\/driver.findElement(By.xpath(&quot;\/\/android.widget.TextView[contains(@text, \u6211\u7684\u8bbe\u5907)]&quot;)).click();\n        driver.findElement(By.xpath(&quot;\/\/android.widget.ListView\/android.widget.LinearLayout[contains(@index, 1)]&quot;)).click();\n        Thread.sleep(1000);\n        \/\/String deviceName = driver.findElementByXPath(&quot;\/\/android.widget.ListView\/android.widget.LinearLayout[0]\/android.widget.TextView&quot;).getText();  \/\/\u9519\u8bef\n        String deviceName = driver.findElementByXPath(&quot;\/\/android.widget.ListView\/android.widget.LinearLayout[contains(@index, 0)]\/android.widget.TextView&quot;).getText();\n        System.out.print(&quot;Device Name: &quot; + deviceName);\n        driver.pressKeyCode(AndroidKeyCode.KEYCODE_HOME);\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Appium java-client\u83b7\u53d6\u624b\u673a\u578b\u53f7 \u6d4b\u8bd5\u5e73\u53f0\uff1a\u7ea2\u7c73 Note 4X \u64cd\u4f5c\u7cfb\u7edf\uff1aAndroid 7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[223],"tags":[],"class_list":["post-798","post","type-post","status-publish","format-standard","hentry","category-appium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=798"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/798\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}