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
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
extern crate base64;

use serde::{Serialize,Deserialize};
use super::reqs::*;
use std::collections::HashMap;
use self::utils::*;
use super::element::*;
use super::actions::*;
use super::specialkey::*;
use super::chromeoptions::*;
use super::firefoxoptions::*;
use super::safarioptions::*;

#[derive(Serialize,Deserialize)]
struct Value{
     value: Session,
    
}
#[allow(non_snake_case)]
#[derive(Serialize,Deserialize)]
struct Session{
    sessionId: String,
}

pub enum BrowserName{
    Chrome,
    Firefox,
    Safari
}
/// Main crate struct

/// 

/// Contains methods for manipulating the browser session, internally making requests to the selenium server.

/// 

#[derive(Debug)]
pub struct Browser{
    session_url: String, //The session/ url for constructing other urls

    go_to_url: String, //The url to a website of the test

    timeouts_url: String,
    back_url: String,
    forward_url: String,
    refresh_url:String,
    title_url:String,
    window_url:String,
    window_handles_url:String,
    window_new_url:String,
    window_rect_url:String,
    frame_url:String,
    frame_parent_url:String,
    window_maximize_url:String,
    window_minimize_url:String,
    window_fullscreen_url:String,
    element_url:String,
    element_active_url:String,
    elements_url:String,
    source_url:String,
    execute_sync_url:String,
    execute_async_url:String,
    cookie_url:String,
    actions_url:String,
    alert_dismiss_url:String,
    alert_accept_url:String,
    alert_text_url:String,
    screenshot_url:String,
    print_page_url:String,
}

impl Browser{
    /// Method to construct the Browser instance with basic session. Supports args for Chrome,

    /// while for Firefox and Safari they will be ignored. To customize the Chrome and Firefox sessions pls use the corresponding

    /// method start_..._session_with_options().

    ///  

    /// # Examples

    /// ```

    /// # use selenium_webdriver::*;

    /// let mut browser = Browser::start_session(BrowserName::Chrome,vec!["--headless"]);

    /// browser.close_browser();

    /// ```

    pub fn start_session(browser: BrowserName, args:Vec<&str>)->Browser{
        let req_body = create_session_body_json(browser,args);
        let response = send_request(Method::POST, "wd/hub/session", cont_length_header(&req_body), &req_body).unwrap();
        let resp_body = resp_body(response).unwrap();
        let val: Value = serde_json::from_str(&resp_body).unwrap();
        let sess_id = val.value.sessionId;
        generate_browser_links(&sess_id)
    }
    ///Method to start the session customized with ChromeOptions

    /// 

    /// # Examples

    /// ```

    /// # use selenium_webdriver::*;

    /// let mut ch = ChromeOptions::new();

    /// let mob = MobileDevice::standard_device("Nexus 6");

    /// ch.add_args(vec!["--headless","--window-size=400,600"]);

    /// ch.add_mobile_emulation(mob);

    /// let mut br = Browser::start_chrome_session_with_options(ch).unwrap();

    /// let res = br.open("https://vk.com");

    /// let res2 = br.close_browser();

    /// assert!(res.is_ok()&&res2.is_ok());

    /// 

    /// ```

    pub fn start_chrome_session_with_options(options:ChromeOptions)->Result<Browser,String>{
        let body = create_json_body_for_session_with_chrome_options(options);
        let resp = send_and_read_body (Method::POST, "wd/hub/session", cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        let val: Value = serde_json::from_str(&resp).unwrap();
        let sess_id = val.value.sessionId;
        Ok(generate_browser_links(&sess_id))
    }
    /// Method to start the Firefox session adjusted with FirefoxOptions

    /// Works similar to the ChromeOptions. For more info please check the FirefoxOptions docs.

    pub fn start_firefox_session_with_options(options:FirefoxOptions)->Result<Browser,String>{
        let body = create_json_body_for_session_with_firefox_options(options);
        let resp = send_and_read_body (Method::POST, "wd/hub/session", cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        let val: Value = serde_json::from_str(&resp).unwrap();
        let sess_id = val.value.sessionId;
        Ok(generate_browser_links(&sess_id))
    }
    /// Method to start the Safari with settings.

    /// Works similar to the ChromeOptions and FFOptions. For more info please check the SafariOptions docs.

    pub fn start_safari_session_with_options(options:SafariOptions)->Result<Browser,String>{
        let body = options.base_string;
        let resp = send_and_read_body (Method::POST, "wd/hub/session", cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        let val: Value = serde_json::from_str(&resp).unwrap();
        let sess_id = val.value.sessionId;
        Ok(generate_browser_links(&sess_id))
    }

    ///Open a webpage or a local file

    pub fn open(&self,uri:&str)->Result<(),String>{
        let body = format!(r#"{{"url":"{}"}}"#,uri);
        let resp = send_request(Method::POST, &self.go_to_url, cont_length_header(&body), &body).unwrap();
        if resp.contains("error"){return Err(resp);}
        Ok(())
    }
    ///Get the url of the current page.

    pub fn get_link(&self)->Result<String,String>{
        let resp = resp_body(send_request(Method::GET, &self.go_to_url, vec![], "").unwrap()).unwrap();
        if resp.contains("error"){return Err(resp);}
        Ok(parse_value(&resp).replace("\"",""))
    }
    ///Deletes current session. As the Browser struct needs dropping, 

    ///it is better to call drop() after this method in long-multibrowser scenarios.  

    pub fn close_browser(&mut self)->Result<(),String>{
        let resp = send_request(Method::DELETE, &self.session_url, vec![], "").unwrap();
        if resp.contains("error"){return Err(resp);}
        self.session_url = String::from("");
        Ok(())
    }
    ///Returns the session timouts data

    pub fn get_timeouts(&self)->Result<Timeouts,String>{
        let resp = send_and_read_body(Method::GET, &self.timeouts_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        Ok(serde_json::from_str(&parse_value(&resp)).unwrap())
    }
    ///Change the session timouts data

    pub fn set_timeouts(&self, timeouts: &Timeouts)->Result<(),&str>{
        let timeouts_json = serde_json::to_string(timeouts).unwrap();
        if let Ok(mess)= send_request(Method::POST, &self.timeouts_url, cont_length_header(&timeouts_json), &timeouts_json){
            if let Ok (body) = resp_body(mess){
                if body.as_str() == r#"{"value":null}"#{
                    return Ok(())
                }
            }
        }
        Err("The timeouts were not set correctly")
    }
    ///Return to the previous page

    pub fn back(&self)->Result<(),String>{
        let body = r#"{"return":true}"#;
        let resp = send_request(Method::POST,&self.back_url, cont_length_header(&body), &body).unwrap();
        if resp.contains("error"){return Err(resp);}
        Ok(())
    }
    pub fn forward(&self)->Result<(),String>{
        let body = r#"{"forward":true}"#;
        let resp = send_request(Method::POST,&self.forward_url, cont_length_header(&body), &body).unwrap();
        if resp.contains("error"){return Err(resp);}
        Ok(())
    }
    pub fn refresh(&self)->Result<(),&str>{
        let body = r#"{"refresh":true}"#;
        if let Ok (mess) = send_request(Method::POST,&self.refresh_url, cont_length_header(&body), &body){
            if let Ok (body) = resp_body(mess){
                if body.as_str()!=r#"{"value":null}"#{
                   return Err("The refresh did not succeed")
                }
            }
        }
        Ok(())
    }
    ///Returns the title of the current tab

    pub fn get_title(&self)->Result<String,String>{
        let json = resp_body(send_request(Method::GET, &self.title_url, vec![], "").unwrap()).unwrap();
        if json.contains("error"){return Err(json);}    
        Ok(parse_value(&json).replace("\"",""))
    }
    ///Returns the handle of the current window, which later may be used to switch to this window.

    pub fn get_window_handle(&self)->Result<String,String>{
        let resp = send_and_read_body(Method::GET, &self.window_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        Ok(parse_value(&resp).replace("\"",""))
    }
    ///Returns the handles of all open windows and tabs

    pub fn get_window_handles(&self)->Result<Vec<String>,String>{
       let resp = send_and_read_body(Method::GET, &self.window_handles_url, vec![], "");
       if resp.contains("error"){return Err(resp);}
       let resp = parse_value(&resp);
       let res:Vec<String> = serde_json::from_str(&resp).unwrap();
       Ok(res)
    }
    ///Switches to the window with the passed id

    pub fn switch_to_window(&self, window_id: String)->Result<(),String>{
        let body = format!(r#"{{"handle":"{}"}}"#,window_id);
        let resp = send_and_read_body(Method::POST, &self.window_url, cont_length_header(&body), &body);
        if resp.as_str()==r#"{"value":null}"#{
            Ok(())
        }else{Err(resp)}
    }
    ///Opens a new window or a new tab depending on the window_type

    pub fn new_window(&self, window_type: NewWindowType)->Result<(String,String),String>{
        let body = match window_type{
            NewWindowType::Tab=>r#"{"type":"tab"}"#,
            NewWindowType::Window=>r#"{"type":"window"}"#,
        };
        let resp=send_and_read_body(Method::POST, &self.window_new_url, cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        let resp = parse_value(&resp);
        let map: HashMap<&str,String> = serde_json::from_str(&resp).unwrap();
        let handle = map.get("handle").unwrap().clone();
        let wtype = map.get("type").unwrap().clone();
        Ok((handle,wtype))
    }
    ///Closes the window and returns the vector of the remaining window handles

    pub fn close_window(&self)->Result<Vec<String>,String>{
       let resp = send_and_read_body(Method::DELETE, &self.window_url, vec![], "");
       if resp.contains("error"){return Err(resp);}
       let resp = parse_value(&resp);
       let res:Vec<String> = serde_json::from_str(&resp).unwrap();
       Ok(res)
    }
    ///Switches to the frame with a given id. For instance, if there are 4 frames and you wish to switch to the second one,

    /// you should call this method like this - switch_to_frame_by_id(1).

    pub fn switch_to_frame_by_id(&self, id: u64)->Result<(),String>{
        let body = format!(r#"{{"id":{}}}"#,id);
        let resp = send_and_read_body(Method::POST, &self.frame_url, cont_length_header(&body), &body);
        if resp.as_str()!=r#"{"value":null}"#{
            return Err(resp);
        }
        Ok(())
    }
    pub fn switch_to_frame_by_element(&self, element:Element)->Result<(),String>{
        let body = format!(r#"{{"id":{{"{}":"{}"}}}}"#,element.element_gr_id,element.element_id);
        let resp = send_and_read_body(Method::POST, &self.frame_url, cont_length_header(&body), &body);
        if resp.as_str()!=r#"{"value":null}"#{
            return Err(resp);
        }
        Ok(())

    }
    pub fn switch_to_parent_frame(&self)->Result<(),String>{
        let body = r#"{}"#;
        let resp = send_and_read_body(Method::POST, &self.frame_parent_url, cont_length_header(&body), &body);
        if resp.as_str()!=r#"{"value":null}"#{
            return Err(resp);
        }
        Ok(())
    }
    pub fn get_active_element(&self)->Result<Element,String>{
        let resp = send_and_read_body(Method::GET, &self.element_active_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        let resp = parse_value(&resp);
        let map: HashMap<String,String> = serde_json::from_str(&resp).unwrap();
        let res = map.iter().next().unwrap();
        Ok(Element{
            element_gr_id:res.0.clone(),
            element_id:res.1.clone(),
            element_url: format!("{}/element/{}",self.session_url,res.1.clone()),
        })
    }
    ///If the locator matches several elements, it returns the first one

    /// 

    /// # Examples

    /// ```

    /// # use selenium_webdriver::*;

    /// 

    ///let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);

    ///br.open("https://vk.com").unwrap();

    ///let el = br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();

    ///let res = el.click(); 

    ///br.close_browser().unwrap();

    ///assert!(res.is_ok()); 

    /// ```

    pub fn find_element(&self,loc_strategy:LocatorStrategy)->Result<Element,String>{
        let body = body_for_find_element(loc_strategy);
        let resp = send_and_read_body(Method::POST, &self.element_url, cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        let resp = parse_value(&resp);
        let map: HashMap<String,String> = serde_json::from_str(&resp).unwrap();
        let res = map.iter().next().unwrap();
        Ok(Element{
            element_gr_id:res.0.clone(),
            element_id:res.1.clone(),
            element_url: format!("{}/element/{}",self.session_url,res.1.clone()),
        })
    }
    pub fn find_elements(&self,loc_strategy:LocatorStrategy)->Result<Vec<Element>,String>{
        let mut result = vec![];
        let body = body_for_find_element(loc_strategy);
        let resp=send_and_read_body(Method::POST, &self.elements_url, cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        let resp = parse_value(&resp);
        let map: Vec<HashMap<String,String>> = serde_json::from_str(&resp).unwrap();
        let element_ur = format!("{}/element",self.session_url);
        for i in map{
            let element_ur = element_ur.clone();
            let res = i.iter().next().unwrap();
            result.push(Element{
            element_gr_id:res.0.clone(),
            element_id:res.1.clone(),
            element_url:format!("{}/{}",element_ur,res.1.clone()),
            });
        }
        Ok(result)
    }
    ///Returns the WindowRect instance which contains the information about the position and size of the current window

    pub fn get_window_rect(&self)->Result<WindowRect,String>{
        let resp = send_and_read_body(Method::GET, &self.window_rect_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        let map:HashMap<&str,WindowRect> = serde_json::from_str(&resp).unwrap();
        Ok(map.get("value").unwrap().clone())
    }
    ///Allow to resize the window and change it's position

    pub fn set_sindow_rect(&self, window_rect:&WindowRect)->Result<WindowRect,String>{
        let body = serde_json::to_string(window_rect).unwrap();
        let resp = send_and_read_body(Method::POST, &self.window_rect_url, cont_length_header(&body), &body);
        let resp = parse_value(&resp);
        let map:Result<WindowRect,serde_json::Error> = serde_json::from_str(&resp);
        match map{
            Ok(cont)=>{
                Ok(cont)
            },
            Err(message)=>Err(message.to_string()),
        }
                
    }
    pub fn maximize_window(&self)->Result<WindowRect,String>{
        let body = r#"{}"#;
        let resp = send_and_read_body(Method::POST, &self.window_maximize_url, cont_length_header(&body), &body);
        let resp = parse_value(&resp);
        if resp.contains("height")&&resp.contains("width"){
            let res: WindowRect = serde_json::from_str(&resp).unwrap();
            Ok(res)
        }else{Err(resp)}

    }
    pub fn minimize_window(&self)->Result<WindowRect,String>{
        let body = r#"{}"#;
        let resp = send_and_read_body(Method::POST, &self.window_minimize_url, cont_length_header(&body), &body);
        let resp = parse_value(&resp);
        if resp.contains("height")&&resp.contains("width"){
            let res: WindowRect = serde_json::from_str(&resp).unwrap();
            Ok(res)
        }else{Err(resp)}
    }
    pub fn fullscreen(&self)->Result<WindowRect,String>{
        let body = r#"{}"#;
        let resp = send_and_read_body(Method::POST, &self.window_fullscreen_url, cont_length_header(&body), &body);
        let resp = parse_value(&resp);
        if resp.contains("height"){
            Ok(serde_json::from_str(&resp).unwrap())
        } else {Err(resp)}
    }
    ///Returns the page source code

    pub fn source(&self)->Result<String,String>{
        let resp = send_and_read_body(Method::GET, &self.source_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        let map:HashMap<&str,String> = serde_json::from_str(&resp).unwrap();
        Ok(map.get("value").unwrap().clone())
    }
    ///Return the vector with all the cookies that the browser is holding at the moment

    pub fn get_all_cookies(&self)->Result<Vec<Cookie>,String>{
        let mut result: Vec<Cookie> = vec![];
        let resp = send_and_read_body(Method::GET, &self.cookie_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        let map:HashMap<&str,Vec<serde_json::Value>> = serde_json::from_str(&resp).unwrap();
        for v in map.get("value").unwrap(){
            result.push(from_value_to_cookie(v));
        }  
        Ok(result)
    }
    ///Returns the information on a particular cookie

    pub fn get_cookie(&self,cookie_name:&str)->Result<Cookie,String>{
        let url = format!("{}/{}",self.cookie_url,cookie_name);
        let resp = send_and_read_body(Method::GET, &url, vec![], "");
        if resp.contains("domain")&&resp.contains("expiry")&&resp.contains("name"){
            let map:HashMap<&str,serde_json::Value> = serde_json::from_str(&resp).unwrap();
            let v = map.get(&"value").unwrap();
            return Ok(from_value_to_cookie(v));
        }
        Err(resp)
    }
    pub fn add_cookie(&self,cookie:Cookie)->Result<(),String>{
        let cook = serde_json::to_string(&cookie).unwrap();
        let body =format!(r#"{{"cookie": {} }}"#,cook);
        let resp = send_and_read_body(Method::POST, &self.cookie_url, cont_length_header(&body), &body);
        if resp==r#"{"value":null}"#{
            return Ok(());
        }
        Err(resp)
    }
    pub fn delete_cookie(&self,cookie_name:&str)->Result<(),String>{
        let uri = format!("{}/{}",self.cookie_url,cookie_name);
        let resp = send_and_read_body(Method::DELETE, &uri, vec![], "");
        if resp==r#"{"value":null}"#{
            return Ok(());
        }
        Err(resp)
    }
    pub fn delete_all_cookies(&self)->Result<(),String>{
        let resp = send_and_read_body(Method::DELETE, &self.cookie_url, vec![], "");
        if resp==r#"{"value":null}"#{
            return Ok(());
        }
        Err(resp)
    }
    ///The path should be absolute with the extension

    /// 

    /// # Examples

    /// ```

    /// # use selenium_webdriver::*;

    /// let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=7680,4320"]);

    /// br.open("https://vk.com").unwrap();

    /// br.take_screenshot("screen.png").unwrap();

    /// br.close_browser().unwrap();

    /// # std::fs::remove_file("screen.png").unwrap();

    /// ```

    pub fn take_screenshot(&self,path:&str)->Result<(),String>{
        if let Ok(resp) = send_request_screensh(Method::GET, &self.screenshot_url, vec![], ""){
             if let Ok(new) = base64::decode(resp){
                match std::fs::write(path,new){
                    Ok(())=>return Ok(()),
                    Err(message)=> return Err(message.to_string()),
                }
             }
        }
        Err(String::from("Could not take a screenshot"))     
    }
    pub fn take_element_screenshot(&self,elem:&Element,path: &str)->Result<(),String>{
        let uri = format!("{}/{}/screenshot",self.element_url,elem.element_id);
        if let Ok(resp) = send_request_screensh(Method::GET, &uri, vec![], ""){
            if let Ok(new) = base64::decode(resp){
                match std::fs::write(path,new){
                    Ok(())=>return Ok(()),
                    Err(message)=>return Err(message.to_string())
                }
            }
        }
        Err(String::from("Could not take a screenshot")) 
    }
    /// Executes the sync fun in the browser. In case the argument is a string, it should be a raw string or should incluse escapes with double quotes

    /// For example, if the args list you want to pass is [5,"Jack", 15], the vector should be ["5",r#"Jack"#,"15"]

    pub fn execute_sync(&self, script: &str, args: &Vec<&str>)->Result<String,String>{
        let args = gen_script_args(args);
        let body = format!(r#"{{"script":"{}","args":{}}}"#,script,args);
        let resp = send_and_read_body(Method::POST, &self.execute_sync_url, cont_length_header(&body), &body);
        if resp.contains("error"){
            return Err(resp);
        }
        Ok(resp)
    }
    ///Executes the async fun in the browser. The args should be passed similarly to the execute_sync fn.

    pub fn execute_async(&self, script: &str, args: &Vec<&str>)->Result<String,String>{
        let args = gen_script_args(args);
        let body = format!(r#"{{"script":"{}","args":{}}}"#,script,args);
        let resp = send_and_read_body(Method::POST, &self.execute_async_url, cont_length_header(&body), &body);
        if resp.contains("error"){
            return Err(resp);
        }
        Ok(resp)
    }
    ///Prints out the page. If you want to print it to pdf, use headless mode. The structs PrintSettings,Page and Margin allow you to customize the print.

    pub fn print(&self,print_settings:&PrintSettings,path:&str)->Result<(),String>{
        let pr_set_body = serde_json::to_string(&print_settings).unwrap();
        let resp = send_request_screensh(Method::POST, &self.print_page_url, cont_length_header(&pr_set_body), &pr_set_body).unwrap();
        let new = base64::decode(resp).unwrap();
        std::fs::write(path,new).unwrap();
        Ok(())
    }
    
}

impl Browser{
    pub fn dismiss_alert(&self)->Result<(),String>{
        let resp = send_and_read_body(Method::POST, &self.alert_dismiss_url, cont_length_header("{}"), "{}");
        if resp ==r#"{"value":null}"#{Ok(())}else{Err(resp)}
    }
    pub fn allow_alert(&self)->Result<(),String>{
        let resp = send_and_read_body(Method::POST, &self.alert_accept_url, cont_length_header("{}"), "{}");
        if resp ==r#"{"value":null}"#{Ok(())}else{Err(resp)}
    }
    pub fn get_alert_text(&self)->Result<String,String>{
        let resp = send_and_read_body(Method::GET, &self.alert_text_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        let map:HashMap<&str,String> = serde_json::from_str(&resp).unwrap();
        Ok((*map.get("value").unwrap()).to_string())
    }
    pub fn send_alert_text(&self,text:&str)->Result<(),String>{
        let body =format!(r#"{{"text":{}}}"#,text) ;
        let resp = send_and_read_body(Method::POST, &self.alert_dismiss_url, cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        Ok(())
    }
    /// Pls see the Actions struct page to learn how to properly construct the Actions instance. 

    /// # Examples

    /// ```

    /// # use selenium_webdriver::*;

    /// let mut actions = Actions::new();

    /// let mut actions_keys = ActionsKeys::new();

    /// actions_keys.press_special_key(SpecialKey::ShiftLeft);

    /// actions_keys.press_key("a");

    /// actions.add_key_actions(actions_keys);

    /// let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=1000,500"]);

    /// br.open("https:vk.com/").unwrap();

    /// br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap().click().unwrap();

    /// br.perform_actions(actions);

    /// br.close_browser().unwrap();

    /// ``` 

    pub fn perform_actions(&self,actions:Actions)->Result<(),String>{
        let mut actions = actions;
        actions.set_ids();
        let body = serde_json::to_string(&actions).unwrap();
        let resp = send_and_read_body(Method::POST, &self.actions_url, cont_length_header(&body), &body);
        if resp.contains("error"){return Err(resp);}
        Ok(())
    }
    ///Releases all the actions present in the current session's internal state.

    ///While the key actions are performed just after calling the perform_actions method,

    ///for instance, mouse actions are performed only after calling this method.

    pub fn release_actions(&self)->Result<(),String>{
        let resp = send_and_read_body(Method::DELETE, &self.actions_url, vec![], "");
        if resp.contains("error"){return Err(resp);}
        Ok(())
    }
}
pub (self) mod utils{
    use super::*;
    pub (super) fn generate_browser_links(sess_id:&str)->Browser{
        Browser{
            session_url:format!("wd/hub/session/{}",sess_id),
            go_to_url: format!("wd/hub/session/{}/url",sess_id),
            timeouts_url: format!("wd/hub/session/{}/timeouts",sess_id),
            back_url: format!("wd/hub/session/{}/back",sess_id),
            forward_url: format!("wd/hub/session/{}/forward",sess_id),
            refresh_url:format!("wd/hub/session/{}/refresh",sess_id),
            title_url:format!("wd/hub/session/{}/title",sess_id),
            window_url:format!("wd/hub/session/{}/window",sess_id),
            window_handles_url:format!("wd/hub/session/{}/window/handles",sess_id),
            window_new_url:format!("wd/hub/session/{}/window/new",sess_id),
            window_rect_url:format!("wd/hub/session/{}/window/rect",sess_id),
            frame_url:format!("wd/hub/session/{}/frame",sess_id),
            frame_parent_url:format!("wd/hub/session/{}/frame/parent",sess_id),
            window_maximize_url:format!("wd/hub/session/{}/window/maximize",sess_id),
            window_minimize_url:format!("wd/hub/session/{}/window/minimize",sess_id),
            window_fullscreen_url:format!("wd/hub/session/{}/window/fullscreen",sess_id),
            element_url:format!("wd/hub/session/{}/element",sess_id),
            element_active_url:format!("wd/hub/session/{}/element/active",sess_id),
            elements_url:format!("wd/hub/session/{}/elements",sess_id),
            source_url:format!("wd/hub/session/{}/source",sess_id),
            execute_sync_url:format!("wd/hub/session/{}/execute/sync",sess_id),
            execute_async_url:format!("wd/hub/session/{}/execute/async",sess_id),
            cookie_url:format!("wd/hub/session/{}/cookie",sess_id),
            actions_url:format!("wd/hub/session/{}/actions",sess_id),
            alert_dismiss_url:format!("wd/hub/session/{}/alert/dismiss",sess_id),
            alert_accept_url:format!("wd/hub/session/{}/alert/accept",sess_id),
            alert_text_url:format!("wd/hub/session/{}/alert/text",sess_id),
            screenshot_url:format!("wd/hub/session/{}/screenshot",sess_id),
            print_page_url:format!("wd/hub/session/{}/print",sess_id),
        }
    }
    pub (super) fn create_session_body_json(browser:BrowserName,args:Vec<&str>)->String{
            match browser{
                BrowserName::Chrome=> create_chrome_session(args),
                BrowserName::Firefox=>create_firefox_session(),
                BrowserName::Safari=>create_safari_session(),
            }
    }
    pub (super) fn create_chrome_session(args:Vec<&str>)->String{
            let one=format!(r#"{{"capabilities": {{"alwaysMatch":{{"platformName":"{}"}}"#,std::env::consts::OS);
            let args = gen_args(args);
            let two=format!(r#"{},"firstMatch":[{{"browserName":"chrome","goog:chromeOptions":{{"args":{}}}}}]}}}}"#,one,args);
            two
    }
    pub (super) fn create_firefox_session()->String{
        let one=format!(r#"{{"capabilities": {{"alwaysMatch":{{"platformName":"{}"}}"#,std::env::consts::OS);
        let two=format!(r#"{},"firstMatch":[{{"browserName":"firefox"}}]}}}}"#,one);
        two
    }
    pub (super) fn create_safari_session()->String{
        let one=format!(r#"{{"capabilities": {{"alwaysMatch":{{"platformName":"{}"}}"#,std::env::consts::OS);
        let two=format!(r#"{},"firstMatch":[{{"browserName":"safari"}}]}}}}"#,one);
        two
    }
    pub (super) fn create_json_body_for_session_with_chrome_options(chrome_options:ChromeOptions)->String{
        let mut options = chrome_options.string_for_session;
        options.pop();
        options.pop();
        options.push('}');
        let base_string = format!(r#"{{
            "capabilities": {{
                "alwaysMatch": {{
                    "platformName": "{}"
                }},
                "firstMatch": [
                    {{"browserName": "chrome",
                        {}
                    }}
                ]
            }}
        }}"#,std::env::consts::OS,options);
        base_string
    }
    pub (super) fn create_json_body_for_session_with_firefox_options(ff_options:FirefoxOptions)->String{
        let mut options = ff_options.string_for_session;
        options.pop();
        options.pop();
        options.push('}');
        let base_string = format!(r#"{{
            "capabilities": {{
                "alwaysMatch": {{
                    "platformName": "{}"
                }},
                "firstMatch": [
                    {{"browserName": "firefox",
                        {}
                    }}
                ]
            }}
        }}"#,std::env::consts::OS,options);
        base_string
    }
    pub (super) fn gen_args(args:Vec<&str>)->String{
            if args.len()==0{
                return String::from("[]");
            }
            let mut result = String::from("[");
            for arg in args{
                result.push_str("\"");
                result.push_str(arg);
                result.push_str("\"");
                result.push_str(",");
            }
            result.pop();
            result.push_str("]");
            result
    }
    pub (super) fn gen_script_args(args:&Vec<&str>)->String{
        if args.len()==0{
            return String::from("[]");
        }
        let mut result = String::from("[");
        let temp_result = args.join(",");
        result.push_str(&temp_result);
        result.push_str("]");
        result
    }
    pub (super) fn from_value_to_cookie(val: &serde_json::Value)->Cookie{
        let name = String::from(val["name"].as_str().unwrap());
        let value = String::from(val["value"].as_str().unwrap());
        let mut domain = String::from("");
        let mut expiry = 0;
        let mut http_only = false;
        let mut path = String::from("");
        let mut secure = false;
        let mut same_site = String::from("");
        if let Some(dom) = val["domain"].as_str(){
            domain=String::from(dom);
        }
        if let Some(exp) = val["expiry"].as_u64(){
            expiry=exp;
        }
        if let Some(http) = val["httpOnly"].as_bool(){
            http_only=http;
        }
        if let Some(pat) = val["path"].as_str(){
            path=String::from(pat);
        }
        if let Some(sec) = val["secure"].as_bool(){
            secure = sec;
        }
        if let Some(same) = val["sameSite"].as_str(){
            same_site=String::from(same);
        }
        Cookie{name,value,path,expiry,secure,domain,httpOnly: http_only,sameSite:same_site}
    }
}

///Needed to call the new_window method

pub enum NewWindowType{
    Tab,
    Window
}
///Utility struct representing window height,width,x-axis and y-axis

#[derive(Serialize,Deserialize,Debug,PartialEq,Clone)]
pub struct WindowRect{
    pub(self)height:i32,
    pub(self)width:i32,
    pub(self)x:i32,
    pub(self)y:i32
}
impl WindowRect{
    pub fn new(height:i32,width:i32,x:i32,y:i32)->WindowRect{
        WindowRect{ height, width, x, y}
    }
}
///Utility struct to manage session cookies

/// 

/// Includes two constructor methods and getters/setters for adjustments

#[allow(non_snake_case)]
#[derive(Serialize,Deserialize,Debug,Clone)]
pub struct Cookie{
    pub(self)domain:String,
    pub(self)expiry: u64,
    pub(self)httpOnly:bool,
    pub(self)name:String,
    pub(self)path:String,
    pub(self)secure:bool,
    pub(self)value:String,
    pub(self)sameSite:String,
}

impl Cookie{
    ///Create a cookie and initialize all its fields

    pub fn new_all(domain:String, expiry:u64,same_site:String, http_only:bool,name:String,path:String,secure:bool,value:String)->Self{
        Cookie{
            domain,
            expiry,
            httpOnly: http_only,
            name,
            path,
            sameSite:same_site,
            secure,
            value
        }
    }
    ///Create default cookie and set only name and value

    pub fn new(name:String,value:String)->Self{
        Cookie{name,value,..Default::default()}
    }

    pub fn get_domain(&self)->String{self.domain.clone()}
    pub fn get_expiry(&self)->u64{self.expiry}
    pub fn get_http_only(&self)->bool{self.httpOnly}
    pub fn get_name(&self)->String{self.name.clone()}
    pub fn get_path(&self)->String{self.path.clone()}
    pub fn get_secure(&self)->bool{self.secure}
    pub fn get_value(&self)->String{self.value.clone()}
    pub fn get_same_site(&self)->String{self.sameSite.clone()}


    pub fn set_domain(&mut self, domain:String){self.domain=domain;}
    pub fn set_expiry(&mut self, expiry: u64){self.expiry=expiry;}
    pub fn set_http_only(&mut self, http_only:bool){self.httpOnly=http_only;}
    pub fn set_path(&mut self, path: String){self.path=path;}
    pub fn set_secure(&mut self, secure: bool){self.secure=secure;}
    pub fn set_same_site(&mut self, same_site:String){self.sameSite=same_site;}
}
impl Default for Cookie{
    fn default()->Self{
        Cookie{
            domain:"".to_string(),
            expiry: 0,
            httpOnly: false,
            name:"".to_string(),
            path:"".to_string(),
            secure:false,
            value:"".to_string(),
            sameSite:"None".to_string(),
        }
    }
}
///Utility struct to manage the session's implicit, page load and script timeouts

#[allow(non_snake_case)]
#[derive(Serialize,Deserialize,Debug,PartialEq)]
pub struct Timeouts{
    implicit:u32,
    pageLoad:u32,
    script:u32,
}
impl Timeouts{
    ///Instantiates the Timeouts with all fields set

    pub fn set_all (implicit: u32, page_load: u32,script:u32)->Timeouts{
        Timeouts{
            implicit,
            pageLoad: page_load,
            script
        }
    }
    ///Instantiates the Timeouts with default timouts of a chrome session

    pub fn new ()->Timeouts{
        Timeouts{
            implicit:0,
            pageLoad: 300000,
            script: 30000,
        }
    }
    pub fn set_implicit(&mut self,implicit:u32){
        self.implicit=implicit;
    }
    pub fn set_page_load(&mut self,page_load:u32){
        self.pageLoad=page_load;
    }
    pub fn set_script(&mut self,script:u32){
        self.script=script;
    }

}
///Main struct for print settings

/// 

/// Has the default method with default WebDriver print settings and getters/setters for print adjustment.

#[allow(non_snake_case)]
#[derive(Serialize,Deserialize,Debug)]
pub struct PrintSettings{
    orientation:String,
    scale: f32,
    background: bool,
    page: Page,
    margin: Margin,
    shrinkToFit: bool,
    pages: Vec<u32>
}
impl PrintSettings{
    pub fn new(orientation: Orientation,scale: f32,background:bool,page:Page,margin:Margin,shrink_tf:bool,pages:Vec<u32>)->Self{
        if scale<0.1||scale>2.0{panic!("The condotion (0.1<=scale<= 2.0) is not fulfilled");}
        let orientation = match orientation{
            Orientation::PORTRAIT=>String::from("portrait"),
            Orientation::LANDSCAPE=>String::from("landscape"),
        };
        PrintSettings{orientation,scale,background,page,margin,shrinkToFit: shrink_tf,pages}
    }
    pub fn set_orientation(&mut self,orientation: Orientation){
        self.orientation = match orientation{
            Orientation::PORTRAIT=>String::from("portrait"),
            Orientation::LANDSCAPE=>String::from("landscape"),
        };
    }
    ///Should be between 0.1 and 2.0 inclusively

    pub fn set_scale(&mut self,scale:f32){
        if scale<0.1||scale>2.0{panic!("The condotion (0.1<=scale<= 2.0) is not fulfilled");}
        self.scale=scale;}
    ///Flags to include the background or not

    pub fn set_background(&mut self,background: bool){self.background=background;}
    pub fn set_page(&mut self,page:Page){self.page=page;}
    pub fn set_margin(&mut self,margin:Margin){self.margin=margin;}
    ///Flags whether the webpage should be shrunk if it does not fit the print page

    pub fn set_shrink_to_fit(&mut self,shr_to_fit:bool){self.shrinkToFit = shr_to_fit;}
    ///Sets the page range for printing

    pub fn set_pages(&mut self,pages:Vec<u32>){self.pages=pages;}
}

impl Default for PrintSettings{
    fn default()->Self{
        PrintSettings{
            orientation:String::from("portrait"),
            scale: 1.0,
            background: false,
            page: Page::default(),
            margin: Margin::default(),
            shrinkToFit: true,
            pages: vec![] 
        }
    }
}
///One of the PrintSettings fields

/// 

/// Includes the info about the page size

#[derive(Serialize,Deserialize,Debug)]
pub struct Page{
    width:f32,
    height:f32,
}
impl Page{
    pub fn new(width:f32, height: f32)->Self{
        if width<0.0||height<0.0{panic!("Width and height can't be less then 0.0");}
        Page{width,height}
    }
    pub fn set_width(&mut self,width:f32){
        if width<0.0{panic!("Width cannot be less then 0.0");}
        self.width = width;
    }
    pub fn set_height(&mut self,height:f32){
        if height<0.0{panic!("Height cannot be less then 0.0");}
        self.height = height;
    }
}
impl Default for Page{
    fn default()->Self{
        Page{width:21.59,height:27.94}
    }
}
/// One of the PrintSettings fields

/// 

/// Includes the info on margin sizes

#[derive(Serialize,Deserialize,Debug)]
pub struct Margin{
    top:u32,
    bottom:u32,
    left:u32,
    right:u32,
}
impl Margin{
    pub fn new(top:u32,bottom:u32,left:u32,right:u32)->Self{
        Margin{
            top,bottom,left,right
        }
    }
    pub fn set_top(&mut self,top:u32){self.top=top;}
    pub fn set_bottom(&mut self,bottom:u32){self.bottom=bottom}
    pub fn set_left(&mut self,left:u32){self.left=left;}
    pub fn set_right(&mut self,right:u32){self.right=right;}
}
impl Default for Margin{
    fn default()->Self{
        Margin{
            top:1,
            bottom:1,
            left:1,
            right:1,
        }
    }
}
///Needed for the PrintSettings struct

pub enum Orientation{
    PORTRAIT,
    LANDSCAPE
}

//TESTS

mod core_fns_tests{

    use super::*;
    use super::Element;
    use std::env::*;
    #[test]
    fn create_session() {
        let mut browser = Browser::start_session(BrowserName::Chrome,vec!["--headless"]);
        let sess:String; 
        {let mut iter = browser.session_url.split("/");
        iter.next();
        iter.next();
        iter.next();
        sess = iter.next().unwrap().to_string();}
        browser.close_browser().unwrap();
        
        assert_eq!(32,sess.len());
    }
    #[test]
    fn go_to_vk() {
        let mut browser = Browser::start_session(BrowserName::Chrome, vec!["--headless"]);
        browser.open("https://vk.com").unwrap();
        let link = browser.get_link().unwrap();
        browser.close_browser().unwrap();
        assert_eq!(link,"https://vk.com/");
    }
    #[test]
    #[should_panic]
    fn close_browser() {
        let mut browser = Browser::start_session(BrowserName::Chrome, vec!["--headless"]);
        browser.open("http://localhost:4444/wd/hub/status").unwrap();
        browser.close_browser().unwrap();        
        let a = browser.get_link().unwrap();
        if a.contains("invalid"){panic!("Invalid session id");}
    }
    #[test]
    fn args() {
        let a = vec!["--headless","--window-size=800,400"];        
        assert!(gen_args(a)==String::from("[\"--headless\",\"--window-size=800,400\"]"));
    }
    #[test]
    fn get_timeouts() {
        let timeouts:Timeouts;
        {
            let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
            timeouts= br.get_timeouts().unwrap();
            br.close_browser().unwrap();
        }
        assert!(timeouts.implicit==0&&timeouts.script==30000);
    }
    #[test]
    fn set_timeouts() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        let timeouts = Timeouts::set_all(1000, 3000, 300000);
        assert!(br.set_timeouts(&timeouts)==Ok(()));
        br.close_browser().unwrap();
    }
    #[test]
    fn check_timouts_init() {
        let mut t = Timeouts::new();
        assert_eq!(t,Timeouts{implicit:0,pageLoad:300000,script:30000});
        t.set_implicit(1);
        assert_eq!(t,Timeouts{implicit:1,pageLoad:300000,script:30000});
        t.set_page_load(1);
        assert_eq!(t,Timeouts{implicit:1,pageLoad:1,script:30000});
        t.set_script(1);
        assert_eq!(t,Timeouts{implicit:1,pageLoad:1,script:1});
    }
    #[test]
    fn back_test() {
        let link: String;
        {let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com/").unwrap();
        br.open("https://m.facebook.com/").unwrap();
        br.back().unwrap();
        link = br.get_link().unwrap();
        br.close_browser().unwrap();}
        assert_eq!(link.as_str(),"https://vk.com/");
    }
    #[test]
    fn forward_test() {
        let link: String;
        {let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com/").unwrap();
        br.open("https://m.facebook.com/").unwrap();
        br.back().unwrap();
        br.forward().unwrap();
        link = br.get_link().unwrap();        
        br.close_browser().unwrap();}
        assert_eq!(&link,"https://m.facebook.com/");
    }
    #[test]
    fn refresh_test() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com/").unwrap();
        assert_eq!(br.refresh(),Ok(()));
        br.close_browser().unwrap();
    }
    #[test]
    fn get_title_test() {
        let title:String;
        {let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://www.w3.org/TR/webdriver/").unwrap();
        title =br.get_title().unwrap();
        br.close_browser().unwrap();}
        assert_eq!(title,String::from("WebDriver"));
        
    }
    #[test]
    fn window_handle() {
        let handle: String;
        {let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        handle = br.get_window_handle().unwrap();
        br.close_browser().unwrap();}
        assert!(handle.starts_with("CDwindow"));
        
    }
    #[test]
    fn switch_window(){
        let res :Result<(),String>;
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let handle = br.get_window_handle().unwrap();
        res = br.switch_to_window(handle);assert_eq!(Ok(()),res);
        br.close_browser().unwrap();
    }
    #[test]
    fn get_handles() {
        let handles;
        {
            let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
            br.open("https://vk.com").unwrap();
            handles = br.get_window_handles();
            br.close_browser().unwrap();
        }
        let len = handles.unwrap().len();
        assert_eq!(len,1);
    }
    #[test]
    fn close_window() {
        let handles;
        {
            let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
            br.open("https://vk.com").unwrap();
            handles = br.close_window();
            br.close_browser().unwrap();
        }
        assert_eq!(handles.unwrap().len(),0);
    }
    #[test]
    fn new_window(){
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        let wind = br.new_window(NewWindowType::Tab).unwrap();
        assert!(wind.1=="tab"&&br.get_window_handles().unwrap().len()==2);
        br.close_browser().unwrap();
    }
    #[test]
    fn sw_to_frame_by_id() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://bash.im").unwrap();
        let res = br.switch_to_frame_by_id(0);
        br.close_browser().unwrap();
        assert_eq!(res,Ok(()));

    }
    #[test]
    fn sw_t_fr_by_el() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let el = br.find_element(LocatorStrategy::CSS("#quick_login_frame")).unwrap();
        let res = br.switch_to_frame_by_element(el);
        br.close_browser().unwrap();
        assert_eq!(res,Ok(()));
    }
    #[test]
    fn find_element() {
        let el;
        {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        el = br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();
        br.close_browser().unwrap();
        }
        let tr =el.element_gr_id.contains("element"); 
        assert!(tr);
    }
    #[test]
    fn find_els() {
        let el;
        {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        el = br.find_elements(LocatorStrategy::CSS("div")).unwrap();
        br.close_browser().unwrap();
        }
        let len = el.len();
        assert!(len>2);
    }
    #[test]
    fn sw_to_par_fr() {
        let res;
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        res = br.switch_to_parent_frame();
        br.close_browser().unwrap(); 
        assert_eq!(res, Ok(()));
    }
    #[test]
    fn get_wind_rect() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        let wr = br.get_window_rect().unwrap();
        br.close_browser().unwrap();
        assert!(wr==WindowRect{height:200,width:400,x:0,y:0});
    }
    #[test]
    fn set_wind_rect(){
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        let wr = WindowRect{height:600, width:1000,x:250,y:250};
        let wr_new = br.set_sindow_rect(&wr).unwrap();
        br.close_browser().unwrap();
        assert_eq!(wr,wr_new);
        
    }
    #[test]
    fn maximize() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        let a = br.maximize_window().unwrap();
        br.close_browser().unwrap();
        let wr = WindowRect{height:200, width:400,x:0,y:0};
        assert_eq!(a,wr);
    }
    #[test]
    fn parse_val_test() {
        let resp = r#"{
       "value": {
       "dftg43rert34tert-34trte-243f-4":
       {
        "id": 333
        }
      }
     }"#;
       let res = parse_value(resp);
       assert_eq!(res,"{\"dftg43rert34tert-34trte-243f-4\":{\"id\":333}}");
    }
    #[test]
    fn fullsize() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        let a = br.fullscreen().unwrap();
        br.close_browser().unwrap();
        assert!(a.x==0&&a.y==0);
    }

    #[test]
    fn src() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("http://localhost:4444/wd/hub/status").unwrap();
        let a = br.source().unwrap();
        br.close_browser().unwrap();
        assert!(a.contains("html")&&a.contains("head"))
    }

    #[test]
    fn script_test() {
        let script = "return 3+2";
        let res = vec!["5",r#""Hello""#];
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        let res = br.execute_sync(script, &res).unwrap();
        br.close_browser().unwrap();
        assert!(res.contains("5"));
    }
    
    #[test]
    fn cookies() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let cook = br.get_all_cookies().unwrap();
        br.close_browser().unwrap();
        assert!(cook.len()>1);
    }

    #[test]
    fn get_cookie() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let c = br.get_cookie("tmr_lvidTS").unwrap();
        br.close_browser().unwrap();
        assert_eq!(c.httpOnly,false);
    }

    #[test]
    fn add_cookie() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let cook = Cookie::new_all(String::from(""), 1000, String::from("Lax"), false, String::from("tmr_detect"), String::from(""), false, String::from("0%7C1604223632022"));
        assert_eq!(br.add_cookie(cook),Ok(()));
        br.close_browser().unwrap();
    }

    #[test]
    fn z_del_all_cook() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        br.delete_all_cookies().unwrap();
        let cook = br.get_all_cookies().unwrap();
        br.close_browser().unwrap();
        assert_eq!(cook.len(),0);
    }
    #[test]
    fn t_del_cookie() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let r = br.delete_cookie("remixjsp");
        br.close_browser().unwrap();
        assert!(r==Ok(()));
    }
    #[test]
    fn screensh() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=7680,4320"]);
        br.open("https://vk.com").unwrap();
        br.take_screenshot("screen.png").unwrap();
        br.close_browser().unwrap();
        let arr=std::fs::read("screen.png").unwrap().len();
        assert!(arr>0);
        std::fs::remove_file("screen.png").unwrap();
    }
    #[test]
    fn el_screensh() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=800,600"]);
        br.open("https://vk.com").unwrap();
        let el = br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();
        br.take_element_screenshot(&el,"element.png").unwrap();
        br.close_browser().unwrap();
        let arr=std::fs::read("element.png").unwrap().len();
        assert!(arr>0);
        std::fs::remove_file("element.png").unwrap();
    }
    #[test]
    fn pr_page() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=2400,1200"]);
        br.open("https://vk.com").unwrap();
        let mut p  = PrintSettings::default();
        p.set_orientation(Orientation::LANDSCAPE);
        p.set_pages(vec![1,2]);
        br.print(&p, "page.pdf").unwrap();
        br.close_browser().unwrap();
        let arr=std::fs::read("page.pdf").unwrap().len();
        assert!(arr>0);
        std::fs::remove_file("page.pdf").unwrap();
    }

    #[test]
    fn alerts() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let resp = br.dismiss_alert().is_err();
        let resp2 = br.allow_alert().is_err();
        br.close_browser().unwrap();
        assert!(resp&&resp2);
    }
    #[test]
    fn get_send_alert_text() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let resp = br.get_alert_text().is_err();
        let resp2 = br.send_alert_text("I am the text").is_err();
        br.close_browser().unwrap();
        assert!(resp&&resp2);
    }
    #[test]
    fn active_el() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
        br.open("https://vk.com").unwrap();
        let a = br.get_active_element().unwrap();
        br.close_browser().unwrap();
        assert!(a.element_gr_id.contains("element"));
    }
    #[test]
    fn find_sub_el() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let par_el= br.find_element(LocatorStrategy::CSS("#top_nav")).unwrap();
        let a = par_el.find_element_from_self(LocatorStrategy::CSS(".HeaderNav__item")).unwrap();
        br.close_browser().unwrap();
        assert!(a.element_gr_id.contains("element"));
    }
    #[test]
    fn sub_els() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://bash.im").unwrap();
        let par_el= br.find_element(LocatorStrategy::CSS("section.quotes")).unwrap();
        let a = par_el.find_elements_from_self(LocatorStrategy::CSS(".quote")).unwrap();
        br.close_browser().unwrap();
        let len  = a.len();
        assert!(len>2);
    }
    #[test]
    fn is_sel() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();
        let res = el.is_selected().unwrap();
        br.close_browser().unwrap();
        assert!(res==false);
    }
    #[test]
    fn get_arrtib() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS(".placeholder_content")).unwrap();
        let res = el.get_attribute("aria-hidde").unwrap();
        let res2 = el.get_attribute("aria-hidden").unwrap();
        br.close_browser().unwrap();
        assert!(res.as_str()=="null");
        assert!(res2.as_str()=="true");
    }
    #[test]
    fn get_property() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res_len = el.get_property("attributes").unwrap().len();
        let res_null = el.get_property("attributes2").unwrap();
        br.close_browser().unwrap();
        assert!(res_len>5000&&res_null.as_str()=="null");
    }
    #[test]
    fn get_css_property() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res = el.get_css_value("color").unwrap().contains("rgba");
        br.close_browser().unwrap();
        assert!(res);
    }
    #[test]
    fn get_el_text() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res = el.get_element_text().unwrap().contains("error");
        br.close_browser().unwrap();
        assert!(!res);
    }
    #[test]
    fn get_el_tag() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res = el.get_tag_name().unwrap().contains("error");
        br.close_browser().unwrap();
        assert!(!res);
    }
    #[test]
    fn get_el_rect() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res = el.get_element_rect().unwrap();
        br.close_browser().unwrap();
        assert!(res.height==140);
    }
    #[test]
    fn el_is_enabled() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res = el.is_enabled().unwrap();
        br.close_browser().unwrap();
        assert!(res);
    }
    #[test]
    fn get_comp_role() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res = el.get_computed_role();
        let res2 = el.get_computed_label();
        dbg!(&res);
        dbg!(&res2);
        br.close_browser().unwrap();
        assert!(res.is_err()&&res2.is_err());
    }
    #[test]
    fn click_test() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#index_login_form")).unwrap();
        let res = el.click();
        br.close_browser().unwrap();
        assert_eq!(res,Ok(()))
    }
    #[test]
    fn el_send_k() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();
        el.send_keys("Sup!").unwrap();
        br.close_browser().unwrap();
    }
    #[test]
    fn el_clear() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        br.open("https://vk.com").unwrap();
        let el= br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();
        let _ = el.send_keys("Sup!");
        el.clear_element().unwrap();
        br.close_browser().unwrap();
    }
    #[test]
    fn rel_actions() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=400,200"]);
        let res1 = br.release_actions();
        br.close_browser().unwrap();
        let res2 = br.release_actions();
        assert!(res1.is_ok()&&res2.is_err());
    }
    #[test]
    fn per_f_ac_with_keys() {
        let mut actions = Actions::new();
        let mut actions_keys = ActionsKeys::new();
        actions_keys.press_special_key(SpecialKey::ShiftLeft);
        actions_keys.press_key("a");
        actions_keys.release_special_key(SpecialKey::ShiftLeft);
        actions_keys.press_key("b");
        actions.add_key_actions(actions_keys);
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=1000,500"]);
        br.open("https:vk.com/").unwrap();
        br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap().click().unwrap();
        let res = br.perform_actions(actions);
        br.close_browser().unwrap();
        assert!(res.is_ok());
    }
    #[test]
    fn perf_mouse_act() {
        let mut actions = Actions::new();
        let mut actions_keys = ActionsMouse::new();
        actions_keys.press_mouse_button(MouseButton::Left);
        actions_keys.pause(10);
        actions_keys.move_mouse_to_point(200,300);
        actions_keys.press_mouse_button(MouseButton::Right);
        actions.add_mouse_actions(actions_keys);
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=1000,500"]);
        br.open("https:vk.com/").unwrap();
        let res = br.perform_actions(actions);
        let res2 = br.release_actions();
        br.close_browser().unwrap();
        assert!(res.is_ok()&&res2.is_ok());
    }
    #[test]
    fn keys_and_mouse_acts() {
        let mut actions = Actions::new();
        let mut keys = ActionsKeys::new();
        let mut mouse = ActionsMouse::new();
        keys.press_special_key(SpecialKey::ShiftLeft);
        keys.press_key("a");
        keys.release_special_key(SpecialKey::ShiftLeft);
        keys.press_key("b");
        mouse.pause(0);
        mouse.pause(0);
        mouse.press_mouse_button(MouseButton::Left);
        mouse.move_mouse_to_point(200,300);
        mouse.press_mouse_button(MouseButton::Right);
        actions.add_key_actions(keys);
        actions.add_mouse_actions(mouse);
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=1000,500"]);
        br.open("https:vk.com/").unwrap();
        let res = br.perform_actions(actions);
        let res2 = br.release_actions();
        br.close_browser().unwrap();
        assert!(res.is_ok()&&res2.is_ok());       
    }
    #[test]
    fn wheel_ac() {
        let mut actions = Actions::new();
        let mut wheel = ActionsWheel::new();
        wheel.scroll(0, 0, 100, 100).scroll(100, 100, 100, 100);
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=600,400"]);
        br.open("https://yandex.ru/").unwrap();
        actions.add_wheel_actions(wheel);
        let res = br.perform_actions(actions);
        br.close_browser().unwrap();
        assert!(res.is_ok());
    }
    #[test]
    fn move_mouse_to_el() {
        let mut actions = Actions::new();
        let mut mouse = ActionsMouse::new();
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=600,400"]);
        br.open("https://vk.com").unwrap();
        let el = br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();    
        mouse.move_mouse_to_element(&el).press_mouse_button(MouseButton::Left);
        actions.add_mouse_actions(mouse);
        let res = br.perform_actions(actions);
        let res2 = br.release_actions();
        br.close_browser().unwrap();
        assert!(res.is_ok());
        assert!(res2.is_ok());
    }
    #[test]
    fn dranddrop() {
        let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=1500,800"]);
        br.open("http://webdriveruniversity.com/Actions/index.html").unwrap();
        let mut actions = Actions::new();
        let mut mouse = ActionsMouse::new();
         let el = br.find_element(LocatorStrategy::CSS("div#draggable")).unwrap();
        let el_dest = br.find_element(LocatorStrategy::CSS("div#droppable")).unwrap(); 
        mouse.drag_n_drop(el, el_dest);
        actions.add_mouse_actions(mouse);
        let res = br.perform_actions(actions);
        let res2 = br.release_actions();
        br.close_browser().unwrap();
        assert!(res.is_ok());
        assert!(res2.is_ok());        
    }
}
mod additional_tests{
    use super::*;
    #[test]
    fn brow_chrome_opts() {
        let mut ch = ChromeOptions::new();
        let mob = MobileDevice::standard_device("Nexus 6");
        ch.add_args(vec!["--headless","--window-size=400,600"]);
        ch.add_mobile_emulation(mob);
        let mut br = Browser::start_chrome_session_with_options(ch).unwrap();
        let res = br.open("https://vk.com");
        let res2 = br.close_browser();
        assert!(res.is_ok()&&res2.is_ok());
    }
    #[test]
    fn brow_firefox_opts() {
        let mut ff = FirefoxOptions::new();
        ff.add_args(vec!["-headless","-devtools"]);
        let mut map = HashMap::new();
        map.insert("MOZ_HEADLESS_WIDTH", "600");
        map.insert("MOZ_HEADLESS_HEIGHT", "400");
        ff.add_env(map);
        let mut br = Browser::start_firefox_session_with_options(ff).unwrap();
        let res = br.open("https://vk.com");
        let res2 = br.close_browser();
        assert!(res.is_ok()&&res2.is_ok());
    }
}
mod safari_tests{
    use super::*;
    #[test]
    #[cfg(target_os="macos")]
    fn saf_open_vk() {
        let mut br = Browser::start_session(BrowserName::Safari, vec![]);
        br.open("https://vk.com").unwrap();
        br.close_browser().unwrap();
    }
    #[test]
    #[cfg(target_os="macos")]
    fn saf_forward() {
        let link: String;
        {let mut br = Browser::start_session(BrowserName::Safari,vec![]);
        br.open("https://vk.com/").unwrap();
        br.open("https://m.facebook.com/").unwrap();
        br.back().unwrap();
        br.forward().unwrap();
        link = br.get_link().unwrap();        
        br.close_browser().unwrap();}
        assert!(link.contains("facebook"));
    }
    #[test]
    #[cfg(target_os="macos")]
    fn saf_diagn() {
        let mut saf_op = SafariOptions::new();
        saf_op.enable_diagnose();
        let mut br = Browser::start_safari_session_with_options(saf_op).unwrap();
        br.open("https://vk.com/").unwrap();
        br.close_browser().unwrap();
    }
    #[test]
    #[cfg(target_os="macos")]
    fn saf_inspe() {
        let mut saf_op = SafariOptions::new();
        saf_op.enable_automatic_inspection();
        let mut br = Browser::start_safari_session_with_options(saf_op).unwrap();
        br.open("https://vk.com/").unwrap();
        br.close_browser().unwrap();
    }
    #[test]
    #[cfg(target_os="macos")]
    fn saf_profi() {
        let mut saf_op = SafariOptions::new();
        saf_op.enable_automatic_profiling();
        let mut br = Browser::start_safari_session_with_options(saf_op).unwrap();
        br.open("https://vk.com/").unwrap();
        br.close_browser().unwrap();
    }
}