2016-08-02 50 views
0
package testgoogleapp; 

import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.concurrent.TimeUnit; 
import io.appium.java_client.ios.IOSDriver; 
import org.openqa.selenium.By; 
import org.openqa.selenium.Keys; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.remote.CapabilityType; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.testng.annotations.Test; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.AfterTest; 

/** 
A test to demonstrate the automation on Safari browser using Appium [the open source tool] 
*/ 
public class NewTest { 
WebDriver wd; 

@BeforeTest 
public void beforeTest() throws MalformedURLException { //set capabilities required 
    DesiredCapabilities capabilities = new DesiredCapabilities(); 
    capabilities.setCapability("deviceName", "iPhone 6"); 
    capabilities.setCapability("platformName", "iOS"); 
    capabilities.setCapability("platformVersion", "8.1"); 
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari"); 
    wd = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);//instantiate driver 
    wd.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 
} 

@Test 
public void testSearchPage() throws InterruptedException { 
    wd.get("https://www.google.co.in"); 
    WebElement serachField = wd.findElement(By.name("q")); 
    serachField.sendKeys("Pooja Shah Selenium youtube"); 
    serachField.sendKeys(Keys.ENTER); 
    System.out.println(wd.getCurrentUrl()); 
} 

@AfterTest 
public void afterTest() { 
    //wd.close(); 
} 
} 

這給下面的輸出:失敗配置:@BeforeTest beforeTest上運行該代碼TestNG的

[TestNG] Running: 
    /private/var/folders/j1/tsq8g74x0730d7523hmm5rch0000gn/T/testng-eclipse-2007236291/testng-customsuite.xml 

[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/Default suite/Default test.xml 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/Default suite exists: true 
FAILED CONFIGURATION: @BeforeTest beforeTest 
java.lang.NoSuchMethodError: io.appium.java_client.ios.IOSDriver.substituteMobilePlatform(Lorg/openqa/selenium/Capabilities;Ljava/lang/String;)Lorg/openqa/selenium/Capabilities; 
    at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:37) 
    at testgoogleapp.NewTest.beforeTest(NewTest.java:30) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100) 
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143) 
    at org.testng.TestRunner.beforeRun(TestRunner.java:624) 
    at org.testng.TestRunner.run(TestRunner.java:592) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:268) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1189) 
    at org.testng.TestNG.runSuites(TestNG.java:1104) 
    at org.testng.TestNG.run(TestNG.java:1076) 
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126) 
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152) 
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57) 

SKIPPED CONFIGURATION: @AfterTest afterTest 
SKIPPED: testSearchPage 

=============================================== 
    Default test 
    Tests run: 1, Failures: 0, Skips: 1 
    Configuration Failures: 1, Skips: 1 
=============================================== 


=============================================== 
Default suite 
Total tests run: 1, Failures: 0, Skips: 1 
Configuration Failures: 1, Skips: 1 
=============================================== 

[TestNG] Time taken by [email protected]: 49 ms 
[TestNG] Time taken by [email protected]: 13 ms 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/junitreports/TEST-testgoogleapp.NewTest.xml 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/junitreports exists: true 
[TestNG] Time taken by [email protected]: 4 ms 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/testng-failed.xml 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/Default suite/testng-failed.xml 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/Default suite exists: true 
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/toc.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/Default test.properties 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/index.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/main.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/groups.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/classes.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/reporter-output.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/methods-not-run.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite/testng.xml.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/Default suite exists: true 
[Utils] Attempting to create /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old/index.html 
[Utils] Directory /Users/akifhazarvi/Documents/workspace/testgoogleapp/test-output/old exists: true 
[TestNG] Time taken by [email protected]: 15 ms 
[TestNG] Time taken by [email protected]: 6 ms 

回答

0

首先,你可以通過它們的常量替換字符串:MobileCapabilityType.PLATFORM_NAME/PLATFORM_VERSION/DEVICE_NAME

然後,您的類路徑中必須至少包含Appium 2.0(以及更低版本)。

相關問題