我想添加嘗試和捕獲異常到我的代碼,但不知道在哪裏把它放到我的代碼中。有人可以請幫忙。 Java新手。我知道,有一個嘗試,你需要抓住。如果任何人都可以得到任何好的幫助。如果你需要任何進一步的細節,讓我知道:)嘗試和捕獲異常處理
我也用頁面對象建模來寫我的代碼也。
package com.gms;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import NGP_IOS_Test.AttractionTab;
import NGP_IOS_Test.MyAlbum;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
public class pages {
AppiumDriver driver;
public AppiumDriverLocalService service;
@BeforeTest
public void AttractionsPage() throws IOException, InterruptedException,
MalformedURLException
{
service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new
File("/usr/local/Cellar/node/8.2.1/bin/node"))
.withAppiumJS(new
File("/Applications/Appium.app/Contents/Resources/app/node_modules
/appium/build/lib/main.js")));
service.start();
Thread.sleep(5000);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.BROWSER_NAME, "safari");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.3");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 7 Plus");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 7 Plus");
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@Test
public void RunTest() throws InterruptedException {
driver.get("http://gms-picsolve-qa.ngpdev.com");
AttractionTab attraction=new AttractionTab(driver);
//click a photo
attraction.clickphoto();
Thread.sleep(3000);
//click thats me on preview
attraction.clickpreview();
Thread.sleep(3000);
//click no on facial detection
attraction.clickFDS();
Thread.sleep(3000);
MyAlbum album=new MyAlbum(driver);
album.clickalbum();
Thread.sleep(3000);
album.photoassiston();
Thread.sleep(3000);
album.exitselfie();
}
@AfterTest
public void afterTest() {
driver.quit();
service.stop();
}
}
「Java新手」。 - 在這種情況下,您可能需要首先了解基礎(而異常處理就是其中之一),然後再深入到更復雜的主題中。您一次採取多個步驟,最終容易摔倒。 – Thomas
*我知道,有一個嘗試,你需要抓住。*從技術上講,不。但是,如果你試圖實現錯誤處理,你爲什麼還要考慮跳過catch? – shmosel
你試圖抓住什麼錯誤? –