Skip to content

Hydroshare Macros

Discover

Bases: Hydroshare

Source code in hydroshare/hs_macros.py
 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
class Discover(Hydroshare):
    start_date = SiteElement(By.ID, "id_start_date")
    end_date = SiteElement(By.ID, "id_end_date")
    map_tab = SiteElement(By.CSS_SELECTOR, 'a[href="#map-view"]')
    map_search = SiteElement(By.ID, "geocoder-address")
    map_submit = SiteElement(By.ID, "geocoder-submit")
    list_tab = SiteElement(By.CSS_SELECTOR, 'a[href="#list-view"]')
    sort_order = SiteElement(By.ID, "id_sort_order")
    sort_direction = SiteElement(By.ID, "id_sort_direction")
    col_headers = SiteElement(By.CSS_SELECTOR, "#items-discovered thead tr")
    legend = SiteElement(By.CSS_SELECTOR, "#headingLegend h4 a")
    legend_labels = SiteElement(
        By.CSS_SELECTOR,
        "#legend-collapse div:first-child div:first-child div.col-xs-12.col-sm-5",
    )
    legend_resources = SiteElement(
        By.CSS_SELECTOR,
        "#legend-collapse div:first-child div:first-child div.col-xs-12.col-sm-7",
    )
    next_page = SiteElement(By.XPATH, '//a[contains(text(), "Next")][1]')
    page = SiteElement(By.ID, "page-number-upper")
    last_updated_by = SiteElement(
        By.XPATH, '//th[text() = "Last updated:"]/following-sibling::td/a'
    )
    search_field = SiteElement(By.ID, "search-input")
    show_all_btn = SiteElement(By.ID, "btn-show-all")
    user_modal_to_profile = SiteElement(
        By.CSS_SELECTOR,
        ".open > ul:nth-child(2) > li:nth-child(1) > div:nth-child(1) "
        "> div:nth-child(2) > h4:nth-child(1) > a:nth-child(1)",
    )
    author_list = SiteElement(By.ID, "list-group-creator")
    result_rows = SiteElement(By.CSS_SELECTOR, "#items-discovered > tbody")
    type_list = SiteElement(By.ID, "list-group-type")
    map_mode = SiteElement(By.ID, "map-mode-button")
    page_left = SiteElement(By.ID, "page-left-upper")
    page_right = SiteElement(By.ID, "page-right-upper")

    @classmethod
    def column_header(index):
        return SiteElement(
            By.CSS_SELECTOR, "thead > tr:nth-child(1) > th:nth-child({})".format(index)
        )

    @classmethod
    def resource_link(self, title):
        return SiteElement(By.XPATH, "//a[contains(text(), '{}')]".format(title))

    @classmethod
    def col_header(self, col_index):
        """Return the column header element, given the index"""
        return SiteElement(
            By.CSS_SELECTOR,
            "#items-discovered thead tr " "th:nth-of-type({})".format(col_index),
        )

    @classmethod
    def cell(self, col, row):
        """
        Return the cell in the discover table, given row and column indicies
        """
        return SiteElement(
            By.CSS_SELECTOR,
            "#items-discovered tbody tr:nth-of-type({}) "
            "td:nth-of-type({}) span".format(row, col),
        )

    @classmethod
    def cell_href(self, col, row):
        """
        Return the cell's hyperlink in the discover table, given row and column
        indicies.
        """
        return SiteElement(
            By.CSS_SELECTOR,
            "#items-discovered tbody tr:nth-of-type({}) "
            "td:nth-of-type({}) a".format(row, col),
        )

    @classmethod
    def cell_strong_href(self, col, row):
        """
        Return the cell's bolded hyperlink in the discover table,
        given row and column indicies.
        """
        return SiteElement(
            By.CSS_SELECTOR,
            "#items-discovered tbody tr:nth-of-type({}) "
            "td:nth-of-type({}) strong a".format(row, col),
        )

    @classmethod
    def filter_author(self, author):
        return SiteElement(By.ID, "author-{}".format(author))

    @classmethod
    def filter_contributor(self, author):
        return SiteElement(By.ID, "contrib-{}".format(author))

    @classmethod
    def filter_content_type(self, content_type):
        return SiteElement(By.ID, "content_type-{}".format(content_type))

    @classmethod
    def filter_subject(self, subject):
        return SiteElement(By.ID, "subj-{}".format(subject))

    @classmethod
    def filter_resource_type(self, resource_type):
        return SiteElement(By.ID, "type-{}".format(resource_type))

    @classmethod
    def filter_owner(self, owner):
        return SiteElement(By.ID, "owner-{}".format(owner))

    @classmethod
    def filter_variable(self, variable):
        return SiteElement(By.ID, "variable_name-{}".format(variable))

    @classmethod
    def filter_sample_medium(self, sample_medium):
        return SiteElement(By.ID, "sample_medium-{}".format(sample_medium))

    @classmethod
    def filter_unit(self, unit):
        return SiteElement(By.ID, "units_name-{}".format(unit))

    @classmethod
    def filter_availability(self, availability):
        return SiteElement(By.ID, "avail-{}".format(availability))

    @classmethod
    def author_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-creator > li:nth-of-type({}) input".format(index),
        )

    @classmethod
    def author_resource_count_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-creator > li:nth-of-type({}) > span".format(index),
        )

    @classmethod
    def contributor_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-contributor > li:nth-of-type({}) input".format(index),
        )

    @classmethod
    def contributor_resource_count_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-contributor > li:nth-of-type({}) > span".format(index),
        )

    @classmethod
    def owner_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-owner > li:nth-of-type({}) input".format(index),
        )

    @classmethod
    def owner_resource_count_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-owner > li:nth-of-type({}) > span".format(index),
        )

    @classmethod
    def type_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-type > li:nth-of-type({}) input".format(index),
        )

    @classmethod
    def type_resource_count_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#list-group-type > li:nth-of-type({}) > span".format(index),
        )

    @classmethod
    def resource_icon_by_index(self, index):
        return SiteElement(
            By.CSS_SELECTOR,
            "#items-discovered > tbody > tr:nth-child({}) > td:nth-child(1) > span > img:nth-child(1)".format(
                index
            ),
        )

    @classmethod
    def set_sort_order(self, driver, option):
        """Set the sort order to {{option}}"""
        self.sort_order.select_option_text(driver, option)
        time.sleep(DISCOVER_TABLE_UPDATE)

    @classmethod
    def set_sort_direction(self, driver, option):
        """Set the sort direction to {{option}}"""
        self.sort_direction.select_option_text(driver, option)
        time.sleep(DISCOVER_TABLE_UPDATE)

    @classmethod
    def set_sort(self, driver, col_index):
        self.col_header(col_index).click(driver)

    @classmethod
    def to_resource(self, driver, title):
        """Navigate to the {{title}} resource landing page by clicking
        on it within the table.  If the resource is not visible will switch to
        the next result page
        """
        num_windows_now = len(driver.window_handles)
        resource_found = False
        time.sleep(DISCOVER_TABLE_UPDATE)
        while not resource_found:
            try:
                self.resource_link(title).click(driver)
                resource_found = True
            except TimeoutException:
                self.page_right.click(driver)
        # Switch to new resource page
        External.switch_new_page(driver, num_windows_now, Resource.authors_locator)

    @classmethod
    def to_last_updated_profile(self, driver):
        self.last_updated_by.click(driver)
        self.user_modal_to_profile.click(driver)

    @classmethod
    def col_index(self, driver, col_name):
        """Indentify the index for a discover page column, given the
        column name.  Indexes here start at one since the
        end application here is xpath, and those indexes are 1 based
        """
        num_cols = self.col_headers.get_immediate_child_count(driver)
        for i in range(1, num_cols + 1):
            name_to_check = self.col_header(i).get_text(driver).replace("\n", " ")
            if name_to_check == col_name:
                return i
        return 0

    @classmethod
    def check_sorting_multi(self, driver, column_name, ascend_or_descend):
        """Check discover page rows are sorted correctly.  The automated
        testing system checks the first eight rows against the rows that
        are 1, 2, and 3 positions down, relative to the base row (a total
        of 24 checks)
        """
        baseline_rows = 8
        all_pass = True
        for i in range(1, baseline_rows):
            for j in range(1, 4):
                if not self.check_sorting_single(
                    driver, column_name, ascend_or_descend, i, i + j
                ):
                    all_pass = False
        return all_pass

    @classmethod
    def check_sorting_single(
        self, driver, column_name, ascend_or_descend, row_one, row_two
    ):
        """Confirm that two rows are sorted correctly relative to
        eachother
        """
        col_ind = self.col_index(driver, column_name)
        if column_name == "Title":
            first_element = self.cell_href(col_ind, row_one)
            second_element = self.cell_href(col_ind, row_two)
            first_two_vals = [
                first_element.get_text(driver),
                second_element.get_text(driver),
            ]
        elif column_name == "First Author":
            first_element = self.cell_href(col_ind, row_one)
            second_element = self.cell_href(col_ind, row_two)
            first_two_vals = [
                first_element.get_text(driver),
                second_element.get_text(driver),
            ]
        else:
            first_element = self.cell(col_ind, row_one)
            second_element = self.cell(col_ind, row_two)
            first_two_vals = [
                first_element.get_text(driver),
                second_element.get_text(driver),
            ]
        if ("Date" in column_name) or (column_name == "Last Modified"):
            date_one = parser.parse(first_two_vals[0])
            date_two = parser.parse(first_two_vals[1])
            if ascend_or_descend == "Descending":
                return date_one >= date_two
            elif ascend_or_descend == "Ascending":
                return date_one <= date_two
        else:
            value_one, value_two = first_two_vals
            if ascend_or_descend == "Descending":
                return value_one >= value_two
            elif ascend_or_descend == "Ascending":
                return value_one <= value_two

    @classmethod
    def show_all(self, driver):
        self.show_all_btn.click(driver)

    @classmethod
    def add_filters(
        self,
        driver,
        author=None,
        subject=None,
        resource_type=None,
        owner=None,
        variable=None,
        sample_medium=None,
        unit=None,
        availability=None,
        contributor=None,
        content_type=None,
    ):
        """Use the filters on the left side of the Discover interface.
        Filters should include author(s) {{author}}, subject(s) {{subject}},
        resource type(s) {{resource_type}}, owner(s) {{owner}}, variables
        {{variable}}, sample medium(s) {{sample_medium}}, unit(s) {{unit}},
        and availability(s) {{availability}}
        """
        if type(author) is list:
            for author_item in author:
                filter_el = self.filter_author(author_item)
                filter_el.javascript_click(driver)
        elif author is not None:
            filter_el = self.filter_author(author)
            filter_el.javascript_click(driver)
        if type(contributor) is list:
            for contributor_item in contributor:
                filter_el = self.filter_contributor(contributor_item)
                filter_el.javascript_click(driver)
        elif contributor is not None:
            filter_el = self.filter_contributor(contributor)
            filter_el.javascript_click(driver)
        if type(content_type) is list:
            for content_item in content_type:
                filter_el = self.filter_contributor(content_item)
                filter_el.javascript_click(driver)
        elif content_type is not None:
            filter_el = self.filter_content_type(content_type)
            filter_el.javascript_click(driver)
        if type(subject) is list:
            for subject_item in subject:
                filter_el = self.filter_subject(subject_item)
                filter_el.javascript_click(driver)
        elif subject is not None:
            filter_el = self.filter_subject(subject)
            filter_el.javascript_click(driver)
        if type(resource_type) is list:
            for resource_type_item in resource_type:
                filter_el = self.filter_resource_type(resource_type_item)
                filter_el.javascript_click(driver)
        elif resource_type is not None:
            filter_el = self.filter_resource_type(resource_type)
            filter_el.javascript_click(driver)
        if type(owner) is list:
            for owner_item in owner:
                filter_el = self.filter_owner(owner_item)
                filter_el.javascript_click(driver)
        elif owner is not None:
            filter_el = self.filter_owner(owner)
            filter_el.javascript_click(driver)
        if type(variable) is list:
            for variable_item in variable:
                filter_el = self.filter_variable(variable_item)
                filter_el.javascript_click(driver)
        elif variable is not None:
            filter_el = self.filter_variable(variable)
            filter_el.javascript_click(driver)
        if type(sample_medium) is list:
            for sample_medium_item in sample_medium:
                filter_el = self.filter_sample_medium(sample_medium_item)
                filter_el.javascript_click(driver)
        elif sample_medium is not None:
            filter_el = self.filter_sample_medium(sample_medium)
            filter_el.javascript_click(driver)
        if type(unit) is list:
            for unit_item in unit:
                filter_el = self.filter_unit(unit_item)
                filter_el.javascript_click(driver)
        elif unit is not None:
            filter_el = self.filter_unit(unit)
            filter_el.javascript_click(driver)
        if type(availability) is list:
            for availability_item in availability:
                filter_el = self.filter_availability(availability_item)
                filter_el.javascript_click(driver)
        elif availability is not None:
            filter_el = self.filter_availability(availability)
            filter_el.javascript_click(driver)

    @classmethod
    def legend_text(self, driver):
        self.legend.click(driver)
        labels = str(self.legend_labels.get_text(driver))
        resources = str(self.legend_resources.get_text(driver))
        return labels, resources

    @classmethod
    def search(self, driver, text):
        self.search_field.click(driver)
        self.search_field.clear_all_text(driver)
        self.search_field.inject_text(driver, text)
        self.search_field.submit(driver)
        time.sleep(DISCOVER_TABLE_UPDATE)

    @classmethod
    def to_search_result_item(self, driver, col_ind, row_one):
        self.cell_href(col_ind, row_one).click(driver)

    @classmethod
    def to_resource_by_index(self, driver, index):
        num_windows_now = len(driver.window_handles)
        self.cell_href(2, index).click(driver)
        External.switch_new_page(driver, num_windows_now, Resource.authors_locator)

    @classmethod
    def is_selected(
        self,
        driver,
        author=None,
        contributor=None,
        owner=None,
        content_type=None,
        subject=None,
        availability=None,
    ):
        if author is not None:
            return self.filter_author(author).is_selected(driver)
        elif contributor is not None:
            return self.filter_contributor(contributor).is_selected(driver)
        elif owner is not None:
            return self.filter_owner(owner).is_selected(driver)
        elif content_type is not None:
            return self.filter_content_type(content_type).is_selected(driver)
        elif subject is not None:
            return self.filter_subject(subject).is_selected(driver)
        elif availability is not None:
            return self.filter_availability(availability).is_selected(driver)

    @classmethod
    def toggle_author_filter_by_index(self, driver, index):
        self.author_by_index(index).javascript_click(driver)
        time.sleep(DISCOVER_TABLE_UPDATE)

    @classmethod
    def get_author_resource_count_by_index(self, driver, index):
        return int(self.author_resource_count_by_index(index).get_text(driver))

    @classmethod
    def toggle_contributor_filter_by_index(self, driver, index):
        self.contributor_by_index(index).javascript_click(driver)
        time.sleep(DISCOVER_TABLE_UPDATE)

    @classmethod
    def get_contributor_resource_count_by_index(self, driver, index):
        return int(self.contributor_resource_count_by_index(index).get_text(driver))

    @classmethod
    def toggle_owner_filter_by_index(self, driver, index):
        self.owner_by_index(index).javascript_click(driver)
        time.sleep(DISCOVER_TABLE_UPDATE)

    @classmethod
    def get_owner_resource_count_by_index(self, driver, index):
        return int(self.owner_resource_count_by_index(index).get_text(driver))

    @classmethod
    def toggle_type_filter_by_index(self, driver, index):
        self.type_by_index(index).javascript_click(driver)
        time.sleep(DISCOVER_TABLE_UPDATE)

    @classmethod
    def get_type_resource_count_by_index(self, driver, index):
        return int(self.type_resource_count_by_index(index).get_text(driver))

    @classmethod
    def get_count_of_types(self, driver):
        time.sleep(DISCOVER_TABLE_UPDATE)
        return int(self.type_list.get_immediate_child_count(driver))

    @classmethod
    def count_results_in_table(self, driver):
        last_page = 0
        count = 0
        while True:
            time.sleep(DISCOVER_TABLE_UPDATE)
            current_page = self.page.get_value(driver)
            if current_page == last_page:
                break
            TestSystem.wait()
            self.page_right.click(driver)
            last_page = current_page
            time.sleep(DISCOVER_TABLE_UPDATE)
            count += self.result_rows.get_immediate_child_count(driver)
        return count

    @classmethod
    def uses_consistent_date_formatting(self, driver):
        last_page = 0
        while True:
            time.sleep(DISCOVER_TABLE_UPDATE)
            for i in range(1, self.result_rows.get_immediate_child_count(driver) + 1):
                # date_created = "/".join([number.zfill(2) for number in self.cell(4, i).get_text(driver).split("/")])
                date_created = self.cell(4, i).get_text(driver)
                last_modified = self.cell(5, i).get_text(driver)
                datetime.strptime(date_created, "%m/%d/%Y")
                datetime.strptime(last_modified, "%m/%d/%Y")
            current_page = self.page.get_value(driver)
            if current_page == last_page:
                break
            self.page.click(driver)
            self.page.clear_all_text(driver)
            self.page.inject_text(driver, "{}".format(int(current_page) + 1))
            self.page.inject_text(driver, Keys.ENTER)
            last_page = current_page
        return True

    @classmethod
    def get_first_author_by_resource_index(self, driver, index):
        try:
            first_author = self.cell_href(3, index).get_text(driver)
        except TimeoutException:
            first_author = self.cell(3, index).get_text(driver)
        return first_author

    @classmethod
    def uses_consistent_icon(self, driver):
        reference_src = self.resource_icon_by_index(1).get_attribute(driver, "src")
        for i in range(2, self.result_rows.get_immediate_child_count(driver) + 1):
            if (
                self.resource_icon_by_index(i).get_attribute(driver, "src")
                == reference_src
            ):
                return True
            if (
                self.resource_icon_by_index(i).get_attribute(driver, "src")
                == BASE_URL + "/static/img/resource-icons/composite48x48.png"
            ):
                return True
            if (
                reference_src
                == BASE_URL + "/static/img/resource-icons/composite48x48.png"
            ):
                return True
        return False

add_filters(driver, author=None, subject=None, resource_type=None, owner=None, variable=None, sample_medium=None, unit=None, availability=None, contributor=None, content_type=None) classmethod

Use the filters on the left side of the Discover interface. Filters should include author(s) {{author}}, subject(s) {{subject}}, resource type(s) {{resource_type}}, owner(s) {{owner}}, variables {{variable}}, sample medium(s) {{sample_medium}}, unit(s) {{unit}}, and availability(s) {{availability}}

Source code in hydroshare/hs_macros.py
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
@classmethod
def add_filters(
    self,
    driver,
    author=None,
    subject=None,
    resource_type=None,
    owner=None,
    variable=None,
    sample_medium=None,
    unit=None,
    availability=None,
    contributor=None,
    content_type=None,
):
    """Use the filters on the left side of the Discover interface.
    Filters should include author(s) {{author}}, subject(s) {{subject}},
    resource type(s) {{resource_type}}, owner(s) {{owner}}, variables
    {{variable}}, sample medium(s) {{sample_medium}}, unit(s) {{unit}},
    and availability(s) {{availability}}
    """
    if type(author) is list:
        for author_item in author:
            filter_el = self.filter_author(author_item)
            filter_el.javascript_click(driver)
    elif author is not None:
        filter_el = self.filter_author(author)
        filter_el.javascript_click(driver)
    if type(contributor) is list:
        for contributor_item in contributor:
            filter_el = self.filter_contributor(contributor_item)
            filter_el.javascript_click(driver)
    elif contributor is not None:
        filter_el = self.filter_contributor(contributor)
        filter_el.javascript_click(driver)
    if type(content_type) is list:
        for content_item in content_type:
            filter_el = self.filter_contributor(content_item)
            filter_el.javascript_click(driver)
    elif content_type is not None:
        filter_el = self.filter_content_type(content_type)
        filter_el.javascript_click(driver)
    if type(subject) is list:
        for subject_item in subject:
            filter_el = self.filter_subject(subject_item)
            filter_el.javascript_click(driver)
    elif subject is not None:
        filter_el = self.filter_subject(subject)
        filter_el.javascript_click(driver)
    if type(resource_type) is list:
        for resource_type_item in resource_type:
            filter_el = self.filter_resource_type(resource_type_item)
            filter_el.javascript_click(driver)
    elif resource_type is not None:
        filter_el = self.filter_resource_type(resource_type)
        filter_el.javascript_click(driver)
    if type(owner) is list:
        for owner_item in owner:
            filter_el = self.filter_owner(owner_item)
            filter_el.javascript_click(driver)
    elif owner is not None:
        filter_el = self.filter_owner(owner)
        filter_el.javascript_click(driver)
    if type(variable) is list:
        for variable_item in variable:
            filter_el = self.filter_variable(variable_item)
            filter_el.javascript_click(driver)
    elif variable is not None:
        filter_el = self.filter_variable(variable)
        filter_el.javascript_click(driver)
    if type(sample_medium) is list:
        for sample_medium_item in sample_medium:
            filter_el = self.filter_sample_medium(sample_medium_item)
            filter_el.javascript_click(driver)
    elif sample_medium is not None:
        filter_el = self.filter_sample_medium(sample_medium)
        filter_el.javascript_click(driver)
    if type(unit) is list:
        for unit_item in unit:
            filter_el = self.filter_unit(unit_item)
            filter_el.javascript_click(driver)
    elif unit is not None:
        filter_el = self.filter_unit(unit)
        filter_el.javascript_click(driver)
    if type(availability) is list:
        for availability_item in availability:
            filter_el = self.filter_availability(availability_item)
            filter_el.javascript_click(driver)
    elif availability is not None:
        filter_el = self.filter_availability(availability)
        filter_el.javascript_click(driver)

cell(col, row) classmethod

Return the cell in the discover table, given row and column indicies

Source code in hydroshare/hs_macros.py
505
506
507
508
509
510
511
512
513
514
@classmethod
def cell(self, col, row):
    """
    Return the cell in the discover table, given row and column indicies
    """
    return SiteElement(
        By.CSS_SELECTOR,
        "#items-discovered tbody tr:nth-of-type({}) "
        "td:nth-of-type({}) span".format(row, col),
    )

cell_href(col, row) classmethod

Return the cell's hyperlink in the discover table, given row and column indicies.

Source code in hydroshare/hs_macros.py
516
517
518
519
520
521
522
523
524
525
526
@classmethod
def cell_href(self, col, row):
    """
    Return the cell's hyperlink in the discover table, given row and column
    indicies.
    """
    return SiteElement(
        By.CSS_SELECTOR,
        "#items-discovered tbody tr:nth-of-type({}) "
        "td:nth-of-type({}) a".format(row, col),
    )

cell_strong_href(col, row) classmethod

Return the cell's bolded hyperlink in the discover table, given row and column indicies.

Source code in hydroshare/hs_macros.py
528
529
530
531
532
533
534
535
536
537
538
@classmethod
def cell_strong_href(self, col, row):
    """
    Return the cell's bolded hyperlink in the discover table,
    given row and column indicies.
    """
    return SiteElement(
        By.CSS_SELECTOR,
        "#items-discovered tbody tr:nth-of-type({}) "
        "td:nth-of-type({}) strong a".format(row, col),
    )

check_sorting_multi(driver, column_name, ascend_or_descend) classmethod

Check discover page rows are sorted correctly. The automated testing system checks the first eight rows against the rows that are 1, 2, and 3 positions down, relative to the base row (a total of 24 checks)

Source code in hydroshare/hs_macros.py
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
@classmethod
def check_sorting_multi(self, driver, column_name, ascend_or_descend):
    """Check discover page rows are sorted correctly.  The automated
    testing system checks the first eight rows against the rows that
    are 1, 2, and 3 positions down, relative to the base row (a total
    of 24 checks)
    """
    baseline_rows = 8
    all_pass = True
    for i in range(1, baseline_rows):
        for j in range(1, 4):
            if not self.check_sorting_single(
                driver, column_name, ascend_or_descend, i, i + j
            ):
                all_pass = False
    return all_pass

check_sorting_single(driver, column_name, ascend_or_descend, row_one, row_two) classmethod

Confirm that two rows are sorted correctly relative to eachother

Source code in hydroshare/hs_macros.py
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
@classmethod
def check_sorting_single(
    self, driver, column_name, ascend_or_descend, row_one, row_two
):
    """Confirm that two rows are sorted correctly relative to
    eachother
    """
    col_ind = self.col_index(driver, column_name)
    if column_name == "Title":
        first_element = self.cell_href(col_ind, row_one)
        second_element = self.cell_href(col_ind, row_two)
        first_two_vals = [
            first_element.get_text(driver),
            second_element.get_text(driver),
        ]
    elif column_name == "First Author":
        first_element = self.cell_href(col_ind, row_one)
        second_element = self.cell_href(col_ind, row_two)
        first_two_vals = [
            first_element.get_text(driver),
            second_element.get_text(driver),
        ]
    else:
        first_element = self.cell(col_ind, row_one)
        second_element = self.cell(col_ind, row_two)
        first_two_vals = [
            first_element.get_text(driver),
            second_element.get_text(driver),
        ]
    if ("Date" in column_name) or (column_name == "Last Modified"):
        date_one = parser.parse(first_two_vals[0])
        date_two = parser.parse(first_two_vals[1])
        if ascend_or_descend == "Descending":
            return date_one >= date_two
        elif ascend_or_descend == "Ascending":
            return date_one <= date_two
    else:
        value_one, value_two = first_two_vals
        if ascend_or_descend == "Descending":
            return value_one >= value_two
        elif ascend_or_descend == "Ascending":
            return value_one <= value_two

col_header(col_index) classmethod

Return the column header element, given the index

Source code in hydroshare/hs_macros.py
497
498
499
500
501
502
503
@classmethod
def col_header(self, col_index):
    """Return the column header element, given the index"""
    return SiteElement(
        By.CSS_SELECTOR,
        "#items-discovered thead tr " "th:nth-of-type({})".format(col_index),
    )

col_index(driver, col_name) classmethod

Indentify the index for a discover page column, given the column name. Indexes here start at one since the end application here is xpath, and those indexes are 1 based

Source code in hydroshare/hs_macros.py
684
685
686
687
688
689
690
691
692
693
694
695
@classmethod
def col_index(self, driver, col_name):
    """Indentify the index for a discover page column, given the
    column name.  Indexes here start at one since the
    end application here is xpath, and those indexes are 1 based
    """
    num_cols = self.col_headers.get_immediate_child_count(driver)
    for i in range(1, num_cols + 1):
        name_to_check = self.col_header(i).get_text(driver).replace("\n", " ")
        if name_to_check == col_name:
            return i
    return 0

set_sort_direction(driver, option) classmethod

Set the sort direction to {{option}}

Source code in hydroshare/hs_macros.py
651
652
653
654
655
@classmethod
def set_sort_direction(self, driver, option):
    """Set the sort direction to {{option}}"""
    self.sort_direction.select_option_text(driver, option)
    time.sleep(DISCOVER_TABLE_UPDATE)

set_sort_order(driver, option) classmethod

Set the sort order to {{option}}

Source code in hydroshare/hs_macros.py
645
646
647
648
649
@classmethod
def set_sort_order(self, driver, option):
    """Set the sort order to {{option}}"""
    self.sort_order.select_option_text(driver, option)
    time.sleep(DISCOVER_TABLE_UPDATE)

to_resource(driver, title) classmethod

Navigate to the {{title}} resource landing page by clicking on it within the table. If the resource is not visible will switch to the next result page

Source code in hydroshare/hs_macros.py
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
@classmethod
def to_resource(self, driver, title):
    """Navigate to the {{title}} resource landing page by clicking
    on it within the table.  If the resource is not visible will switch to
    the next result page
    """
    num_windows_now = len(driver.window_handles)
    resource_found = False
    time.sleep(DISCOVER_TABLE_UPDATE)
    while not resource_found:
        try:
            self.resource_link(title).click(driver)
            resource_found = True
        except TimeoutException:
            self.page_right.click(driver)
    # Switch to new resource page
    External.switch_new_page(driver, num_windows_now, Resource.authors_locator)

Hydroshare

Bases: WebPage

Source code in hydroshare/hs_macros.py
 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
class Hydroshare(WebPage):
    navigation_landing_page = SiteElement(By.ID, "img-brand-logo")
    navigation_home = SiteElement(By.ID, "dropdown-menu-home")
    navigation_my_resources = SiteElement(By.ID, "dropdown-menu-my-resources")
    navigation_discover = SiteElement(By.ID, "dropdown-menu-search")
    navigation_collaborate = SiteElement(
        By.CSS_SELECTOR, "#dropdown-menu-collaborate a"
    )
    navigation_apps = SiteElement(
        By.ID, "dropdown-menu-https:--www.hydroshare.org-apps-"
    )
    navigation_help = SiteElement(
        By.CSS_SELECTOR, 'a[href="{}"]'.format("http://help.hydroshare.org")
    )
    navigation_login = SiteElement(By.CSS_SELECTOR, "#signin-menu a")
    profile_button = SiteElement(
        By.CSS_SELECTOR, ".account div.dropdown-footer .btn.btn-primary"
    )
    profile_menu = SiteElement(By.ID, "profile-menu")
    signout_menu = SiteElement(By.ID, "signout-menu")
    resource_creation = SiteElement(By.ID, "select-resource-type")
    footer = SiteElement(By.CSS_SELECTOR, "footer")
    footer_terms = SiteElement(By.CSS_SELECTOR, "footer a[href='/terms-of-use']")
    footer_privacy = SiteElement(By.CSS_SELECTOR, "footer a[href='/privacy']")
    footer_sitemap = SiteElement(By.CSS_SELECTOR, "footer a[href='/sitemap/']")
    footer_twitter = SiteElement(
        By.CSS_SELECTOR, ".content.social ul li:nth-child(1) > a"
    )
    footer_facebook = SiteElement(
        By.CSS_SELECTOR, ".content.social ul li:nth-child(2) > a"
    )
    footer_youtube = SiteElement(
        By.CSS_SELECTOR, ".content.social ul li:nth-child(3) > a"
    )
    footer_github = SiteElement(
        By.CSS_SELECTOR, ".content.social ul li:nth-child(4) > a"
    )
    footer_linkedin = SiteElement(
        By.CSS_SELECTOR, ".content.social ul li:nth-child(5) > a"
    )
    footer_version = SiteElement(By.CSS_SELECTOR, ".content p b")
    support_email = SiteElement(By.CSS_SELECTOR, 'a[href="mailto:help@cuahsi.org"]')
    page_tip = SiteElement(By.CSS_SELECTOR, ".page-tip > .container > .row > div > p")
    logged_in_full_name = SiteElement(By.ID, "profile-menu-fullname")
    logged_in_email = SiteElement(By.ID, "profile-menu-email")
    notifications = SiteElement(By.CSS_SELECTOR, "#notifications-dropdown > a")
    notifications_clear = SiteElement(By.CSS_SELECTOR, "#btn-notifications-clear")

    @classmethod
    def resource_type(self, resource_type):
        return SiteElement(By.CSS_SELECTOR, 'a[data-value="{}"]'.format(resource_type))

    @classmethod
    def to_landing_page(self, driver):
        self.navigation_landing_page.click(driver)

    @classmethod
    def to_home(self, driver):
        self.navigation_home.click(driver)

    @classmethod
    def to_my_resources(self, driver):
        self.navigation_my_resources.click(driver)

    @classmethod
    def to_discover(self, driver):
        self.navigation_discover.click(driver)

    @classmethod
    def to_collaborate(self, driver):
        self.navigation_collaborate.click(driver)

    @classmethod
    def to_apps(self, driver):
        num_windows_now = len(driver.window_handles)
        self.navigation_apps.click(driver)
        External.switch_new_page(driver, num_windows_now, Apps.apps_locator)

    @classmethod
    def to_help(self, driver):
        self.navigation_help.click(driver)
        time.sleep(EXTERNAL_PAGE_LOAD)

    @classmethod
    def to_about(self, driver):
        self.navigation_help.click(driver)
        time.sleep(EXTERNAL_PAGE_LOAD)
        Help.to_about.javascript_click(driver)

    @classmethod
    def to_login(self, driver):
        self.navigation_login.click(driver)

    @classmethod
    def to_profile(self, driver):
        self.profile_menu.click(driver)
        self.profile_button.click(driver)

    @classmethod
    def logout(self, driver):
        self.profile_menu.click(driver)
        self.signout_menu.click(driver)

    @classmethod
    def create_resource(self, driver, type):
        self.resource_creation.click(driver)
        self.resource_type(type).click(driver)

    @classmethod
    def to_terms(self, driver):
        self.footer_terms.click(driver)

    @classmethod
    def to_privacy(self, driver):
        self.footer_privacy.click(driver)

    @classmethod
    def to_sitemap(self, driver):
        self.footer_sitemap.click(driver)

    @classmethod
    def get_social_link(self, driver, social):
        social_links = {
            "facebook": self.footer_facebook,
            "twitter": self.footer_twitter,
            "youtube": self.footer_youtube,
            "github": self.footer_github,
            "linkedin": self.footer_linkedin,
        }
        return social_links[social].get_attribute(driver, "href")

    @classmethod
    def get_version(self, driver):
        return self.footer_version.get_text(driver).strip()

    @classmethod
    def get_latest_release(self, org, repo):
        """
        Retrieves the version of the latest published release of 'hydroshare'
        repository.
        """
        # See https://developer.github.com/v3/repos/
        # releases/#get-the-latest-release
        request_url = f"https://api.github.com/repos/{org}/" f"{repo}/releases/latest"
        response_data = urlopen(request_url).read()
        release_version = json.loads(response_data)["tag_name"]
        return release_version

    @classmethod
    def get_support_email(self, driver):
        return self.support_email.get_href(driver)

    @classmethod
    def get_logged_in_name(self, driver):
        self.profile_menu.click(driver)
        name = self.logged_in_full_name.get_text(driver)
        self.profile_menu.click(driver)
        return name

    @classmethod
    def get_logged_in_email(self, driver):
        self.profile_menu.click(driver)
        name = self.logged_in_email.get_text(driver)
        self.profile_menu.click(driver)
        return name

    @classmethod
    def clear_notifications(self, driver):
        self.notifications.click(driver)
        self.notifications_clear.click(driver)
        self.notifications.click(driver)

get_latest_release(org, repo) classmethod

Retrieves the version of the latest published release of 'hydroshare' repository.

Source code in hydroshare/hs_macros.py
211
212
213
214
215
216
217
218
219
220
221
222
@classmethod
def get_latest_release(self, org, repo):
    """
    Retrieves the version of the latest published release of 'hydroshare'
    repository.
    """
    # See https://developer.github.com/v3/repos/
    # releases/#get-the-latest-release
    request_url = f"https://api.github.com/repos/{org}/" f"{repo}/releases/latest"
    response_data = urlopen(request_url).read()
    release_version = json.loads(response_data)["tag_name"]
    return release_version