public static void screenVSC7(AndroidDriver driver) { int i; int i2; // create collection of Radio Groups var vCollection = driver.FindElementsByClassName("android.widget.RadioGroup"); var vCollRadio = driver.FindElementsByClassName("android.widget.RadioButton"); //Loop through Radio Group collection for (i = 0; i < (vCollection.Count()); i++) { vCollRadio = vCollection[i].FindElements(By.ClassName("android.widget.RadioButton")); //Check the NO option is selected - If no select it for (i2 = 0; i2 < (vCollRadio.Count()); i2++) { if (vCollRadio[i2].Text == "No" && vCollRadio[i2].GetAttribute("checked").ToString() == "false") { vCollRadio[i2].Click(); } } } //Set up touch screen scrolling RemoteTouchScreen touch = new RemoteTouchScreen(driver); do { //scroll to ensure next radio group is present touch.Flick(150, -1); Thread.Sleep(500); // create collection of Radio Groups vCollection = driver.FindElementsByClassName("android.widget.RadioGroup"); //Loop through Radio Group collection for (i = 0; i < (vCollection.Count()); i++) { vCollRadio = vCollection[i].FindElements(By.ClassName("android.widget.RadioButton")); //Check the NO option is selected - If no select it for (i2 = 0; i2 < (vCollRadio.Count()); i2++) { if (vCollRadio[i2].Text == "No" && vCollRadio[i2].GetAttribute("checked").ToString() == "false") { vCollRadio[i2].Click(); } } } } while (IsElementPresent("Next", driver) == false); //select NEXT driver.FindElementByName("Next").Click(); }
public void APIDemo() { AppiumDriver <AppiumWebElement> driver; var cap = new AppiumOptions(); cap.AddAdditionalCapability("deviceName", "Appium_emulator"); cap.AddAdditionalCapability("platformVersion", "9.0.0"); cap.AddAdditionalCapability("platformName", "Android"); cap.AddAdditionalCapability("appPackage", "io.appium.android.apis"); cap.AddAdditionalCapability("appActivity", "io.appium.android.apis.ApiDemos"); driver = new AndroidDriver <AppiumWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); //click Preference driver.FindElementByXPath("//android.widget.TextView[@content-desc='Preference']").Click(); //click PreferenceDependencies wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//android.widget.TextView[@content-desc='3. Preference dependencies']"))).Click(); //click wifi checkbox wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("android:id/checkbox"))).Click(); //click WIFI Settings wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("(//android.widget.RelativeLayout)[2]"))).Click(); //send keys driver.FindElementByClassName("android.widget.EditText").SendKeys("hello"); //use findelements if the xpath is same for many elements and choose the index and click the element //click ok button which is in second position with the index 1 driver.FindElementsByClassName("android.widget.Button")[1].Click(); }
public static void Main(string[] args) { DesiredCapabilities caps = new DesiredCapabilities(); caps.SetCapability("browserstack.user", userName); caps.SetCapability("browserstack.key", accessKey); caps.SetCapability("device", "Google Pixel"); caps.SetCapability("app", "bs://<hashed app-id>"); AndroidDriver <AndroidElement> driver = new AndroidDriver <AndroidElement>(new Uri("http://hub-cloud.browserstack.com/wd/hub"), caps); AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until( ExpectedConditions.ElementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia")) ); searchElement.Click(); AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until( ExpectedConditions.ElementToBeClickable(MobileBy.Id("org.wikipedia.alpha:id/search_src_text")) ); insertTextElement.SendKeys("BrowserStack"); System.Threading.Thread.Sleep(5000); IReadOnlyList <AndroidElement> allTextViewElements = driver.FindElementsByClassName("android.widget.TextView"); Console.WriteLine(allTextViewElements.Count() > 0); driver.Quit(); }
public static void screenTemperature(AndroidDriver driver) { //Console.WriteLine("SPECIAL - Temperature start"); var vCollection = driver.FindElementsByClassName("android.widget.EditText"); var random = new Random(); string myText; int randomInt = random.Next(95, 105); //get a random decimal place myText = randomInt + "." + random.Next(0, 9); driver.Navigate().Back(); GenericFunctions.Wait(1); vCollection[0].SendKeys(myText); //Console.WriteLine("SPECIAL - Temperature = " + myText); driver.Navigate().Back(); Thread.Sleep(1000); vCollection[1].SendKeys(myText); //Console.WriteLine("SPECIAL - Temperature = " + myText); //close the keyboard driver.Navigate().Back(); GenericFunctions.Wait(1); //select 'Next' driver.FindElementByName("Next").Click(); GenericFunctions.Wait(1); driver.FindElementByName("Next").Click(); GenericFunctions.Wait(1); }
// Get a list of elements from selector and return based on index public static AndroidElement GetElementFromList(AndroidDriver <AndroidElement> driver, SelectBy by, string selector, int index) { AndroidElement e = null; switch (by) { case SelectBy.ID: e = driver.FindElementsById(selector)[index]; break; case SelectBy.Class: e = driver.FindElementsByClassName(selector)[index]; break; case SelectBy.XPath: e = driver.FindElementsByXPath(selector)[index]; break; case SelectBy.ExactText: e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().text(\"{0}\")", selector)).ElementAt(index); break; case SelectBy.ContainsText: e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().textContains(\"{0}\")", selector)).ElementAt(index); break; case SelectBy.RegexText: e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().textMatches(\"{0}\")", selector)).ElementAt(index); break; } return(e ?? throw new NotFoundException("Element with selector " + selector + " not found.")); }
public static void SpecialTrainingCompleteStartNewVrc(AndroidDriver driver) { //Console.WriteLine("SPECIAL - specialTrainingCompleteStartNewVRC"); //select 'Yes' training understood driver.FindElementByName("Yes").Click(); //Select 'Next' driver.FindElementByName("Next").Click(); GenericFunctions.Wait(1); //Eneter Live PIN and confirm it var vCollection = driver.FindElementsByClassName("android.widget.EditText"); for (int i = 0; i <= (vCollection.Count() - 1); i++) { vCollection[i].SendKeys("1111"); } //Select 'Next' to set PIN driver.FindElementByName("Next").Click(); GenericFunctions.Wait(1); //enter 'Yes' to New VRC screen driver.FindElementByName("Yes").Click(); //Select 'Next' driver.FindElementByName("Next").Click(); GenericFunctions.Wait(1); //select injection site location and confirm in review screen ScreenInjectionSiteLocation(driver); GenericFunctions.Wait(1); driver.FindElementByName("Submit").Click(); GenericFunctions.Wait(1); }
static void Main(string[] args) { AppiumOptions caps = new AppiumOptions(); // Set your BrowserStack access credentials caps.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME"); caps.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test caps.AddAdditionalCapability("app", "bs://<app-id>"); // Specify device and os_version caps.AddAdditionalCapability("device", "Google Pixel 3"); caps.AddAdditionalCapability("os_version", "9.0"); // Specify the platform name caps.PlatformName = "Android"; // Set other BrowserStack capabilities caps.AddAdditionalCapability("project", "First CSharp project"); caps.AddAdditionalCapability("build", "CSharp Android"); caps.AddAdditionalCapability("name", "first_test"); // Initialize the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above AndroidDriver <AndroidElement> driver = new AndroidDriver <AndroidElement>( new Uri("http://hub-cloud.browserstack.com/wd/hub"), caps); // Test case for the BrowserStack sample Android app. // If you have uploaded your app, update the test case here. AndroidElement searchElement = (AndroidElement) new WebDriverWait( driver, TimeSpan.FromSeconds(30)).Until( SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable( MobileBy.AccessibilityId("Search Wikipedia")) ); searchElement.Click(); AndroidElement insertTextElement = (AndroidElement) new WebDriverWait( driver, TimeSpan.FromSeconds(30)).Until( SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable( MobileBy.Id("org.wikipedia.alpha:id/search_src_text")) ); insertTextElement.SendKeys("BrowserStack"); System.Threading.Thread.Sleep(5000); IReadOnlyList <AndroidElement> allTextViewElements = driver.FindElementsByClassName("android.widget.TextView"); Console.WriteLine(allTextViewElements.Count > 0); // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.Quit(); }
public static void screenER(AndroidDriver driver) { //Console.WriteLine("SPECIAL SCREEN - ER"); //semi-randomly select check boxes int randomInt; Random random = new Random(); var vCollection = driver.FindElementsByClassName("android.widget.CheckBox"); if (driver.FindElementsByClassName("android.widget.CheckBox").Count() == 3) { randomInt = random.Next(0, 4); switch (randomInt) { case 0: //select NONE vCollection[0].Click(); //Console.WriteLine("ER Screen: NONE"); break; case 1: //select ER vCollection[1].Click(); //Console.WriteLine("ER Screen: ER"); break; case 2: //select HOSPITALISED vCollection[2].Click(); //Console.WriteLine("ER Screen: HOSPITALISED"); break; case 3: //select ER and HOSPITALISED vCollection[1].Click(); vCollection[2].Click(); //Console.WriteLine("ER Screen: ER and HOSPITALISED"); break; } //select NEXT and return special driver.FindElementByName("Next").Click(); } }
//Function to ensure unresolved events remain unresolved for the duration of the diary entry public static void screenOnGoing(AndroidDriver driver) { //work out which log screen this is var vCollection = driver.FindElementsByClassName("android.widget.TextView"); string screenName = vCollection[2].GetAttribute("name").ToString(); switch (screenName) { case "UnresolvedIsrSiteOneSwellingActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrSiteOneRednessActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrSiteOnePainActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrSiteOneOtherUpdateActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrSiteTwoSwellingActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrSiteTwoRednessActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrSiteTwoPainActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrSiteTwoOtherUpdateActivity": driver.FindElementByName("Yes").Click(); driver.FindElementByName("Next").Click(); break; case "UnresolvedIsrInstructionsActivity": driver.FindElementByName("Next").Click(); break; } }
private IWebElement FindTouchPaint() { try { return(driver.FindElementByName("Touch Paint")); } catch (NoSuchElementException) { var els = driver.FindElementsByClassName("android.widget.TextView"); var loc1 = els [els.Count - 1].Location; var loc2 = els [0].Location; var swipe = Actions.Swipe(driver, loc1.X, loc1.Y, loc2.X, loc2.Y, 800); swipe.Perform(); return(FindTouchPaint()); } }
public void AddNewItem() { AndroidDriver <AppiumWebElement> driver = StartApp(); // tap on second item var el1 = driver.FindElement(MobileBy.AccessibilityId("Add")); el1.Click(); var elItemText = driver.FindElement(MobileBy.AccessibilityId("ItemText")); elItemText.Clear(); elItemText.SendKeys("This is a new Item"); var elItemDetail = driver.FindElement(MobileBy.AccessibilityId("ItemDescription")); elItemDetail.Clear(); elItemDetail.SendKeys("These are the details"); var elSave = driver.FindElement(MobileBy.AccessibilityId("Save")); elSave.Click(); CreateScreenshot(driver); WaitForProgressbarToDisapear(driver); CreateScreenshot(driver); var scrollableElement = driver.FindElement(MobileBy.AccessibilityId("ItemsListView")); Func <AppiumWebElement> FindElementAction = () => { // find all text views // check if the text matches var elements = driver.FindElementsByClassName("android.widget.TextView"); foreach (var textView in elements) { if (textView.Text == "This is a new Item") { return(textView); } } return(null); }; var elementFound = ScrollUntillItemFound(driver, scrollableElement, FindElementAction, 4); Assert.IsTrue(elementFound != null); driver.CloseApp(); }
public static void Main(string[] args) { Local local = new Local(); List <KeyValuePair <string, string> > options = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key", accessKey) }; local.start(options); DesiredCapabilities caps = new DesiredCapabilities(); caps.SetCapability("browserstack.user", userName); caps.SetCapability("browserstack.key", accessKey); caps.SetCapability("device", "Google Pixel"); caps.SetCapability("browserstack.local", true); caps.SetCapability("app", "bs://<hashed app-id>"); AndroidDriver <AndroidElement> driver = new AndroidDriver <AndroidElement>(new Uri("http://hub-cloud.browserstack.com/wd/hub"), caps); AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until( ExpectedConditions.ElementToBeClickable(MobileBy.Id("com.example.android.basicnetworking:id/test_action")) ); searchElement.Click(); AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until( ExpectedConditions.ElementToBeClickable(MobileBy.ClassName("android.widget.TextView")) ); AndroidElement testElement = null; IReadOnlyList <AndroidElement> allTextViewElements = driver.FindElementsByClassName("android.widget.TextView"); System.Threading.Thread.Sleep(5000); foreach (AndroidElement textElement in allTextViewElements) { if (textElement.Text.Contains("The active connection is")) { testElement = textElement; } } Console.WriteLine(testElement.Text); driver.Quit(); local.stop(); }
public void SimpleTouchActionTestCase() { IList <AppiumWebElement> els = driver.FindElementsByClassName("android.widget.TextView"); int number1 = els.Count; TouchAction tap = new TouchAction(driver); tap.Tap(els[4], 10, 5, 2).Perform(); els = driver.FindElementsByClassName("android.widget.TextView"); Assert.AreNotEqual(number1, els.Count); }
/// <summary> /// This method will sign a user IN to google /// </summary> public void GoogleLogin() { // Access Menu TouchAction touchAction = new TouchAction(driver); AndroidElement element = driver.FindElementByXPath("//android.widget.ImageView[@content-desc='More options']"); var action = touchAction.Tap(element); action.Perform(); action.Cancel(); Thread.Sleep(2000); // Tap Sign in element = driver.FindElementByXPath("//android.widget.TextView[@text='Sign In']"); action = touchAction.Tap(element); action.Perform(); action.Cancel(); Thread.Sleep(2000); // Tap Google element = driver.FindElementByXPath("//android.widget.Button[@text='GOOGLE']"); action = touchAction.Tap(element); action.Perform(); action.Cancel(); Thread.Sleep(6000); // Find all the ListViews On The Page var elements = driver.FindElementsByClassName("//android.widget.LinearLayout[@resource-id='com.google.android.gms:id/container']"); //var elements = driver.FindElementsByClassName("android.widget.ListView"); // The first List View Element is The Button We Want To Tap element = elements.ElementAt(0); // So I'm Gonna Tap It. action = touchAction.Tap(element); action.Perform(); action.Cancel(); Thread.Sleep(2000); }
static void Main(string[] args) { Local browserStackLocal = null; AppiumOptions appiumOptions = new AppiumOptions(); // Set your BrowserStack access credentials appiumOptions.AddAdditionalCapability("browserstack.user", userName); appiumOptions.AddAdditionalCapability("browserstack.key", accessKey); // Set URL of the application under test appiumOptions.AddAdditionalCapability("app", "bs://<app-id>"); // Specify device and os_version appiumOptions.AddAdditionalCapability("device", "Google Pixel 3"); appiumOptions.AddAdditionalCapability("os_version", "9.0"); appiumOptions.AddAdditionalCapability("browserstack.local", "true"); // Specify the platform name appiumOptions.PlatformName = "Android"; // Set other BrowserStack capabilities appiumOptions.AddAdditionalCapability("project", "First CSharp project"); appiumOptions.AddAdditionalCapability("build", "CSharp Android local"); appiumOptions.AddAdditionalCapability("name", "local_test"); // if the platform is Windows, enable local testing fropm within the test // for Mac and GNU/Linux, run the local binary manually to enable local testing (see the docs) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && appiumOptions.ToCapabilities().HasCapability("browserstack.local") && appiumOptions.ToCapabilities().GetCapability("browserstack.local").ToString() == "true") { browserStackLocal = new Local(); List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key", accessKey) }; browserStackLocal.start(bsLocalArgs); } // Initialize the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above AndroidDriver <AndroidElement> driver = new AndroidDriver <AndroidElement>( new Uri("http://hub-cloud.browserstack.com/wd/hub"), appiumOptions); // Test case for the BrowserStack sample Android Local app. // If you have uploaded your app, update the test case here. AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until( SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(MobileBy.Id("com.example.android.basicnetworking:id/test_action")) ); searchElement.Click(); AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until( SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(MobileBy.ClassName("android.widget.TextView")) ); AndroidElement testElement = null; IReadOnlyList <AndroidElement> allTextViewElements = driver.FindElementsByClassName("android.widget.TextView"); System.Threading.Thread.Sleep(5000); foreach (AndroidElement textElement in allTextViewElements) { if (textElement.Text.Contains("The active connection is")) { testElement = textElement; } } Console.WriteLine(testElement.Text); // Invoke driver.quit() after the test is done to indicate the test is completed. driver.Quit(); // Stop the BrowserStack Local Binary. if (browserStackLocal != null) { browserStackLocal.stop(); } }
public void AddNewItemWithNewCategory() { System.Environment.SetEnvironmentVariable("ANDROID_HOME", @"C:\Program Files (x86)\Android\android-sdk"); System.Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin"); var capabilities = new AppiumOptions(); // automatic start of the emulator if not running capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.Avd, "demo_device"); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AvdArgs, "-no-boot-anim -no-snapshot-load"); capabilities.AddAdditionalCapability(MobileCapabilityType.FullReset, true); // connecting to a device or emulator capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "2471736c36037ece"); capabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName, "UiAutomator2"); // specifyig which app we want to install and launch var currentPath = Directory.GetCurrentDirectory(); Console.WriteLine($"Current path: {currentPath}"); var packagePath = Path.Combine(currentPath, @"..\..\..\AppsToTest\com.fluentbytes.carvedrock-x86.apk"); packagePath = Path.GetFullPath(packagePath); Console.WriteLine($"Package path: {packagePath}"); capabilities.AddAdditionalCapability(MobileCapabilityType.App, packagePath); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppPackage, "com.fluentbytes.carvedrock"); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppActivity, "crc641782d5af3c9cf50a.MainActivity"); var _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().Build(); _appiumLocalService.Start();; var driver = new AndroidDriver <AppiumWebElement>(_appiumLocalService, capabilities); // Create new Category item first var categoryButton = driver.FindElement(MobileBy.AccessibilityId("AddCategory")); categoryButton.Click(); // fill out the form for a new category var categoryName = driver.FindElement(MobileBy.AccessibilityId("categoryName")); categoryName.Clear(); categoryName.SendKeys("New category from automation"); //save category var saveCategory = driver.FindElement(MobileBy.AccessibilityId("Save")); saveCategory.Click(); var el1 = driver.FindElementByAccessibilityId("Add"); el1.Click(); var elItemText = driver.FindElementByAccessibilityId("ItemText"); elItemText.Clear(); elItemText.SendKeys("This is a new Item"); var elItemDetail = driver.FindElementByAccessibilityId("ItemDescription"); elItemDetail.Clear(); elItemDetail.SendKeys("These are the details"); var elItemCategory = driver.FindElement(MobileBy.AccessibilityId("ItemCategory_Container")); elItemCategory.Click(); var picker = driver.FindElement(By.Id("android:id/contentPanel")); var categoryListItems = picker.FindElements(By.ClassName("android.widget.TextView")); foreach (var categoryElement in categoryListItems) { if (categoryElement.Text == "New category from automation") { categoryElement.Click(); } } var elSave = driver.FindElementByAccessibilityId("Save"); elSave.Click(); //wait for progress bar to disapear var wait = new DefaultWait <AndroidDriver <AppiumWebElement> >(driver) { Timeout = TimeSpan.FromSeconds(60), PollingInterval = TimeSpan.FromMilliseconds(500) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); wait.Until(d => d.FindElement(MobileBy.AccessibilityId("Second item"))); var listview = driver.FindElementByAccessibilityId("ItemsListView"); //now use wait to scroll untill we find item Func <AppiumWebElement> FindElementAction = () => { // find all text views // check if the text matches var elements = driver.FindElementsByClassName("android.widget.TextView"); foreach (var textView in elements) { if (textView.Text == "This is a new Item") { return(textView); } } return(null); }; wait = new DefaultWait <AndroidDriver <AppiumWebElement> >(driver) { Timeout = TimeSpan.FromSeconds(60), PollingInterval = TimeSpan.FromMilliseconds(1000) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); AppiumWebElement elementfound = null; elementfound = wait.Until(d => { var input = new PointerInputDevice(PointerKind.Touch); ActionSequence FlickUp = new ActionSequence(input); FlickUp.AddAction(input.CreatePointerMove(listview, 0, 0, TimeSpan.Zero)); FlickUp.AddAction(input.CreatePointerDown(MouseButton.Left)); FlickUp.AddAction(input.CreatePointerMove(listview, 0, -600, TimeSpan.FromMilliseconds(200))); FlickUp.AddAction(input.CreatePointerUp(MouseButton.Left)); driver.PerformActions(new List <ActionSequence>() { FlickUp }); return(FindElementAction()); }); Assert.IsTrue(elementfound != null); driver.CloseApp(); }
public void TestShouldFindElementsByClassName() { ICollection <AndroidElement> elements = driver.FindElementsByClassName("android.widget.FrameLayout"); Assert.AreEqual(3, elements.Count); }
public static string enrolSubject(string loginPIN, string subjectID, string centreID, AndroidDriver driver) { string sTempPIN = "false"; //login as site admin //standroid.GetScreenShot(driver, "test"); //standroid.takeScreenshot(driver); driver.FindElementByClassName("android.widget.EditText").SendKeys(loginPIN); driver.FindElementByName("Next").Click(); //select New Subject GenericFunctions.Wait(5); driver.FindElementByName("New Subject").Click(); //enter new subject enrollment details GenericFunctions.Wait(1); //standroid.GetScreenShot(driver, "screenshot"); orangutan.CaptureElementCollection("android.widget.EditText", driver); var fields = driver.FindElementsByClassName("android.widget.EditText"); fields[0].SendKeys(centreID); fields[1].SendKeys(centreID); fields[2].SendKeys(subjectID); fields[3].SendKeys(subjectID); //flick screen to get next question in view var touch = new RemoteTouchScreen(driver); GenericFunctions.Wait(1); touch.Flick(500, -1); GenericFunctions.Wait(1); touch.Flick(500, -1); GenericFunctions.Wait(1); //select 'No' to replacement phone question driver.FindElementByName("No").Click(); //select Next to confirm enrolment form details driver.FindElementByName("Next").Click(); GenericFunctions.Wait(1); //Capture the temporary PIN and SUBMIT orangutan.CaptureElementCollection("android.widget.TextView", driver); fields = driver.FindElementsByClassName("android.widget.TextView"); sTempPIN = fields[6].Text; //check it captured it correctly if (sTempPIN.Length != 4) { //didn't capture it correctly - return false sTempPIN = "false"; } //Console.WriteLine("sTempPIN = " + sTempPIN); driver.FindElementByName("Submit").Click(); //Select Next in the enrolment confirmation screen Thread.Sleep(1000); //standroid.GetScreenShot(driver, "screenshot"); driver.FindElementByName("Next").Click(); //Logout of the site admin side Thread.Sleep(1000); //standroid.GetScreenShot(driver, "screenshot"); driver.FindElementByName("Logout").Click(); //standroid.GetScreenShot(driver, "screenshot"); return(sTempPIN); }
public static bool amIspecial(AndroidDriver driver) { bool bamSpecial = false; var vCollection = driver.FindElementsByClassName("android.widget.EditText"); //int randomInt; //string randomText; //string myText; Random random = new Random(); //check to see if screen is special //am i the new VRC screen? if (driver.FindElementsByName("New VRC").Any()) { //Console.WriteLine("SPECIAL - New VRC start"); //standroid.GetScreenShot(driver, "screenshot"); //New VRC screen - select Yes then Next driver.FindElementByName("Yes").Click(); Thread.Sleep(500); driver.FindElementByName("Next").Click(); Thread.Sleep(500); //Console.WriteLine("SPECIAL - New VRC completed with YES"); } //am i the Injection Location screen? if (IsElementPresent("InjectionSiteLocationActivity", driver)) //if (driver.FindElementsByName("InjectionSiteLocationActivity").Count() > 0) { ScreenInjectionSiteLocation(driver); bamSpecial = true; return(bamSpecial); } //am i the temperature screen? //if (driver.FindElementsByName("Oral Temperature").Count() > 0) if (IsElementPresent("TemperatureEntryActivity", driver)) { screenTemperature(driver); //return special return(true); } //am i the Training Complete screen? if (driver.FindElementsByName("The training module is now complete.").Count() > 0) { SpecialTrainingCompleteStartNewVrc(driver); //return special return(true); } //am i an ER screen? if (driver.FindElementsByName("ER including urgent health centers").Count() > 0 && driver.FindElementsByClassName("android.widget.CheckBox").Count() == 3) { screenER(driver); return(true); } //am i a LOG screen? if (driver.FindElementsByName("TAP TO ADD").Count() > 0) { screenLog(driver); return(true); } //am i the VSC instructions screen? if (IsElementPresent("VscInstructionsActivity", driver)) { screenVSC(driver); return(true); } //am i the ISRd6 instructions screen? if (IsElementPresent("Isrd6InstructionsActivity", driver)) { screenISRD6(driver); return(true); } // If OnGoing is not required the diary will be completed at random and could still have some ongoing events //Check if OnGoing is required - OnGoing set in globals if (Globals.Run.PsOnGoing == "Yes") { //am i the Ongoing events screen? if (driver.FindElementsByName("Ongoing events").Any()) { screenOnGoing(driver); return(true); } } //I'm not special :[ return(false); }
public static void screenLog(AndroidDriver driver) { //work out which log screen this is var vCollection = driver.FindElementsByClassName("android.widget.TextView"); string screenName = vCollection[2].Text.ToString(); switch (screenName) { case "Other Complaints or Illnesses:": //Console.WriteLine("LOG SCREEN: OCI"); driver.FindElementByName("TAP TO ADD").Click(); orangutan.goBananas(driver); driver.FindElementByName("Next").Click(); merckVRC.screenER(driver); driver.FindElementByName("Next").Click(); break; case "Non-study vaccinations:": //Console.WriteLine("LOG SCREEN: NSV"); driver.FindElementByName("TAP TO ADD").Click(); orangutan.goBananas(driver); driver.FindElementByName("Next").Click(); driver.FindElementByName("Next").Click(); break; case "Medications": //Console.WriteLine("LOG SCREEN: MEDICATIONS"); driver.FindElementByName("TAP TO ADD").Click(); orangutan.goBananas(driver); driver.FindElementByName("Next").Click(); driver.FindElementByName("Next").Click(); break; case "Injection Site Complaints": //Console.WriteLine("LOG SCREEN: ISCd6"); driver.FindElementByName("TAP TO ADD").Click(); orangutan.goBananas(driver); merckVRC.screenER(driver); driver.FindElementByName("Next").Click(); driver.FindElementByName("Next").Click(); break; case "Vaccine Specific Complaints:": //Console.WriteLine("LOG SCREEN: VSR"); driver.FindElementByName("TAP TO ADD").Click(); orangutan.goBananas(driver); driver.FindElementByName("Next").Click(); orangutan.goBananas(driver); // scroll down to ensure RemoteTouchScreen touch = new RemoteTouchScreen(driver); do { Thread.Sleep(500); touch.Flick(500, -1); Thread.Sleep(500); } while(IsElementPresent("Next", driver) == false); driver.FindElementByName("Next").Click(); orangutan.goBananas(driver); driver.FindElementByName("Next").Click(); orangutan.goBananas(driver); // scroll down to ensure //RemoteTouchScreen touch1 = new RemoteTouchScreen(driver); do { Thread.Sleep(500); touch.Flick(500, -1); Thread.Sleep(500); } while(IsElementPresent("Next", driver) == false); driver.FindElementByName("Next").Click(); orangutan.goBananas(driver); driver.FindElementByName("Next").Click(); orangutan.goBananas(driver); driver.FindElementByName("Next").Click(); screenVSC7(driver); driver.FindElementByName("Next").Click(); break; } }
public static void ScreenInjectionSiteLocation(AndroidDriver driver) { //Console.WriteLine("SPECIAL SCREEN - Injection Site Location"); //semi-randomly select a location int randomInt; int i; var random = new Random(); var vCollection = driver.FindElementsByClassName("android.widget.ToggleButton"); if (driver.FindElementsByClassName("android.widget.ToggleButton").Count() == 3) { randomInt = random.Next(0, 3); switch (randomInt) { case 0: //select RIGHT vCollection[0].Click(); //Console.WriteLine("Inejection Site Location Screen: Left arm"); break; case 1: //select LEFT vCollection[1].Click(); //Console.WriteLine("Inejection Site Location Screen: Right arm"); break; case 2: //select OTHER vCollection[2].Click(); Thread.Sleep(500); string randomInjection = orangutan.randomSentence(30); driver.FindElementByClassName("android.widget.EditText").SendKeys(randomInjection); //Console.WriteLine("Inejection Site Location Screen: Other(" + randomInjection + ")"); break; } //select NEXT driver.FindElementByName("Next").Click(); } else if (driver.FindElementsByClassName("android.widget.ToggleButton").Count() == 6) { randomInt = random.Next(0, 6); for (i = 0; i < 2; i++) { //set int to odd if randomInt is even on first select and vice versa if (i > 0 && randomInt % 2 == 0) { //Generate odd number randomInt = random.Next(0 / 2, 6 / 2) * 2 + 1; } else if (i > 0 && randomInt % 2 == 1) { //Generate even number randomInt = random.Next(0 / 2, 6 / 2) * 2; } switch (randomInt) { case 0: //select Left Arm vCollection[0].Click(); //Console.WriteLine("Inejection Site Location Screen: Left arm"); break; case 1: //select Right Arm vCollection[1].Click(); //Console.WriteLine("Inejection Site Location Screen: Right arm"); break; case 2: //select Left Thigh vCollection[2].Click(); //Console.WriteLine("Inejection Site Location Screen: Left thigh"); break; case 3: //select Right Thigh vCollection[3].Click(); //Console.WriteLine("Inejection Site Location Screen: Right thigh"); break; case 4: //select Other 1 vCollection[4].Click(); string randomInjection1 = orangutan.randomSentence(30); driver.FindElementByClassName("android.widget.EditText").SendKeys(randomInjection1); //Console.WriteLine("Inejection Site Location Screen: Other(" + randomInjection1 + ")"); break; case 5: //select Other 2 vCollection[5].Click(); Thread.Sleep(500); string randomInjection2 = orangutan.randomSentence(30); //Check the number of text boxes on the screen - if greater than 1 select the second and populate with random string if (driver.FindElementsByClassName("android.widget.EditText").Count() > 1) { var vColl = driver.FindElementsByClassName("android.widget.EditText"); vColl[1].SendKeys(randomInjection2); } //if only one exists populate with random string else { driver.FindElementByClassName("android.widget.EditText").SendKeys(randomInjection2); } //Console.WriteLine("Inejection Site Location Screen: Other(" + randomInjection2 + ")"); break; } } //select NEXT driver.FindElementByName("Next").Click(); } else { //Console.WriteLine("FAIL @ Injection Site Location Screen: Missmatch in Collection Count: Count = " + driver.FindElementsByClassName("android.widget.ToggleButton").Count().ToString()); } }