Reputation: 21
How to do automation test using appium server and appium inspector for flutter application switching to web browser or web view.
When flutter application is switched to web view or browser from flutter native user has to Sign in with the email address and password or create account using email address and password , confirm password and I want to do automation testing whiling Signing In and Signing Up.
I have setup Appium Inspector and Appium Server successfully and able to connect to my app debug.apk on my emulator.
My code looks like
import Util.TestBase; import appium_flutter_driver.FlutterFinder; import appium_flutter_driver.finder.FlutterElement; import com.relevantcodes.extentreports.LogStatus; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebElement; import org.testng.annotations.Test; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import java.io.File; import org.openqa.selenium.OutputType; import io.appium.java_client.MobileElement; import pro.truongsinh.appium_flutter.FlutterFinder; public class AppiumTestDemo extends TestBase { @Test public static void main(String args[]){ try { switchContext("WEBVIEW"); logger = extent.startTest("WEBVIEW Switch Context"); logger.log(LogStatus.PASS, "WEBVIEW Switch Context passed"); switchContext("NATIVE_APP"); FlutterFinder find = new FlutterFinder(driver); Thread.sleep(3000);*/ AppiumDriver driver= TestBase.initializeDriver(); driver.manage().timeouts().implicitywait(10,TimeUnit.SECONDS); WebElement viewClick = ((FindsByAndroidUIAutomator)driver).findElementByAndroidUIAutomator(using ("new UiSelector().text(\"Create your account\")")); WebElement viewClick1 = ((FindsByAndroidUIAutomator)driver).findElementByAndroidUIAutomator(using ("new UiSelector().text(\"Sign In\")")); System.out.println(viewClick.getText()); viewClick.click(); WebElement webviewClick = ((FindsByAndroidUIAutomator)driver).findElementByAndroidUIAutomator(using ("new UiScrollable(new UiSelector().scrollable(true).instanstance(0)).scrollIntoView(new UiSelector.className(\"android.widget.TextView\").text(\"WebView\"))")); webViewClick.click(); Set<String> contextNames = driver.getContextHandles(); for (String contextName : contextNames) { System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1 } driver.context("WEBVIEW_io..appium.android.apis"); System.out.println(driver.findElement(newBy.ByCssSelector("body>h1")).getText()); FlutterElement txt_username = find.byValueKey("Email address"); FlutterElement txt_password = find.byValueKey("Password"); FlutterElement button_login = find.byValueKey("SIGN IN"); txt_username.sendKeys("[email protected]"); txt_password.sendKeys("admin"); button_login.click(); logger = extent.startTest("Flutter data input & Click test"); logger.log(LogStatus.PASS, "Flutter data input & Click test passed"); Thread.sleep(5000); catch (TimeoutException | InterruptedException e) { logger = extent.startTest("Flutter data input & Click test Failed "); logger.log(LogStatus.FAIL, e); } driver.context("NATIVE_APP"); } }
Please help me Switch from Flutter Context to web or browser Context and perform automation testing on the browser url containing Sign In and Sign Up form and come back again to flutter native application.
Tried setting Appium Inspector and Started my appium server, Written test script as AppiumTestDemo.java but unable to run it and perform test
Upvotes: 0
Views: 136