Last active
June 21, 2023 14:47
-
-
Save SarahElson/f4cafff93396b3fe4edaf56c2d92aa1a to your computer and use it in GitHub Desktop.
Automated App Testing Using Appium With TestNG [Tutorial]
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
package com.lambdatest.appium.sample.ios; | |
import static com.lambdatest.appium.sample.enums.Platform.IOS; | |
import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable; | |
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated; | |
import java.net.MalformedURLException; | |
import com.lambdatest.appium.sample.BaseTest; | |
import com.lambdatest.appium.sample.enums.Environment; | |
import com.lambdatest.appium.sample.enums.Platform; | |
import com.lambdatest.appium.sample.pages.HomePage; | |
import com.lambdatest.appium.sample.utils.Swipe; | |
import io.appium.java_client.MobileElement; | |
import io.appium.java_client.ios.IOSDriver; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
import org.testng.Assert; | |
import org.testng.annotations.BeforeTest; | |
import org.testng.annotations.Parameters; | |
import org.testng.annotations.Test; | |
// 1. | |
public class IOSTest extends BaseTest<IOSDriver<MobileElement>> { | |
private static final Platform PLATFORM = IOS; | |
private HomePage homePage; | |
// 2. | |
@Parameters ({ "environment", "deviceName", "version", "app" }) | |
@BeforeTest | |
public void setupDriver (final Environment environment, final String deviceName, final String version, | |
final String app) throws MalformedURLException { | |
this.homePage = new HomePage (); | |
this.driver = new IOSDriver<> (getUrl (environment), getOptions (environment, "iOS", deviceName, version, app)); | |
this.wait = new WebDriverWait (this.driver, 10); | |
this.swipe = new Swipe<> (this.driver); | |
} | |
// 3. | |
@Test | |
public void testNotifications () { | |
this.wait.until (elementToBeClickable (this.homePage.notificationButton () | |
.get (PLATFORM))) | |
.click (); | |
this.swipe.down (); | |
Assert.assertTrue (this.wait.until (visibilityOfElementLocated (this.homePage.proverbialNotification () | |
.get (PLATFORM))) | |
.getText () | |
.contains ("Test Notification, Please enjoy this notification")); | |
this.swipe.up (); | |
} | |
// 4. | |
@Test | |
public void testTextButton () { | |
this.wait.until (elementToBeClickable (this.homePage.textButton () | |
.get (PLATFORM))) | |
.click (); | |
Assert.assertEquals (this.wait.until (visibilityOfElementLocated (this.homePage.message () | |
.get (PLATFORM))) | |
.getText (), "Proverbial"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment