public void CSharpIOSNativeTest1() { try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); reportiumClient.StepStart("Enter email"); IOSElement email = (IOSElement)wait.Until(ExpectedConditions.ElementIsVisible((By.Name("login_email")))); email.SendKeys("*****@*****.**"); reportiumClient.StepStart("Enter password"); IOSElement password = (IOSElement)wait.Until(ExpectedConditions.ElementIsVisible((By.Name("login_password")))); password.SendKeys("test123"); driver.HideKeyboard(); reportiumClient.StepStart("Click login"); driver.HideKeyboard(); IOSElement login = (IOSElement)wait.Until(ExpectedConditions.ElementIsVisible((By.Name("login_login_btn")))); login.Click(); reportiumClient.StepStart("Add expense"); IOSElement add = (IOSElement)wait.Until(ExpectedConditions.ElementIsVisible((By.Name("list_add_btn")))); add.Click(); reportiumClient.StepStart("Select head"); IOSElement head = (IOSElement)wait.Until(ExpectedConditions.ElementIsVisible((By.Name("edit_head")))); head.Click(); wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath("//*[@value='- Select -']")))[0].SendKeys("Flight"); reportiumClient.StepStart("Enter amount"); IOSElement amount = (IOSElement)wait.Until(ExpectedConditions.ElementIsVisible((By.Name("edit_amount")))); amount.SendKeys("100"); reportiumClient.StepStart("Save expense"); IOSElement save = (IOSElement)wait.Until(ExpectedConditions.ElementIsVisible((By.Name("add_save_btn")))); save.Click(); reportiumClient.StepStart("Verify alert"); String expectedText = "Please enter valid category"; Boolean res = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@name='" + expectedText + "']"))).Displayed; reportiumClient.ReportiumAssert("Alert text validation.", res); reportiumClient.TestStop(Reportium.Test.Result.TestResultFactory.CreateSuccess()); } catch (Exception e) { reportiumClient.TestStop(Reportium.Test.Result.TestResultFactory.CreateFailure(e)); } ////Close connection and ends the test driver.Quit(); Console.WriteLine("C# IOS execution completed"); }
public void AndroidTest() { DesiredCapabilities capabilities = new DesiredCapabilities(); // 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com). String cloudName = "<<cloud name>>"; // 2. Replace <<security token>> with your perfecto security token. String securityToken = "<<security token>>"; capabilities.SetCapability("securityToken", securityToken); // 3. Set web capabilities. capabilities.SetCapability("platformName", "Android"); capabilities.SetCapability("model", "Galaxy S.*"); capabilities.SetCapability("browserName", "Chrome"); capabilities.SetCapability("useAppiumForWeb", true); capabilities.SetCapability("openDeviceTimeout", 5); // Initialize the driver RemoteWebDriver driver = new RemoteWebDriver( new Uri("https://" + cloudName.Replace(".perfectomobile.com", "") + ".perfectomobile.com/nexperience/perfectomobile/wd/hub"), capabilities); // Setting implicit wait driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); PerfectoExecutionContext perfectoExecutionContext; if (System.Environment.GetEnvironmentVariable("jobName") != null) { perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder() .WithProject(new Project("My Project", "1.0")) .WithJob(new Job(System.Environment.GetEnvironmentVariable("jobName"), int.Parse(System.Environment.GetEnvironmentVariable("jobNumber")))) .WithWebDriver(driver).Build(); } else { perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder() .WithProject(new Project("My Project", "1.0")) .WithWebDriver(driver).Build(); } ReportiumClient reportiumClient = PerfectoClientFactory.CreatePerfectoReportiumClient(perfectoExecutionContext); reportiumClient.TestStart("Selenium C# Android Sample", new Reportium.Test.TestContext("selenium", "android")); try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); String search = "perfectomobile"; reportiumClient.StepStart("Navigate to Google"); Dictionary <String, Object> pars = new Dictionary <String, Object>(); driver.Url = "https://www.google.com"; reportiumClient.StepEnd(); reportiumClient.StepStart("Search for Perfecto"); IWebElement searchbox = wait.Until(ExpectedConditions.ElementToBeClickable(driver.FindElement(By.XPath("//*[@name='q']")))); searchbox.SendKeys(search); searchbox.SendKeys(Keys.Enter); reportiumClient.StepEnd(); reportiumClient.StepStart("Verify Title"); String expectedText = "perfectomobile - Google Search"; Console.WriteLine(driver.Title); // Adding assertions to the Execution Report. This method will not fail the test reportiumClient.ReportiumAssert(expectedText, driver.Title.Contains(expectedText)); reportiumClient.StepEnd(); reportiumClient.TestStop(TestResultFactory.CreateSuccess()); } catch (Exception e) { reportiumClient.TestStop(TestResultFactory.CreateFailure(e)); } // Prints the Smart Reporting URL String reportURL = reportiumClient.GetReportUrl(); Console.WriteLine("Report url - " + reportURL); // Quits the driver driver.Quit(); }
public void PerfectoCSharpAndroidNativeTest1() { try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); reportiumClient.StepStart("Enter email"); IWebElement email = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("io.perfecto.expense.tracker:id/login_email"))); email.SendKeys("*****@*****.**"); reportiumClient.StepStart("Enter password"); IWebElement password = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("io.perfecto.expense.tracker:id/login_password"))); password.SendKeys("test123"); reportiumClient.StepStart("Click login"); driver.HideKeyboard(); IWebElement login = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("io.perfecto.expense.tracker:id/login_login_btn"))); login.Click(); reportiumClient.StepStart("Add expense"); IWebElement add = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("io.perfecto.expense.tracker:id/list_add_btn"))); add.Click(); reportiumClient.StepStart("Select head"); IWebElement head = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("io.perfecto.expense.tracker:id/input_layout_head"))); head.Click(); IWebElement flight = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@text='Flight']"))); flight.Click(); reportiumClient.StepStart("Enter amount"); IWebElement amount = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("io.perfecto.expense.tracker:id/add_amount"))); amount.SendKeys("100"); reportiumClient.StepStart("Save expense"); IWebElement save = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("io.perfecto.expense.tracker:id/layout_buttons"))); save.Click(); reportiumClient.StepStart("Verify alert"); String expectedText = "Select Currency"; bool res = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@text='" + expectedText + "']"))).Displayed; reportiumClient.ReportiumAssert("Alert text validation.", res); reportiumClient.TestStop(Reportium.Test.Result.TestResultFactory.CreateSuccess()); } catch (Exception e) { reportiumClient.TestStop(Reportium.Test.Result.TestResultFactory.CreateFailure(e)); } //Close connection and ends the test driver.Quit(); Console.WriteLine("C# Android execution completed"); }