public class screen_detects_ extends Base {
@Test
public void testing() {
try {
page tutorial = new page(driver);
tutorial.skipTutorial(driver);
boardpage v = new boardpage(driver);
v.clickOnDashBoardButton(driver);
v.tapOnSignInAP("jkjk@gmail.com", "tatata");
v.clickOnMyTickets();
vicketsAndasses backbutton = new vicketsAndasses(driver);
backbutton.clickBackButton();
} catch (Exception exp) {
exp.printStackTrace();
}
}
}
base.java //这个类从主要类扩展而来。我从驱动程序或//配置中收到错误。
public class base {
public static final Logger LOGGER = Log.getDefaultLogger();
protected AppiumDriver driver;
protected String platform;
protected String environment;
protected JSONObject jsonConfig;
// @beforemethod(alwaysRun = true)
// @parameters({ "appName", "platform", "platformVersion", "deviceName","seleniumUrl", "environment", "enableEnv", "ticketFutureDate" })
public void setUp(@optional String appName, @optional String platform, @optional String platformVersion, @optional String deviceName, @optional String seleniumUrl, @optional String environment, @optional String enableEnv, @optional String ticketFutureDate, ITestContext ctx, Method method) throws Exception {
if (appName == null || appName.isEmpty() || environment == null || enableEnv == null) {
JSONObject jsonCapabilities = DataProviderHelper.readCapabilities();
appName = jsonCapabilities.getString("appName");
platform = jsonCapabilities.getString("platform");
platformVersion = jsonCapabilities.getString("platformVersion");
deviceName = jsonCapabilities.getString("deviceName");
seleniumUrl = jsonCapabilities.getString("seleniumUrl");
environment = jsonCapabilities.isNull("environment") ? null :
jsonCapabilities.getString("environment");
enableEnv = jsonCapabilities.getString("enableEnv");
ticketFutureDate = jsonCapabilities.getString("ticketFutureDate");
}
this.platform = platform;
this.environment = environment;
System.out.println("********************************************");
System.out.println("appName= " + appName);
System.out.println("platform= " + platform);
System.out.println("platformVersion= " + platformVersion);
System.out.println("deviceName= " + deviceName);
System.out.println("seleniumUrl= " + seleniumUrl);
System.out.println("environment= " + environment);
System.out.println("enableEnv= " + enableEnv);
System.out.println("ticketFutureDate= " + ticketFutureDate);
System.out.println("********************************************");
this.driver = BaseTest.setupDriver(appName, platform, platformVersion, deviceName, seleniumUrl, environment, enableEnv, ticketFutureDate, ctx, method);
//Parse FP object from json
//TestDataHelper.loadTestData(TestDataHelper.ANDROID_JSON_FILE);
}
// @aftermethod(alwaysRun = true)
public void tearDown() {
BaseTest.quitDriver(driver);
}
public JSONObject getGeneralJson() throws JSONException {
String fileName = TestDataHelper.ANDROID_JSON_FILE;
//fileName = fileName.split("\.")[fileName.split("\.").length - 1];
String jsonpath = TestDataHelper.ANDROID_JSON_FILE_LOCATION;
jsonpath = System.getProperty("user.dir") + Constants.DIR_SEPARATOR +
jsonpath;
jsonpath = jsonpath + fileName;
String jsonString = null;
try {
jsonString = DataProviderHelper.readFileAsString(jsonpath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new JSONObject(jsonString);
}
}
控制台测试结果;
08-30 22:23:02.712 [com.disney.appium.scripts.iOS.aprenewals.T1632401_Verify_ap_screen_detects_ap_renewal_eligibility AP_Renewals] Skip Tutorial
**java.lang.NullPointerException**--
(' //错误我不知道如何解决它。我不确定它是否有一个 驱动程序或客户端或配置')
(' io.appium.java_client.pagefactory.AppiumElementLocator。 (AppiumElementLocator.java:72)') 在
io.appium.java_client.pagefactory.AppiumElementLocatorFactory.createLocator(AppiumElementLocatorFactory.java:26)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:65)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:115)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:107)
at com.disney.apps.dlr.pageObjects.iOS.Tutorial.Tutorial_iOSPage.<init>(Tutorial_iOSPage.java:50)
at com.disney.appium.scripts.iOS.aprenewals.T1632401_Verify_ap_screen_detects_ap_renewal_eligibility.AP_Renewals(T1632401_Verify_ap_screen_detects_ap_renewal_eligibility.java:55)
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:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
PASSED: AP_Renewals
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
页面课程
public class Page
{
private AppiumDriver driver;
final private String TUTORIAL_CLOSE = "//XCUIElementTypeButton[@label='Close']";
@iOSFindBy( id = "tutorialPageImage1" )
private MobileElement tutorial_image1;
@iOSFindBy( id = "tutorialPageImage2" )
private MobileElement tutorial_image2;
@iOSFindBy( id = "tutorialPageImage3" )
private MobileElement tutorial_image3;
@iOSFindBy( xpath = TUTORIAL_CLOSE)
private MobileElement tutorial_close;
@iOSFindBy (accessibility = "Get Started")
private MobileElement get_started;
public Page( final AppiumDriver driver )
{
this.driver = driver;
PageFactory.initElements( new AppiumFieldDecorator( driver , AppiumConstants.IMPLICITLY_WAIT_TIMEOUT , TimeUnit.SECONDS ) , this );
}
public boolean verifyTutorialScreen()
{
AutomationTools.waitForElementToLoad( driver , tutorial_image1, 10 );
Assert.assertEquals( true , tutorial_image1.isDisplayed() , "Tutorial screen not found" );
Log.log(driver).info( "Verified Tutorial screen" );
return true;
}
public boolean clickOnDismissScreen()
{
AutomationTools.waitForElementToLoad( driver , tutorial_close, 10 );
tutorial_close.click();
Log.log(driver).info( "Clicked on Dismiss Tutorial" );
return true;
}
public void skipTutorial(AppiumDriver driver) throws Exception
{
try
{
// Verify Tutorial screen displayed
if(verifyTutorialScreenDisplayed()) //pagesource.contains("Close"))
{
// Dismiss the Tutorial screen displayed
iosHelper.clickElementBtn(driver, By.xpath(TUTORIAL_CLOSE), tutorial_close);
//iosHelper.closeScreen(driver);
Log.log(driver).info("Tutorial screen displayed and closed" );
}
else
Log.log(driver).info("Tutorial screen not displayed");
}
catch(Exception e) {
Assert.fail("Unable to dismiss the Tutorial screen: " + e.getMessage());
}
}
public boolean verifyTutorialScreenDisplayed() throws Exception
{
boolean isTutorialDisplayed = false;
try
{
isTutorialDisplayed = iosHelper.verifyElementDisplayed(driver, tutorial_image1);
Log.log(driver).info( "Verified Tutorial screen" );
return isTutorialDisplayed;
}
catch(Exception e) {
Assert.fail("Tutorial screen Image not displayed: " + e.getMessage());
return false;
}
}
public void verifyTutorialPages() throws Exception
{
try
{
Assert.assertTrue(iosHelper.verifyElementDisplayed(driver, tutorial_image1),"");
Log.log(driver).info( "Verified Tutorial screen Page 1" );
iosHelper.swipeElementToUpDirection(driver, tutorial_image2);
Assert.assertTrue(iosHelper.verifyElementDisplayed(driver, tutorial_image2),"");
Log.log(driver).info( "Verified Tutorial screen Page 2" );
iosHelper.swipeElementToUpDirection(driver, tutorial_image3);
Assert.assertTrue(iosHelper.verifyElementDisplayed(driver, tutorial_image3),"");
Log.log(driver).info( "Verified Tutorial screen Page 3" );
// Tap on Get Started button
Log.log(driver).info("Tap on Get Started button after tutorial pages verified");
get_started.click();
}
catch(Exception e) {
Assert.fail("Tutorial pages has not verified completely: " + e.getMessage());
}
}
}