public void Click(string image) { var imageObject = Patterns.FromFile(_pathToProject + image); _session.Click(imageObject); Log.Info(String.Format("{0} : click", image)); }
public void SikuliSharpTest() { using (var loginPage = Sikuli.CreateSession()) { //Patterns var nextButton = Patterns.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Images\nextButton.png")); var userNameInput = Patterns.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Images\emailInput.png")); var userPassInput = Patterns.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Images\passwordInput.png")); var searchEmailInput = Patterns.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Images\searchEmailInput.png")); //Waiting until the user name input is present loginPage.Wait(userNameInput); //Setting user name and password loginPage.Type("abarrazabriones"); //Clicking on the Next button loginPage.Click(nextButton); //Waiting until the password input is present loginPage.Wait(userPassInput); //Setting user name and password loginPage.Type("cacuca13"); //Clicking on the "Sign in" button loginPage.Click(nextButton); //Waiting until the search email input is present loginPage.Wait(searchEmailInput); } }
public bool Exists(string image) { var imageObject = Patterns.FromFile(_pathToProject + image); Log.Info(String.Format("{0} : exist", image)); return(_session.Exists(imageObject)); }
/// <summary> /// Keyword use to click on the Image /// </summary> /// <param name="pageName"></param> /// <param name="locatorName"></param> public static void Click(string pageName, string locatorName) { string element = ElementLocator.GetElementforSikkli(pageName, locatorName); if (element != null) { try { using (var session = Sikuli.CreateSession()) { var clickme = Patterns.FromFile(element, 0.9f); session.Click(clickme); session.Dispose(); } //System.Console.WriteLine("launch started found..."); Report.Pass("Clicked On " + locatorName); log.Info("Clicked On " + locatorName); } catch (FileNotFoundException fe) { Report.Fail(fe.Message); log.Error(TestContext.CurrentContext.Test.MethodName + " " + locatorName + " not found"); } } else { Report.Fail(locatorName + " not found"); log.Error(TestContext.CurrentContext.Test.MethodName + " " + locatorName + " not found"); } }
public void ThenUserVerifiesTheData() { try { SelectBrowser.driver.SwitchTo().Window(SelectBrowser.driver.WindowHandles.Last()); using (var session = Sikuli.CreateSession()) { var down_text = Patterns.FromFile(@"C:\Users\ankit.kansal\Desktop\Downloadbutton.PNG", 0.9f); var save_button = Patterns.FromFile(@"C:\Users\ankit.kansal\Desktop\SaveButton.PNG", 0.9f); session.Wait(down_text, 500); session.Click(down_text); test.Log(Status.Pass, "User Clicks on the Download Button"); session.Wait(save_button, 500); session.Click(save_button); test.Log(Status.Pass, "User Clicks on the Save Button"); } Assert.IsTrue(PDFReaderP.ExtractPDF(@"C:\Users\ankit.kansal\Downloads\ReconReport_V9.pdf").Contains("Account")); } catch (AssertFailedException ex) { Console.WriteLine("Exception==>" + ex); ScreenshotPage.TakesScreenshotWithDate(@"Screesnhot", System.Drawing.Imaging.ImageFormat.Png); } }
/// <summary> /// Key is use to virify the Visibility of an Image /// </summary> /// <param name="pageName"></param> /// <param name="locatorName"></param> /// <returns></returns> public static Boolean ImageVisible(string pageName, string locatorName) { Boolean status = false; string element = ElementLocator.GetElementforSikkli(pageName, locatorName); if (element != null) { using (var session = Sikuli.CreateSession()) { var clickme = Patterns.FromFile(element, 0.9f); status = session.Exists(clickme, 60); if (status == true) { log.Info(locatorName + " is present "); session.Hover(clickme); } else { log.Info(locatorName + " not found"); status = false; } session.Dispose(); } } else { Report.Fail("Image of " + locatorName + " is not Found"); log.Error(TestContext.CurrentContext.Test.MethodName + " " + locatorName + " not found"); status = false; } return(status); }
public void Hover(string image) { var imageObject = Patterns.FromFile(_pathToProject + image); _session.Hover(imageObject); Log.Info(String.Format("{0} : hover", image)); }
public void ThenUserShouldClickOnDownloadLinkForDownloadingPdfFile() { try { SelectBrowser.driver.SwitchTo().Window(SelectBrowser.driver.WindowHandles.Last()); //Assert.IsTrue(SelectBrowser.driver.Url.Contains("w9form")); using (var session = Sikuli.CreateSession()) { var down_text = Patterns.FromFile(@"C:\Users\Anuruddha.Tiwari\source\repos\ThomasNetProject\ThomasNetProject\Images\DownloadButton.PNG", 0.9f); var save_button = Patterns.FromFile(@"C:\Users\Anuruddha.Tiwari\source\repos\ThomasNetProject\ThomasNetProject\Images\SaveButton.PNG", 0.9f); session.Wait(down_text, 500); session.Click(down_text); test.Log(Status.Pass, "User Clicks on the Download Button"); session.Wait(save_button, 500); session.Click(save_button); test.Log(Status.Pass, "User Clicks on the Save Button"); } //Assert.IsTrue(PDFReaderP.ExtractPDF(@"C:\Users\ankit.kansal\Downloads\ReconReport_V9.pdf").Contains("Account")); } catch (AssertFailedException ex) { Console.WriteLine("Exception==>" + ex); ScreenshotPage.TakesScreenshotWithDate(@"Screesnhot", System.Drawing.Imaging.ImageFormat.Png); } }
public void TestMethod1() { /* * Pattern file = new Pattern(@"C:\Users\Fabio\Desktop\jdownloaderImages\file.png"); * Pattern max = new Pattern(@"C:\Users\Fabio\Desktop\jdownloaderImages\maximize.png"); * Pattern aggiungi = new Pattern(@"C:\Users\Fabio\Desktop\jdownloaderImages\aggiungi.png"); * Pattern testoAggiungi = new Pattern(@"C:\Users\Fabio\Desktop\jdownloaderImages\testoAggiungi.png"); * Pattern continua = new Pattern(@"C:\Users\Fabio\Desktop\jdownloaderImages\continua.png"); * * * TestStack.White.Application application = TestStack.White.Application.Launch(@"C:\Users\Fabio\AppData\Local\JDownloader v2.0\JDownloader2.exe"); * * Thread.Sleep(5000); * * Sikuli4Net.sikuli_REST.Screen scr = new Sikuli4Net.sikuli_REST.Screen(); * scr.Click(max); * scr.Click(file); * scr.Click(aggiungi); * * scr.Click(testoAggiungi); * SendKeys.SendWait("http://releases.ubuntu.com/19.04/ubuntu-19.04-desktop-amd64.iso"); * Thread.Sleep(1000); * scr.Click(continua); * * * Thread.Sleep(4000); * application.Close(); * */ var file = Patterns.FromFile(@"C:\Users\Fabio\Desktop\jdownloaderImages\file.png"); var max = Patterns.FromFile(@"C:\Users\Fabio\Desktop\jdownloaderImages\maximize.png", 0.8f); var aggiungi = Patterns.FromFile(@"C:\Users\Fabio\Desktop\jdownloaderImages\aggiungi.png"); var testoAggiungi = Patterns.FromFile(@"C:\Users\Fabio\Desktop\jdownloaderImages\testoAggiungi.png"); var continua = Patterns.FromFile(@"C:\Users\Fabio\Desktop\jdownloaderImages\continua.png"); TestStack.White.Application application = TestStack.White.Application.Launch(@"C:\Users\Fabio\AppData\Local\JDownloader v2.0\JDownloader2.exe"); Thread.Sleep(5000); using (var session = Sikuli.CreateSession()) { try { session.Click(max); } catch (SikuliFindFailedException e) { } session.Click(file); session.Click(aggiungi); session.Click(testoAggiungi); SendKeys.SendWait("http://releases.ubuntu.com/19.04/ubuntu-19.04-desktop-amd64.iso"); Thread.Sleep(1000); session.Click(continua); } Thread.Sleep(4000); application.Close(); }
public void DragAndDrop(string image, string endPointImage) { var imageObject = Patterns.FromFile(_pathToProject + image); var place = Patterns.FromFile(_pathToProject + endPointImage); _session.DragAndDrop(imageObject, place); Log.Info(String.Format("{0} : drag and drop", image)); }
public void CanRunSikuliCommands() { using (var session = Sikuli.CreateSession()) { using (var app = ResourcesUtil.StartTestApplication()) { var redLabelPattern = Patterns.FromFile(ResourcesUtil.RedLabelPatternPath, 0.9f); var greenLabelPattern = Patterns.FromFile(ResourcesUtil.GreenLabelPatternPath, 0.9f); var testButtonPattern = Patterns.FromFile(ResourcesUtil.TestButtonPatternPath, 0.9f); var blackOffsetLabelPattern = Patterns.FromFile(ResourcesUtil.BlackOffsetLabelPatternPath, 0.9f); var whiteOffsetLabelPattern = Patterns.FromFile(ResourcesUtil.WhiteOffsetLabelPatternPath, 0.9f); var OffsetButtonPattern = Patterns.FromFile(ResourcesUtil.OffsetButtonPatternPath, 0.9f); Assert.That(session.Wait(redLabelPattern), Is.True, "Wait for application startup"); Assert.That(session.Exists(blackOffsetLabelPattern), Is.True, "Black offset label should exist"); Assert.That(session.Click(testButtonPattern, new Point(125, 0)), Is.True, "Click on the offset button by offsetting from the test button"); Assert.That(session.Exists(whiteOffsetLabelPattern), Is.True, "White offset label should exist"); var appLocation = app.GetWindowLocation(); Assert.That(session.Click(new Location(appLocation.X + 350, appLocation.Y + 100)), Is.True, "Click on offset button by location"); Assert.That(session.Exists(blackOffsetLabelPattern), Is.True, "Black offset label should exist"); session.Highlight(session.Find(blackOffsetLabelPattern), "blue"); session.Highlight(session.FindAll(OffsetButtonPattern)[0], "red"); Assert.That(session.Wait(redLabelPattern), Is.True, "Red label should exist"); Assert.That(session.Exists(greenLabelPattern), Is.False, "Green label should not exist yet"); Assert.That(session.Hover(testButtonPattern), Is.True, "Hover over Test Button"); Assert.That(session.Hover(new Location(appLocation.X + 350, appLocation.Y + 100)), Is.True, "Hover outside Test Button"); Assert.That(session.Click(testButtonPattern), Is.True, "Click on test button"); Assert.That(session.Exists(greenLabelPattern), Is.False, "Green label should still not exist (a 5s timer is shown)"); Assert.Throws <SikuliFindFailedException>(() => session.Wait(greenLabelPattern, 1), "Wait for green label, but not long enough should now work"); Assert.That(session.Wait(greenLabelPattern, 10), Is.True, "Wait for green label long enough should work"); Assert.That(session.Exists(greenLabelPattern, 10), Is.True, "Green label should now exist"); Assert.That(session.Type("x"), Is.True, "Type 'x' to exit"); Assert.That(session.WaitVanish(greenLabelPattern, 10), Is.True, "Wait for green label to vanish after app has exited"); } } }
public void ThenUserShouldBeAbleToVerifyPdfSuccesfully() { using (var session = Sikuli.CreateSession()) { var Download_img = Patterns.FromFile(@"C:\Users\Anuruddha.Tiwari\Desktop\DownloadButton.PNG", 0.9f); var Save_img = Patterns.FromFile(@"C:\Users\Anuruddha.Tiwari\Desktop\SaveButton.PNG", 0.9f); session.Wait(Download_img, 100); session.Click(Download_img); session.Wait(Save_img, 100); session.Click(Save_img); } }
public YoutubeEmbeddedPage(IWebDriver seleniumWebDriver) : base(seleniumWebDriver) { QualityAcceleratedLink = new Link(By.CssSelector("a[class='service_second_menu-list_link js-service_second_menu-list_link'][href='#header2']"), seleniumWebDriver); Screen = Sikuli.CreateSession(); PlayButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\play.png"); PauseButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\pause.png"); MuteButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\mute.png"); UnmuteButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\unmute.png"); SettingButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\setting.png"); QualityButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\quality.png"); FourEightZeroButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\480p.png"); FourEightZeroSelectedButtonPattern = Patterns.FromFile(ImagePath + "\\Images\\480pselected.png"); }
static void UseSikuli() { using (var session = Sikuli.CreateSession()) { var pattern = Patterns.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Capture.PNG")); bool exists = session.Exists(pattern); string result = exists ? "Pattern exists" : "Pattern not found"; Console.WriteLine(result); if (exists) { session.Hover(pattern); } Console.ReadKey(); } }
/// <summary> /// Method for Verifying the existance of a pattern i.e image in the Page /// /// NOTE: Using Sikuli with Parallel testing and with Remote Driver is not reliable as when it interacts with Images,the Test case whose browser is /// running upfront(visible on the screen) will get passed but other test cases which is running in back (not running upfront) will get failed /// We can use Sikuli for running test case Sequentially using LocalWebDriver instance /// </summary> /// <param name="Pattern">Here "Pattern" refers to a partial(Sub image)/full image of a web image/page which we need to validate /// e.g. We need to validate a part of google map,so we need to take a screenshot of that portion of the map and save it as a image /// with a name,and that saved image file's location along with the imagename is considered a "Pattern" i.e for an example @"C:\Users\Admin\Desktop\image.png" /// /// Note:SikuliSharp wrapper is available for .net version 4.5 not for previous verison /// </param> public void SikuliPatternVerifier(String Pattern) { try { using (var session = Sikuli.CreateSession()) { log.Info("The Path of the Pattern is: " + Pattern); var pattern = Patterns.FromFile(Pattern); MbUnit.Framework.Assert.IsTrue(session.Exists(pattern)); log.Info("The image/Pattern " + Pattern + " is verified successfully with Sikuli "); } } catch (Exception) { log.Error("Exception occured while creating Sikuli session"); } }
public void TestSikuliIntegration() { try { session = Sikuli.CreateSession(); patterns = Patterns.FromFile(@"C:\Data\win.PNG"); if (session.Exists(patterns)) { Console.WriteLine("Patteren Exist " + patterns.ToString()); session.Wait(patterns, 60); session.Click(patterns); } } finally { session?.Dispose(); } }
public void WhenClickOnThePrintButton() { try { using (var session = Sikuli.CreateSession()) { var print_text = Patterns.FromFile(@"C:\Users\ankit.kansal\Desktop\PrintImage.PNG", 0.9f); session.Wait(print_text, 500); session.Click(print_text); test.Log(Status.Pass, "User Clicks on the Print button"); } } catch (Exception ex) { Console.WriteLine("Exception==>" + ex); ScreenshotPage.TakesScreenshotWithDate(@"Screesnhot", System.Drawing.Imaging.ImageFormat.Png); } }
public void WriteInGoogleSearchBar(string searchTerm) { try { using (var session = Sikuli.CreateSession()) { var input = Patterns.FromFile("C:\\Users\\juan_\\Documents\\projects\\dotnetBase\\GenericProject\\GenericProject\\Resources\\SikuliImages\\GoogleSearchInput.png", 0.9f); var logo = Patterns.FromFile("C:\\Users\\juan_\\Documents\\projects\\dotnetBase\\GenericProject\\GenericProject\\Resources\\SikuliImages\\GoogleLogo.png", 0.9f); session.Click(input); session.Type(searchTerm); session.Click(logo); } } catch (Exception ex) { AssertionProvider.FailTest(ex.Message); } }
static void Main(string[] args) { string folderpath = @"..\..\Steps\"; string path = folderpath + @"Step1\Chrome.PNG"; SikuliRunner.InitializeSession(); IPattern ima = Patterns.FromFile(path); SikuliRunner.Click(ima); string path2 = folderpath + @"Step1\Chromeaddress.PNG"; var ima2 = Patterns.FromFile(path2); SikuliRunner.Wait(ima2); SikuliRunner.Type("https://www.nike.com/launch/"); SikuliRunner.PressKey(Keys.Enter); path = folderpath + @"Step2\Instock.PNG"; ima = Patterns.FromFile(path); SikuliRunner.Wait(ima); SikuliRunner.Click(ima); path = folderpath + @"Step3\Product1.PNG"; ima = Patterns.FromFile(path); if (SikuliRunner.SearchDown(ima, 10.0)) { SikuliRunner.Click(ima); } System.Threading.Thread.Sleep(1000); SikuliRunner.PressKey(Keys.Down); SikuliRunner.PressKey(Keys.Down); //path = folderpath + "Size1.PNG"; //ima = Patterns.FromFile(path); //if (SikuliRunner.SearchDown(ima,10.0)) //{ // SikuliRunner.Click(ima); //} //else //{ // Console.Write("Time out"); //} }
public void CanRunSikuliCommands() { using (var session = Sikuli.CreateSession()) { using (ResourcesUtil.StartTestApplication()) { var redLabelPattern = Patterns.FromFile(ResourcesUtil.RedLabelPatternPath, 0.9f); var greenLabelPattern = Patterns.FromFile(ResourcesUtil.GreenLabelPatternPath, 0.9f); var testButtonPattern = Patterns.FromFile(ResourcesUtil.TestButtonPatternPath, 0.9f); var blackOffsetLabelPattern = Patterns.FromFile(ResourcesUtil.BlackOffsetLabelPatternPath, 0.9f); var whiteOffsetLabelPattern = Patterns.FromFile(ResourcesUtil.WhiteOffsetLabelPatternPath, 0.9f); Assert.That(session.Wait(redLabelPattern), Is.True, "Wait for application startup"); Assert.That(session.Exists(blackOffsetLabelPattern), Is.True, "Black offset label should exist"); Assert.That(session.Click(testButtonPattern, new Point(125, 0)), Is.True, "Click on the offset button by offsetting from the test button"); Assert.That(session.Exists(whiteOffsetLabelPattern), Is.True, "White offset label should exist"); Assert.That(session.Wait(redLabelPattern), Is.True, "Red label should exist"); Assert.That(session.Exists(greenLabelPattern), Is.False, "Green label should not exist yet"); Assert.That(session.Click(testButtonPattern), Is.True, "Click on test button"); Assert.That(session.Exists(greenLabelPattern), Is.False, "Green label should still not exist (a 5s timer is shown)"); Assert.Throws <TimeoutException>(() => session.Wait(greenLabelPattern, 1), "Wait for green label, but not long enough should now work"); Assert.That(session.Wait(greenLabelPattern, 10), Is.True, "Wait for green label long enough should work"); Assert.That(session.Exists(greenLabelPattern), Is.True, "Green label should now exist"); Assert.That(session.Type("x"), Is.True, "Type 'x' to exit"); Assert.That(session.WaitVanish(greenLabelPattern, 10), Is.True, "Wait for green label to vanish after app has exited"); } } }
public void MakeReplays() { if (!IsBusy && Matches.Count > 0) { IsBusy = true; Task T = Task.Factory.StartNew(() => { CurrentMatch = Matches.Dequeue(); CurrentMatch.Status = "Replay In Progress"; string imagePath = HttpRuntime.AppDomainAppPath + "Images\\"; using (ISikuliSession session = Sikuli.CreateSession()) { //session.Click(Patterns.FromFile(imagePath + "CloseButton.PNG")); WaitAndClick(session, imagePath + "WatchButton.PNG"); WaitAndClick(session, imagePath + "WatchButton.PNG"); WaitAndClick(session, imagePath + "ReplaysButton.PNG"); WaitAndClick(session, imagePath + "MatchIds.PNG"); session.Type(CurrentMatch.MatchId); WaitAndClick(session, imagePath + "SearchButton.PNG"); WaitAndClick(session, imagePath + "DownloadReplayButton.PNG"); WaitAndClick(session, imagePath + "MatchIdText.PNG"); WaitAndClick(session, imagePath + "WatchReplayButton.PNG", .9F); StartStopRecording(); WaitAndClick(session, imagePath + "CollapseButton.PNG", .7f, 300); //Wait 2 hours at most //session.Wait(Patterns.FromFile(imagePath + "WatchReplayButton.PNG"), 7200); try { session.Wait(Patterns.FromFile(imagePath + "WatchReplayButton.PNG"), 60); } catch { }; StartStopRecording(); //Wait 1 second for the sake of shadowplay's save Thread.Sleep(1000); } //Cleanup Replay File File.Delete(@"D:\Program Files (x86)\Steam\steamapps\common\dota 2 beta\game\dota\replays\" + CurrentMatch.MatchId + ".DEM"); CurrentMatch.Done = true; CurrentMatch.ProgressPercentage = 100; LastCompletedMatch = CurrentMatch; CurrentMatch = null; IsBusy = false; CurrentMatch.Status = "Replay Uploading"; YoutubeUploader.UploadToYoutube(); MakeReplays(); }); } //Task to give a rough idea of replay progress Task progressUpdator = Task.Factory.StartNew(() => { DateTime startTime = DateTime.Now; while (CurrentMatch != null && !CurrentMatch.Done) { CurrentMatch.ProgressPercentage = DateTime.Now.Subtract(startTime).Seconds / int.Parse(CurrentMatch.Duration); Thread.Sleep(2000); } }); }
private void WaitAndClick(ISikuliSession session, string fileName, float matchPercentage = .7f, int waitSeconds = 120) { session.Wait(Patterns.FromFile(fileName, matchPercentage), waitSeconds); session.Click(Patterns.FromFile(fileName, matchPercentage)); }
public static void Click(string imagePath, string imageName, float accuracy) { session.Click(Patterns.FromFile(Path.Combine(imagePath, imageName), accuracy)); }
private IPattern ResolveScreenshot(string screenshotName, double similiraty = 0.7) => Patterns.FromFile($"D:\\ITSteps\\2020\\Automation Testing\\{screenshotName}", (float)similiraty);
public void CanCreateFilePattern() { Assert.That(Patterns.FromFile(@"C:\Test.png"), Is.TypeOf <FilePattern>()); }