webdriver_1.0.0_dabe4682/example/test.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
with Ada.Wide_Wide_Text_IO;

with League.Strings;
with League.JSON.Arrays;
with League.JSON.Objects;
with League.JSON.Values;

with WebDriver.Drivers;
with WebDriver.Elements;
with WebDriver.Remote;
with WebDriver.Sessions;

procedure Test is
   function "+"
     (Text : Wide_Wide_String) return League.Strings.Universal_String
      renames League.Strings.To_Universal_String;

   function Headless return League.JSON.Values.JSON_Value;

   --------------
   -- Headless --
   --------------

   function Headless return League.JSON.Values.JSON_Value is
      Cap      : League.JSON.Objects.JSON_Object;
      Options  : League.JSON.Objects.JSON_Object;
      Args     : League.JSON.Arrays.JSON_Array;
   begin
      return Cap.To_JSON_Value;
      pragma Warnings (Off);
      Args.Append (League.JSON.Values.To_JSON_Value (+"--headless"));
      Args.Append (League.JSON.Values.To_JSON_Value (+"--disable-extensions"));
      Args.Append (League.JSON.Values.To_JSON_Value (+"--no-sandbox"));
      Options.Insert (+"args", Args.To_JSON_Value);
      Options.Insert
        (+"binary",
         League.JSON.Values.To_JSON_Value
           (+"/usr/lib64/chromium-browser/headless_shell"));
      Cap.Insert (+"chromeOptions", Options.To_JSON_Value);
      return Cap.To_JSON_Value;
   end Headless;

   Web_Driver : aliased WebDriver.Drivers.Driver'Class
     := WebDriver.Remote.Create (+"http://127.0.0.1:9515");
   Session    : constant WebDriver.Sessions.Session_Access :=
     Web_Driver.New_Session (Headless);
begin
   Session.Go (+"http://www.ada-ru.org/");

   Ada.Wide_Wide_Text_IO.Put_Line
     (Session.Get_Current_URL.To_Wide_Wide_String);

   declare
      Body_Element : constant WebDriver.Elements.Element_Access :=
        Session.Find_Element
          (Strategy => WebDriver.Tag_Name,
           Selector => +"body");
   begin
      Ada.Wide_Wide_Text_IO.Put_Line
        ("Selected=" & Boolean'Wide_Wide_Image (Body_Element.Is_Selected));
      Ada.Wide_Wide_Text_IO.Put_Line
        ("itemtype=" &
           Body_Element.Get_Attribute (+"itemtype").To_Wide_Wide_String);
      Ada.Wide_Wide_Text_IO.Put_Line
        ("height=" &
           Body_Element.Get_CSS_Value (+"height").To_Wide_Wide_String);
      Ada.Wide_Wide_Text_IO.Put_Line
        ("tag=" & Body_Element.Get_Tag_Name.To_Wide_Wide_String);
   end;
end Test;