Esempio n. 1
0
        public void ByType()
        {
            // Text
            FlutterDriver.Click(FlutterBy.Type("FlatButton"));

            AssertCounterIs("-4", because: "we pressed the Add button (Flat Button)");
        }
Esempio n. 2
0
        public void ByTooltip()
        {
            // Text
            FlutterDriver.Click(FlutterBy.Tooltip("FUT: FlutterBy.Tooltip (Increment 3)"));

            AssertCounterIs("3", because: "we pressed the Add+3 button");
        }
Esempio n. 3
0
        public void BySemanticsLabel()
        {
            // Text
            FlutterDriver.Click(FlutterBy.SemanticsLabel("FUT: FlutterBy.SemanticsLabel (Increment 4)"));

            AssertCounterIs("4", because: "we pressed the Semantics Label button");
        }
Esempio n. 4
0
        public void ByText()
        {
            // Text
            FlutterDriver.Click(FlutterBy.Text("FUT: FlutterBy.Text (Increment 1)"));

            AssertCounterIs("1", because: "we pressed the Add+1 button");
        }
Esempio n. 5
0
        public void ByValueKey()
        {
            // Text
            FlutterDriver.Click(FlutterBy.ValueKey("FUT: FlutterBy.ValueKey (Increment 2)"));

            AssertCounterIs("2", because: "we pressed the Add+2 button");
        }
Esempio n. 6
0
        private Position GetAndAssertPositionResult(FlutterBy by, string position)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            var result = ExecuteScript(position, by.ToBase64());;

            if (result == null)
            {
                throw new System.InvalidCastException($"Position APIs are expected to return a Dictionary<string, object> but returned null. ");
            }

            var dictionary = result as Dictionary <string, object>;

            if (dictionary == null)
            {
                throw new System.InvalidCastException($"Position APIs are expected to return a Dictionary<string, object> but instead returned type {result.GetType().FullName}");
            }

            if (!dictionary.ContainsKey("dx") || !dictionary.ContainsKey("dy"))
            {
                throw new System.InvalidOperationException($"The response was of type Dictionary<string, object> but did not contain both a 'dx' and 'dy' property as expected. ");
            }

            dictionary.ToList().ForEach(pair =>
            {
                Console.WriteLine($"key: {pair.Key}, value: {pair.Value}");
            });

            return(new Position(dx: System.Convert.ToDouble(dictionary["dx"]), dy: System.Convert.ToDouble(dictionary["dy"])));
        }
Esempio n. 7
0
        public void NavigateToTextTestPage()
        {
            FlutterDriver.Click(FlutterBy.Text("Navigate to Taps Test Page"));

            FlutterDriver.WaitFor(FlutterBy.Text("Taps Page"));

            FlutterDriver.GetText(FlutterBy.ValueKey("tapCounter")).Should().Be("0", because: "the counter is initially 0");
        }
Esempio n. 8
0
        public void GetSemanticsId_ByScript()
        {
            var result = FlutterDriver.ExecuteScript("flutter:getSemanticsId", FlutterBy.Tooltip("FUT: FlutterBy.Tooltip (Increment 3)").ToBase64());

            result.Should().BeOfType(typeof(long));

            ((long)result).Should().NotBe(0);
        }
Esempio n. 9
0
        public void ShortAndLongPress()
        {
            var touchActions = new FlutterTouchActions().Tap(TapControl).LongPress(TapControl);

            FlutterDriver.Perform(touchActions);

            FlutterDriver.GetText(FlutterBy.ValueKey("tapCounter")).Should().Be("11", because: "because a tap and long press will increase the counter by 11 (1 + 10)");
        }
Esempio n. 10
0
        public void Tap()
        {
            var touchActions = new FlutterTouchActions().Tap(TapControl);

            FlutterDriver.Perform(touchActions);

            FlutterDriver.GetText(FlutterBy.ValueKey("tapCounter")).Should().Be("1", because: "because a short tap will increase the counter by 1");
        }
Esempio n. 11
0
        public void WaitFor(FlutterBy by, int timeoutInSeconds)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            // TODO: Can we capture and forward on a more useful error message?
            ExecuteScript("flutter:waitFor", by.ToBase64(), timeoutInSeconds);
        }
Esempio n. 12
0
        public void SetupScreenshotTests()
        {
            // NOTE: If we take the screenshot immediately on app startup, we occasionally get this error:
            // Original error: {"code":-32000,"message":"Could not capture image screenshot."}
            //
            // So its better to wait for some state to converge first
            FlutterDriver.WaitFor(FlutterBy.Text("Navigate to Finders and Position Test Page"));

            OutputPath = System.IO.Path.Combine(TestContext.TestRunResultsDirectory, $"{DateTime.Now.ToString("yyyyMMddHHmmss")}.png");
        }
Esempio n. 13
0
        public long GetSemanticsId(FlutterBy by)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            var response = ExecuteScript("flutter:getSemanticsId", by.ToBase64());

            return((long)response);
        }
Esempio n. 14
0
        public void Click(FlutterBy by)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            var response = Execute(DriverCommand.ClickElement, new Dictionary <string, object>()
            {
                { "id", by.ToBase64() }
            });
        }
Esempio n. 15
0
        public void SendKeys(FlutterBy by, string keys)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            Execute(DriverCommand.SendKeysToElement, new Dictionary <string, object>()
            {
                { "id", by.ToBase64() },
                { "text", keys }
            });
        }
Esempio n. 16
0
        public void PageBack()
        {
            // NodeJs Snippet:
            // console.log(find.pageBack())

            // Output:
            // eyJmaW5kZXJUeXBlIjoiUGFnZUJhY2sifQ
            var asPageBackFinder = FlutterBy.PageBack();

            var asBase64 = asPageBackFinder.ToBase64();

            asBase64.Should().Be("eyJmaW5kZXJUeXBlIjoiUGFnZUJhY2sifQ", because: "the Base64 Serialization should match the NodeJs version");
        }
Esempio n. 17
0
        public void ByValueKeyIsInt()
        {
            // NodeJs Snippet:
            // const anIntValueKeyFinder = find.byValueKey(100);
            // console.log("The Counter Int String: " + anIntValueKeyFinder);

            // Output:
            // The Counter Int String: eyJmaW5kZXJUeXBlIjoiQnlWYWx1ZUtleSIsImtleVZhbHVlU3RyaW5nIjoxMDAsImtleVZhbHVlVHlwZSI6ImludCJ9
            var asFlutterFinder = FlutterBy.ValueKey(100);

            var asBase64 = asFlutterFinder.ToBase64();

            asBase64.Should().Be("eyJmaW5kZXJUeXBlIjoiQnlWYWx1ZUtleSIsImtleVZhbHVlU3RyaW5nIjoxMDAsImtleVZhbHVlVHlwZSI6ImludCJ9", because: "the Base64 Serialization should match the NodeJs version");
        }
Esempio n. 18
0
        public string GetText(FlutterBy by)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            var response = Execute(DriverCommand.GetElementText, new Dictionary <string, object>()
            {
                { "id", by.ToBase64() }
            });

            return($"{response.Value}");
        }
Esempio n. 19
0
        public void GetRenderObjectDiagnostics_Javascript()
        {
            var by = FlutterBy.ValueKey("counter");

            var response = FlutterDriver.ExecuteScript("flutter:getRenderObjectDiagnostics", by.ToBase64(), new Dictionary <string, object>()
            {
                { "includeProperties", true },
                { "subtreeDepth", 2 }
            });

            var responseAsDictionary = response as Dictionary <string, object>;

            AssertGetRenderObjectDiagnosticsResponse(responseAsDictionary);
        }
Esempio n. 20
0
        public void ByValueKeyIsString()
        {
            // NodeJs Snippet:
            // const aStringValueKeyFinder = find.byValueKey('counter');
            // console.log("The Counter Text String: " + aStringValueKeyFinder);

            // Output:
            // The Counter Text String: eyJmaW5kZXJUeXBlIjoiQnlWYWx1ZUtleSIsImtleVZhbHVlU3RyaW5nIjoiY291bnRlciIsImtleVZhbHVlVHlwZSI6IlN0cmluZyJ9
            var asFlutterFinder = FlutterBy.ValueKey("counter");

            var asBase64 = asFlutterFinder.ToBase64();

            asBase64.Should().Be("eyJmaW5kZXJUeXBlIjoiQnlWYWx1ZUtleSIsImtleVZhbHVlU3RyaW5nIjoiY291bnRlciIsImtleVZhbHVlVHlwZSI6IlN0cmluZyJ9", because: "the Base64 Serialization should match the NodeJs version");
        }
Esempio n. 21
0
        public Dictionary <string, object> GetRenderObjectDiagnostics(FlutterBy by, bool includeProperties = true, int subtreeDepth = 2)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            var raw = ExecuteScript("flutter:getRenderObjectDiagnostics", by.ToBase64(), new Dictionary <string, object>()
            {
                { "includeProperties", includeProperties },
                { "subtreeDepth", subtreeDepth }
            });

            var response = raw as Dictionary <string, object>;

            return(response);
        }
Esempio n. 22
0
        public IFlutterTouchActions LongPress(FlutterBy by)
        {
            if (null == by)
            {
                throw new System.ArgumentNullException(nameof(by));
            }

            Actions.Add(new Dictionary <string, object>()
            {
                { "action", "longPress" },
                { "options", new Dictionary <string, object>()
                  {
                      { "element", by.ToBase64() }
                  } }
            });

            return(this);
        }
Esempio n. 23
0
        public void BySemanticsLabel_NotRegularExpression(string inputText, string nodeOutputAsBase64)
        {
            // NodeJs Snippet:
            // console.log(find.bySemanticsLabel(null))
            // console.log(find.bySemanticsLabel(""))
            // console.log(find.bySemanticsLabel(" "))
            // console.log(find.bySemanticsLabel("theSemanticsLabel"))

            // Output:
            // eyJmaW5kZXJUeXBlIjoiQnlTZW1hbnRpY3NMYWJlbCIsImlzUmVnRXhwIjpmYWxzZSwibGFiZWwiOm51bGx9
            // eyJmaW5kZXJUeXBlIjoiQnlTZW1hbnRpY3NMYWJlbCIsImlzUmVnRXhwIjpmYWxzZSwibGFiZWwiOiIifQ
            // eyJmaW5kZXJUeXBlIjoiQnlTZW1hbnRpY3NMYWJlbCIsImlzUmVnRXhwIjpmYWxzZSwibGFiZWwiOiIgIn0
            // eyJmaW5kZXJUeXBlIjoiQnlTZW1hbnRpY3NMYWJlbCIsImlzUmVnRXhwIjpmYWxzZSwibGFiZWwiOiJ0aGVTZW1hbnRpY3NMYWJlbCJ9
            var asResult = FlutterBy.SemanticsLabel(inputText);

            var asBase64 = asResult.ToBase64();

            asBase64.Should().Be(nodeOutputAsBase64, because: "the Base64 Serialization should match the NodeJs version");
        }
Esempio n. 24
0
        public void ByText(string inputText, string nodeOutputAsBase64)
        {
            // NodeJs Snippet:
            // console.log(find.byText(null))
            // console.log(find.byText(""))
            // console.log(find.byText(" "))
            // console.log(find.byText("theText"))

            // Output:
            // eyJmaW5kZXJUeXBlIjoiQnlUZXh0IiwidGV4dCI6bnVsbH0
            // eyJmaW5kZXJUeXBlIjoiQnlUZXh0IiwidGV4dCI6IiJ9
            // eyJmaW5kZXJUeXBlIjoiQnlUZXh0IiwidGV4dCI6IiAifQ
            // eyJmaW5kZXJUeXBlIjoiQnlUZXh0IiwidGV4dCI6InRoZVRleHQifQ
            var asPageBackFinder = FlutterBy.Text(inputText);

            var asBase64 = asPageBackFinder.ToBase64();

            asBase64.Should().Be(nodeOutputAsBase64, because: "the Base64 Serialization should match the NodeJs version");
        }
Esempio n. 25
0
        public void ByTooltip(string inputText, string nodeOutputAsBase64)
        {
            // NodeJs Snippet:
            // console.log(find.byTooltip(null))
            // console.log(find.byTooltip(""))
            // console.log(find.byTooltip(" "))
            // console.log(find.byTooltip("theText"))

            // Output:
            // eyJmaW5kZXJUeXBlIjoiQnlUb29sdGlwTWVzc2FnZSIsInRleHQiOm51bGx9
            // eyJmaW5kZXJUeXBlIjoiQnlUb29sdGlwTWVzc2FnZSIsInRleHQiOiIifQ
            // eyJmaW5kZXJUeXBlIjoiQnlUb29sdGlwTWVzc2FnZSIsInRleHQiOiIgIn0
            // eyJmaW5kZXJUeXBlIjoiQnlUb29sdGlwTWVzc2FnZSIsInRleHQiOiJ0aGVUZXh0In0
            var asPageBackFinder = FlutterBy.Tooltip(inputText);

            var asBase64 = asPageBackFinder.ToBase64();

            asBase64.Should().Be(nodeOutputAsBase64, because: "the Base64 Serialization should match the NodeJs version");
        }
Esempio n. 26
0
        private void AssertCounterIs(string value, string because)
        {
            var result = FlutterDriver.GetText(FlutterBy.ValueKey("counter"));

            result.Should().Be(value, because);
        }
Esempio n. 27
0
        public void GetSemanticsId_Driver()
        {
            var semanticsId = FlutterDriver.GetSemanticsId(FlutterBy.Type("FlatButton"));

            semanticsId.Should().NotBe(0);
        }
Esempio n. 28
0
        public void PageBack()
        {
            FlutterDriver.Click(FlutterBy.PageBack());

            FlutterDriver.WaitFor(FlutterBy.Text("Navigate to Finders and Position Test Page"));
        }
Esempio n. 29
0
        public void NavigateToPageback()
        {
            FlutterDriver.Click(FlutterBy.Text("Navigate to Finders and Position Test Page"));

            FlutterDriver.WaitForAbsent(FlutterBy.Text("Navigate to Finders and Position Test Page"));
        }
Esempio n. 30
0
 public void NavigateToFindersPage()
 {
     FlutterDriver.Click(FlutterBy.Text("Navigate to Finders and Position Test Page"));
 }