This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static io.github.mfaisalkhatri.drivers.DriverManager.createAndroidDriver; | |
import static io.github.mfaisalkhatri.drivers.DriverManager.quitSession; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
public class BaseTest { | |
@BeforeClass | |
public void testSetup() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DriverManager { | |
private static final String APP_PATH = System.getProperty ("user.dir") + "\\src\\test\\resources\\app\\webdriverio-app.apk"; | |
private static final ThreadLocal<AppiumDriver> DRIVER = new ThreadLocal<> (); | |
private static final Logger LOG = LogManager.getLogger ("DriverManager.class"); | |
private static AppiumDriverLocalService service; | |
public static void createAndroidDriver () { | |
startServer (); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static AppiumDriverLocalService service; | |
public static void createAndroidDriver () { | |
startServer (); | |
DRIVER.set (new AndroidDriver (service.getUrl (), setCapabilities ())); | |
setupDriverTimeouts (); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static DesiredCapabilities setCapabilities () { | |
DesiredCapabilities capabilities = new DesiredCapabilities (); | |
capabilities.setCapability (MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID); | |
capabilities.setCapability (MobileCapabilityType.DEVICE_NAME, "Pixel_5_API_30"); | |
capabilities.setCapability (MobileCapabilityType.APP, APP_PATH); | |
capabilities.setCapability ("appPackage", "com.wdiodemoapp"); | |
capabilities.setCapability ("appActivity", "com.wdiodemoapp.MainActivity"); | |
capabilities.setCapability ("noReset", false); | |
capabilities.setCapability (MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2); | |
return capabilities; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void startServer () { | |
AppiumServiceBuilder builder = new AppiumServiceBuilder (); | |
builder.withIPAddress ("127.0.0.1") | |
.usingPort (4723) | |
.withAppiumJS ( | |
new File ("C:\\Users\\Windows\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js")) | |
.usingDriverExecutable (new File ("E:\\Program Files\\nodejs\\node.exe")) | |
.withArgument (BASEPATH, "/wd/hub") | |
.withArgument (GeneralServerFlag.SESSION_OVERRIDE) | |
.withArgument (GeneralServerFlag.LOG_LEVEL, "debug"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testRegisterUserWithBuilder () { | |
RegisterUserWithBuilder registerUserWithBuilder = getUserData (); | |
System.out.println (registerUserWithBuilder.getFirstName ()); | |
System.out.println (registerUserWithBuilder.getLastName ()); | |
System.out.println (registerUserWithBuilder.getAddress ()); | |
System.out.println (registerUserWithBuilder.getCity ()); | |
System.out.println (registerUserWithBuilder.getState ()); | |
System.out.println (registerUserWithBuilder.getCountry ()); | |
System.out.println (registerUserWithBuilder.getMobileNumber ()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataBuilder { | |
private static final Faker FAKER = Faker.instance (); | |
public static RegisterUserWithBuilder getUserData () { | |
return RegisterUserWithBuilder.builder () | |
.firstName (FAKER.name () | |
.firstName ()) | |
.lastName (FAKER.name () | |
.lastName ()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Getter | |
@Builder | |
public class RegisterUserWithBuilder { | |
private String firstName; | |
private String lastName; | |
private String address; | |
private String city; | |
private String state; | |
private String country; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegistrationTest { | |
@Test | |
public void testRegisterUser () { | |
RegisterUser registerUser = new RegisterUser ("John", "Doe", "302, Adam Street, 1st Lane", "New Orleans", | |
"New Jersey", "US", "52145364"); | |
assertEquals (registerUser.getFirstName (), "John"); | |
assertEquals (registerUser.getCountry (), "US"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegisterUser { | |
private String firstName; | |
private String lastName; | |
private String address; | |
private String city; | |
private String state; | |
private String country; | |
private String mobileNumber; | |
public RegisterUser (final String firstName, final String lastName, final String address, final String city, |