#!/usr/bin/python3

import os
import time
# import unittest
import composerlib
import testlib


@testlib.nondestructive
@testlib.timeout(2400)
@testlib.no_retry_when_changed
class TestWizard(composerlib.ComposerCase):

    def testQCOW2Customized(self):
        b = self.browser

        self.login_and_go("/composer")
        b.wait_visible("#main")

        # create image wizard (no upload support)
        b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
        b.wait_in_text(".pf-c-wizard__main", "httpd-server")
        # check ? (Process length help) button
        time.sleep(1)
        b.wait_text("h1", "Image output")
        b.click("button[aria-label='Process length help']")
        b.wait_text(".pf-c-popover__body", "This process can take a while. "
                    "Images are built in the order they are started.")
        b.click(".pf-c-popover__content button")
        b.wait_not_present(".pf-c-popover__body")
        # check non upload image action (Create only)
        b.select_PF4("#image-output-select-toggle", "QEMU Image (.qcow2)")
        # check ? (image size help) button
        b.click("button[aria-label='Image size help']")
        b.wait_text(".pf-c-popover__body",
                    "Set the size that you want the image to be when instantiated. The total "
                    "package size and target destination of your image should be considered when "
                    "setting the image size.")
        b.click(".pf-c-popover__content button")
        b.wait_not_present(".pf-c-popover__body")
        # default size = 2GB for qcow2 image
        b.wait_val("#image-size", 2)
        b.focus("#image-size")
        # delete 2 and input 1
        b.key_press("\b")
        b.key_press("1")
        # error if less than 2 GB
        b.wait_attr("button:contains('Next')", "disabled", "")
        # delete 1 and input 2
        b.key_press("\b")
        b.key_press("2")

        # go to details page
        b.click("button:contains('Next')")
        b.wait_text("h1", "System")
        # go to users page
        b.click("button:contains('Next')")
        b.wait_text("h1", "Users")
        # go to packages page
        b.click("button:contains('Next')")
        b.wait_text("h1", "Packages")
        # select openssh-server
        b.focus("div[data-testid='search-available-pkgs-input'] input")
        b.key_press("openssh-server")
        b.click("button[aria-label='Search button for available packages']")
        with b.wait_timeout(180):
            b.click("li[data-testid='openssh-server']")
            b.click("button[aria-label='Add selected']")
            b.click("li[data-testid='httpd']")
            b.click("button[aria-label='Remove selected']")

        # # go to review page
        b.click("button:contains('Next')")
        b.wait_text("h1", "Review")

        b.wait_in_text("#review-list", "Blueprint name")
        b.wait_in_text("#review-list", "httpd-server")
        b.wait_in_text("#review-list", "Output type")
        b.wait_in_text("#review-list", "qcow2")
        b.wait_in_text("#review-list", "Image size")
        b.wait_in_text("#review-list", "2")
        b.wait_in_text("#review-list", "Packages")
        b.wait_in_text("#review-list", "3")

        # save image
        b.click(".pf-c-wizard__footer button:contains('Save blueprint')")
        # Create image
        with b.wait_timeout(120):
            b.click(".pf-c-wizard__footer button:contains('Create image')")

        b.wait_not_present("#create-image-wizard")
        # notification
        # On first load on fedora this notification can take a while to trigger
        with b.wait_timeout(300):
            b.wait_visible("#alertComposeQueued")
        b.click("#alertComposeQueued .pf-c-alert__action button")
        b.wait_not_present("#alertComposeQueued")

        # got to images tab
        b.click("#httpd-server-name")
        with b.wait_timeout(300):
            b.click("#pf-tab-images-blueprint-tabs")
            b.wait_visible("ul[data-list=images]")
        b.wait_in_text("div[data-testid='image-type']", "QEMU Image (.qcow2)")
        # image building needs more time
        with b.wait_timeout(1800):
            b.wait_in_text("div[data-testid='image-status']", "Image build complete")
        # image size should be 2GB
        b.wait_in_text("div[data-testid='image-size']", "2 GB")

        # check for logs
        b.is_present("button:contains('Logs')")

        # download image
        b.click(".pf-c-data-list__item-row button[aria-label='Actions']")
        b.click("a:contains('Download')")

        # delete image
        time.sleep(5)
        b.click("button[data-testid='delete-image']")
        b.wait_visible("#cmpsr-modal-delete")
        b.click("#cmpsr-modal-delete button:contains('Delete image')")
        time.sleep(5)
        b.wait_text("h2", "No images")

        # collect code coverage result
        self.check_coverage()

    # TODO: verify popover text after string translation
    def testAWSStep(self):
        b = self.browser

        self.login_and_go("/composer")
        b.wait_visible("#main")

        # create image wizard (no upload support)
        b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
        b.wait_in_text(".pf-c-wizard__main", "httpd-server")
        time.sleep(1)
        # select AWS
        b.select_PF4("#image-output-select-toggle", "Amazon Web Services (.raw)")
        # Upload image
        b.wait_visible("label:contains('Upload to AWS')")
        b.click("#image-upload")

        b.click("button[aria-label='Upload to AWS help']")
        # b.wait_in_text(".pf-c-popover__body",
        #                " Image Builder can upload images you create to an S3 bucket in AWS and "
        #                "then import them into EC2. When the image build is complete and the upload"
        #                " action is successful, the image file is available in the AMI section of "
        #                "EC2. Most of the values required to upload the image can be found in the "
        #                "AWS Management Console.  This upload process requires that you have an "
        #                "Identity and Access Management (IAM) role named vmimport to ensure that "
        #                "the image can be imported from the S3 bucket into EC2. For more details, "
        #                "refer to the AWS Required Service Role. ")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")

        # Auth page
        b.click("button:contains('Next')")

        b.wait_text("h1", "Authentication")

        b.wait_visible("label:contains('Access key ID')")
        b.click("button[aria-label='Access key help']")
        # b.wait_text(".pf-c-popover__body",
        #             "You can create and find existing Access key IDs on the "
        #             "Identity and Access Management (IAM) page in the AWS console.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='aws-access-key']")
        b.key_press("never")

        b.wait_visible("label:contains('Secret access key')")
        b.click("button[aria-label='Secret access key help']")
        # b.wait_text(".pf-c-popover__body",
        #             "You can view the Secret access key only when you create a new Access key ID "
        #             "on the Identity and Access Management (IAM) page in the AWS console.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='aws-secret-access-key']")
        b.key_press("gunna")

        # Destination page
        b.click("button:contains('Next')")

        b.wait_text("h1", "Destination")
        b.wait_visible("label:contains('Image name')")
        b.click("button[aria-label='Image name help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide a file name to be used for the image file that will be uploaded.")
        b.click(".pf-c-popover__content button")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='aws-image-name']")
        b.key_press("give")

        b.wait_visible("label:contains('Amazon S3 bucket')")
        b.click("button[aria-label='S3 bucket help']")
        # b.wait_text(".pf-c-popover__body",
        #             " Provide the S3 bucket name to which the image file will be uploaded before "
        #             "being imported into EC2.  The bucket must already exist in the Region where "
        #             "you want to import your image. You can find a list of buckets on the S3 "
        #             "buckets page in the Amazon S3 storage service in the AWS console. ")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='aws-s3-bucket']")
        b.key_press("you")

        b.wait_visible("label:contains('AWS region')")
        # check image name help button
        b.click("button[aria-label='Region help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the AWS Region where you want to import your image. "
        #             "This must be the same region where the S3 bucket exists.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        # enter access key id value
        b.focus("input[id='aws-region']")
        b.key_press("up")

        b.click("button:contains('Next')")
        # skip packages and customizations steps
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")

        # Verify AWS Review page
        b.wait_text("h1", "Review")

        b.wait_in_text("#review-list", "Blueprint name")
        b.wait_in_text("#review-list", "httpd-server")
        b.wait_in_text("#review-list", "Output type")
        b.wait_in_text("#review-list", "ami")
        b.wait_in_text("#review-list", "Image size")
        b.wait_in_text("#review-list", "6")
        with b.wait_timeout(180):
            b.wait_in_text("#review-list", "Packages")
            b.wait_in_text("#review-list", "3")

        # the key values are hidden
        b.wait_in_text("#review-list", "Access key ID")
        b.wait_in_text("#review-list", "*****")
        b.wait_in_text("#review-list", "Secret access key")
        b.wait_in_text("#review-list", "*****")
        b.wait_in_text("#review-list", "Image name")
        b.wait_in_text("#review-list", "give")
        b.wait_in_text("#review-list", "Amazon S3 bucket")
        b.wait_in_text("#review-list", "you")
        b.wait_in_text("#review-list", "AWS region")
        b.wait_in_text("#review-list", "up")

        # Close wizard
        b.click("button:contains('Cancel')")
        b.wait_not_present("#create-image-wizard")
        # collect code coverage result
        self.check_coverage()

    # TODO: verify popover text after string translation
    def testAzureStep(self):
        b = self.browser
        self.login_and_go("/composer")
        b.wait_visible("#main")

        # create image wizard (no upload support)
        b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
        b.wait_in_text(".pf-c-wizard__main", "httpd-server")
        time.sleep(1)
        # select AWS
        b.select_PF4("#image-output-select-toggle", "Microsoft Azure (.vhd)")
        # Upload image
        b.wait_visible("label:contains('Upload to Azure')")
        b.click("#image-upload")

        b.click("button[aria-label='Upload to Azure help']")
        # b.wait_in_text(".pf-c-popover__body",
        #                " Image Builder can upload images you create to a Blob container in "
        #                "Microsoft Azure. When the image build is complete and the upload action "
        #                "is successful, the image file is available in the Storage account and Blob "
        #                "container that you specified. ")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")

        # Auth page
        b.click("button:contains('Next')")

        b.wait_text("h1", "Authentication")

        b.wait_visible("label:contains('Storage account')")
        b.click("button[aria-label='Storage account help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the name of a storage account. You can find storage accounts on the "
        #             "Storage accounts page in the Azure portal.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='azure-storage-account']")
        b.key_press("never")

        b.wait_visible("label:contains('Storage access key')")
        b.click("button[aria-label='Storage access key help']")
        # b.wait_text(".pf-c-popover__body",
        #             " Provide the access key for the desired storage account. You can find the "
        #             "access key on the Access keys  page of the storage account. You can find "
        #             "storage accounts on the Storage accounts page in the Azure portal. ")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='azure-storage-access-key']")
        b.key_press("gunna")

        # Destination page
        b.click("button:contains('Next')")

        b.wait_text("h1", "Destination")
        b.wait_visible("label:contains('Image name')")
        b.click("button[aria-label='Image name help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide a file name to be used for the image file that will be uploaded.")
        b.click(".pf-c-popover__content button")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='azure-image-name']")
        b.key_press("give")

        b.wait_visible("label:contains('Storage container')")
        b.click("button[aria-label='Storage container help']")
        # b.wait_text(".pf-c-popover__body",
        #             " Provide the Blob container to which the image file will be uploaded. You can "
        #             "find containers under the Blob service  section of a storage account. You can "
        #             "find storage accounts on the Storage accounts page in the Azure portal. ")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='azure-storage-container']")
        b.key_press("you-up")

        b.click("button:contains('Next')")
        # skip packages and customizations steps
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")

        # Verify Azure Review page
        b.wait_text("h1", "Review")

        b.wait_in_text("#review-list", "Blueprint name")
        b.wait_in_text("#review-list", "httpd-server")
        b.wait_in_text("#review-list", "Output type")
        b.wait_in_text("#review-list", "vhd")
        b.wait_in_text("#review-list", "Image size")
        b.wait_in_text("#review-list", "2")
        with b.wait_timeout(180):
            b.wait_in_text("#review-list", "Packages")
            b.wait_in_text("#review-list", "3")

        b.wait_in_text("#review-list", "Storage account")
        b.wait_in_text("#review-list", "never")
        # key value is hidden
        b.wait_in_text("#review-list", "Storage access key")
        b.wait_in_text("#review-list", "*****")
        b.wait_in_text("#review-list", "Image name")
        b.wait_in_text("#review-list", "give")
        b.wait_in_text("#review-list", "Storage container")
        b.wait_in_text("#review-list", "you-up")

        # Close wizard
        b.click("button:contains('Cancel')")
        b.wait_not_present("#create-image-wizard")

        # collect code coverage result
        self.check_coverage()

    # TODO: verify popover text after string translation
    def testVMWareStep(self):
        b = self.browser

        self.login_and_go("/composer")
        b.wait_visible("#main")

        # create image wizard (no upload support)
        b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
        b.wait_in_text(".pf-c-wizard__main", "httpd-server")
        time.sleep(1)
        # select AWS
        b.select_PF4("#image-output-select-toggle", "VMWare VSphere (.vmdk)")
        # Upload image
        b.wait_visible("label:contains('Upload to VMWare')")
        b.click("#image-upload")

        b.click("button[aria-label='Upload to VMWare help']")
        # b.wait_in_text(".pf-c-popover__body",
        #                " Image Builder can upload images you create to VMWare vSphere. "
        #                "When the image build is complete and the upload action is successful, "
        #                "the image file is available in the Cluster on the vSphere "
        #                "instance that you specified. ")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")

        # Auth page
        b.click("button:contains('Next')")

        b.wait_text("h1", "Authentication")

        b.wait_visible("label:contains('Username')")
        b.focus("input[id='vmware-username']")
        b.key_press("never")

        b.wait_visible("label:contains('Password')")
        b.focus("input[id='vmware-password']")
        b.key_press("gunna")

        # Destination page
        b.click("button:contains('Next')")

        b.wait_text("h1", "Destination")
        b.wait_visible("label:contains('Image name')")
        b.click("button[aria-label='Image name help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide a file name to be used for the image file that will be uploaded.")
        b.click(".pf-c-popover__content button")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='vmware-image-name']")
        b.key_press("give")

        b.wait_visible("label:contains('Host')")
        b.click("button[aria-label='Host help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the url of your VMWare vSphere instance to which the image file will be uploaded.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='vmware-host']")
        b.key_press("you")

        b.wait_visible("label:contains('Cluster')")
        b.click("button[aria-label='Cluster help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the name of the Cluster to which the image file will be uploaded.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='vmware-cluster']")
        b.key_press("up")

        b.wait_visible("label:contains('Datacenter')")
        b.click("button[aria-label='Datacenter help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the name of the Datacenter to which the image file will be uploaded.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='vmware-data-center']")
        b.key_press("never-gunna")

        b.wait_visible("label:contains('Datastore')")
        b.click("button[aria-label='Datastore help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the name of the Datastore to which the image file will be uploaded.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='vmware-data-store']")
        b.key_press("let-you-down")

        b.click("button:contains('Next')")
        # skip packages and customizations steps
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")

        # Verify Azure Review page
        b.wait_text("h1", "Review")

        b.wait_in_text("#review-list", "Blueprint name")
        b.wait_in_text("#review-list", "httpd-server")
        b.wait_in_text("#review-list", "Output type")
        b.wait_in_text("#review-list", "vmdk")
        b.wait_in_text("#review-list", "Image size")
        b.wait_in_text("#review-list", "2")
        with b.wait_timeout(180):
            b.wait_in_text("#review-list", "Packages")
            b.wait_in_text("#review-list", "3")

        b.wait_in_text("#review-list", "Username")
        b.wait_in_text("#review-list", "never")
        # password value is hidden
        b.wait_in_text("#review-list", "Password")
        b.wait_in_text("#review-list", "*****")
        b.wait_in_text("#review-list", "Image name")
        b.wait_in_text("#review-list", "give")
        b.wait_in_text("#review-list", "Host")
        b.wait_in_text("#review-list", "you")
        b.wait_in_text("#review-list", "Cluster")
        b.wait_in_text("#review-list", "up")
        b.wait_in_text("#review-list", "Data center")
        b.wait_in_text("#review-list", "never-gunna")
        b.wait_in_text("#review-list", "Data store")
        b.wait_in_text("#review-list", "let-you-down")

        # Close wizard
        b.click("button:contains('Cancel')")
        b.wait_not_present("#create-image-wizard")

        # collect code coverage result
        self.check_coverage()

    # initially only test edge-commit/fedra-iot-commit so as to verify all fields
    # this image type contains all currently supported ostree settings
    # TODO: verify popover text after string translation
    def testOSTreeStep(self):
        b = self.browser

        self.login_and_go("/composer")
        b.wait_visible("#main")

        # create image wizard (no upload support)
        b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
        b.wait_in_text(".pf-c-wizard__main", "httpd-server")
        time.sleep(1)
        # select ostee image type depending on distro
        distro = os.environ.get("TEST_OS").split('-')[0]
        if (distro == "fedora"):
            image_type_label = "Fedora IoT Commit (.tar)"
            image_type = "fedora-iot-commit"
        else:
            image_type_label = "RHEL for Edge Commit (.tar)"
            image_type = "edge-commit"

        b.select_PF4("#image-output-select-toggle", image_type_label)

        b.click("button:contains('Next')")
        # OSTree settings page
        b.wait_text("h1", "OSTree settings")

        b.wait_visible("label:contains('Repository URL')")
        b.click("button[aria-label='Repository URL help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the URL of the upstream repository. This repository is where the parent OSTree commit will be pulled from.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='ostree-repo-url']")
        b.key_press("127.0. 0.1")

        b.wait_visible("label:contains('Parent')")
        b.click("button[aria-label='Parent help']")
        # b.wait_text(".pf-c-popover__body",
        #             "Provide the name of the branch for the content. If the ref does not already exist it will be created.")        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.set_input_text("input[id='ostree-parent-commit']", "asdf1234")

        b.wait_visible("label:contains('Ref')")
        b.click("button[aria-label='Ref help']")
        # b.wait_text(".pf-c-popover__body",
        #             Provide the name of the branch for the content. If the ref does not already exist it will be created.")
        b.click(".pf-c-popover__content button[aria-label='Close']")
        b.wait_not_present(".pf-c-popover__body")
        b.focus("input[id='ostree-ref']")
        b.key_press("my/ref")
        b.wait_text("#ostree-ref-helper",
                    "Valid characters for ref are letters from a to z, the digits from 0 to 9, "
                    "the hyphen (-), the underscore (_), the period (.), and the forward slash (/). "
                    "A ref must start with a letter, a number, or an underscore. Slashes must also be "
                    "followed by a letter or number.")

        b.click("button:contains('Next')")
        # skip customizations and packages steps
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")

        # Verify AWS Review page
        b.wait_text("h1", "Review")

        b.wait_in_text("#review-list", "Blueprint name")
        b.wait_in_text("#review-list", "httpd-server")
        b.wait_in_text("#review-list", "Output type")
        b.wait_in_text("#review-list", image_type)

        # Close wizard
        b.click("button:contains('Cancel')")
        b.wait_not_present("#create-image-wizard")
        # collect code coverage result
        self.check_coverage()

    def testCustomizationsHostname(self):
        b = self.browser

        distro = os.environ.get("TEST_OS").split('-')[0]
        if (distro == "fedora"):
            image_type_label = "Fedora IoT Commit (.tar)"
        else:
            image_type_label = "RHEL for Edge Commit (.tar)"

        self.login_and_go("/composer", superuser=True)
        b.wait_visible("#main")

        b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
        b.wait_in_text(".pf-c-wizard__main", "httpd-server")
        time.sleep(1)
        # select RHEL Installer
        b.select_PF4("#image-output-select-toggle", image_type_label)

        # go to next page and skip ostree settings
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")

        b.wait_text("h1", "System")
        b.focus("input[id='customizations-hostname']")
        b.key_press("myhost")

        # skip user and packages
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")

        b.click("button:contains('Save blueprint')")
        with b.wait_timeout(120):
            b.click("button:contains('Cancel')")

        b.click("li[data-blueprint=httpd-server] a[href='#/blueprint/httpd-server']")

        b.wait_visible("#input-hostname")
        b.wait_in_text("#input-hostname", "myhost")
        # collect code coverage result
        self.check_coverage()

    def testCustomizationsUser(self):
        b = self.browser

        self.login_and_go("/composer", superuser=True)
        b.wait_visible("#main")

        b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
        b.wait_in_text(".pf-c-wizard__main", "httpd-server")
        time.sleep(1)
        b.select_PF4("#image-output-select-toggle", "QEMU Image (.qcow2)")

        # go to next page and skip details step
        b.click("button:contains('Next')")
        b.click("button:contains('Next')")

        b.wait_text("h1", "Users")

        b.click("button:contains('Add user')")
        b.focus("input[id='customizations-users[0].username']")
        b.key_press("admin")
        b.focus("input[id='customizations-users[0].password']")
        b.key_press("foobar")
        b.focus("textarea[id='customizations-users[0].ssh-key']")
        b.key_press("ssh-rsa key")
        b.click("input[id='customizations-users[0].is-admin']")
        # go to next page and skip packages
        b.click("button:contains('Next')")
        b.wait_text("h1", "Packages")
        b.click("button:contains('Next')")

        b.wait_text("h1", "Review")
        b.click("button:contains('Save blueprint')")
        with b.wait_timeout(120):
            b.click("button:contains('Cancel')")

        # collect code coverage result
        self.check_coverage()

    # RHEL for Edge Simplified Installer (.iso) is currently not supported but this test is for the field
    # @unittest.skipIf(os.environ.get("TEST_OS").split('-')[0] != "rhel", "Does not support RHEL for Edge Installer options")
    # def testCustomizationsInstallerDevice(self):
    #     b = self.browser

    #     self.login_and_go("/composer", superuser=True)
    #     b.wait_visible("#main")

    #     b.click("li[data-blueprint=httpd-server] button[aria-label='Create image']")
    #     b.wait_in_text(".pf-c-wizard__main", "httpd-server")
    #     time.sleep(1)
    #     # select RHEL Installer
    #     b.select_PF4("#image-output-select-toggle", "RHEL for Edge Simplified Installer (.iso)")

    #     # skip ostree settings
    #     b.click("button:contains('Next')")

    #     b.wait_text("h1", "Customizations")
    #     b.focus("#customizations-install-device")
    #     b.key_press("/dev/test")

    #     # go to next page and then skip packages
    #     b.click("button:contains('Next')")
    #     b.click("button:contains('Next')")

    #     b.click("button:contains('Save blueprint')")
    #     b.click(".pf-c-wizard__close")

    #     b.click("li[data-blueprint=httpd-server] a[href='#/blueprint/httpd-server']")

    #     b.wait_visible("#input-install-device")
    #     b.wait_in_text("#input-install-device", "/dev/test")
    #     # collect code coverage result
    #     self.check_coverage()


if __name__ == '__main__':
    testlib.test_main()
