-
Notifications
You must be signed in to change notification settings - Fork 76
/
TestBase.java
116 lines (100 loc) · 3.42 KB
/
TestBase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package Tests.AbstractBaseTests;
import Pages.NavigationPage;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
/**
* An abstract base for all of the Android tests within this package
*
* Responsible for setting up the Appium test Driver
*/
public abstract class TestBase {
/**
* Make the driver static. This allows it to be created only once
* and used across all of the test classes.
*/
public static AndroidDriver<MobileElement> driver;
/**
* This allows the navigation to work within the app.
* The category name is returned so we can navigate to it from the navigation
* drawer.
*
* @return The name of the Android category
*/
public abstract String getName();
/**
* A page containing the navigation drawer
*/
private NavigationPage navigationPage;
/**
* Method to initialize the test's page
*/
@BeforeTest
public abstract void setUpPage();
/**
* This method runs before any other method.
*
* Appium follows a client - server model:
* We are setting up our appium client in order to connect to Device Farm's appium server.
*
* We do not need to and SHOULD NOT set our own DesiredCapabilities
* Device Farm creates custom settings at the server level. Setting your own DesiredCapabilities
* will result in unexpected results and failures.
*
* @throws MalformedURLException An exception that occurs when the URL is wrong
*/
@BeforeSuite
public void setUpAppium() throws MalformedURLException {
final String URL_STRING = "http://127.0.0.1:4723/wd/hub";
URL url = new URL(URL_STRING);
//Use a empty DesiredCapabilities object
DesiredCapabilities capabilities = new DesiredCapabilities();
driver = new AndroidDriver<MobileElement>(url, capabilities);
//Use a higher value if your mobile elements take time to show up
driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);
}
/**
* Always remember to quit
*/
@AfterSuite
public void tearDownAppium() {
driver.quit();
}
/**
*
* Creates a navigation page and navigates to the Class' category
* within the navigation drawer
*
*/
@BeforeClass
public void navigateTo() throws InterruptedException {
navigationPage = new NavigationPage(driver);
navigationPage.gotoCategory(getName());
}
/**
* Restart the app after every test class to go back to the main
* screen and to reset the behavior
*/
@AfterClass
public void restartApp() {
driver.resetApp();
}
}