func (i *Installer) IsInProgressStep() bool {
	count, _ := i.page.FindByClass("grv-installer-progres-indicator").Count()
	return count != 0
}
IsInProgressStep checks if installer is in progress
package installer
import (
	"encoding/json"
	"fmt"
	"github.com/gravitational/robotest/e2e/framework"
	"github.com/gravitational/robotest/e2e/uimodel/defaults"
	"github.com/gravitational/robotest/e2e/uimodel/utils"
	. "github.com/onsi/gomega"
	web "github.com/sclevine/agouti"
	. "github.com/sclevine/agouti/matchers"
	log "github.com/sirupsen/logrus"
)
type Installer struct {
	page *web.Page
}
func Open(page *web.Page, URL string) Installer {
	installer := Installer{page: page}
	installer.navigateTo(URL)
	return installer
}
func (i *Installer) ProcessLicenseStepIfRequired(license string) {
	elems := i.page.FindByClass("grv-license")
	count, _ := elems.Count()
	if count > 0 {
		log.Infof("trying to complete license step")
		Expect(license).NotTo(BeEmpty(), "should have a valid license")
		Expect(elems.SendKeys(license)).To(Succeed())
		Expect(i.page.FindByClass("grv-installer-btn-new-site").Click()).
			To(Succeed(), "should input the license text")
		Eventually(i.page.FindByClass("grv-installer-warning"), defaults.FindTimeout).
			ShouldNot(BeFound(), "should be no warnings")
	}
}
func (i *Installer) InitAWSInstallation(domainName string) {
	log.Infof("trying to initialize AWS install operation")
	Expect(i.IsCreateSiteStep()).To(BeTrue())
	specifyDomainName(i.page, domainName)
	log.Infof("providing AWS keys")
	config := framework.TestContext.AWS
	Expect(i.page.FindByClass("--aws").Click()).To(Succeed())
	Expect(i.page.FindByName("aws_access_key").Fill(config.AccessKey)).To(Succeed())
	Expect(i.page.FindByName("aws_secret_key").Fill(config.SecretKey)).To(Succeed())
	Expect(i.page.FindByClass("grv-installer-btn-new-site").Click()).To(Succeed())
	Eventually(func() bool {
		return utils.IsFound(i.page, ".grv-installer-aws-region") || i.IsWarningVisible()
	}, defaults.AjaxCallTimeout).Should(BeTrue(), "should accept AWS keys")
	Expect(i.IsWarningVisible()).To(BeFalse(), "should be no warnings")
	utils.PauseForComponentJs()
	log.Infof("setting region")
	utils.SetDropdownValue(i.page, "grv-installer-aws-region", config.Region)
	log.Infof("setting key pair")
	utils.SetDropdownValue(i.page, "grv-installer-aws-key-pair", config.KeyPair)
	log.Infof("setting VPC")
	utils.SetDropdownValue(i.page, "grv-installer-aws-vpc", config.VPC)
	i.proceedToReqs()
}
func (i *Installer) InitOnPremInstallation(domainName string) {
	log.Infof("trying to initialize onprem install operation")
	utils.PauseForPageJs()
	Expect(i.IsCreateSiteStep()).To(BeTrue())
	specifyDomainName(i.page, domainName)
	log.Infof("setting provisioner")
	Expect(i.page.FindByClass("--metal").Click()).To(Succeed())
	i.proceedToReqs()
}
func (i *Installer) PrepareOnPremNodes(dockerDevice string) {
	onpremProfiles := i.GetOnPremProfiles()
	Expect(len(onpremProfiles)).NotTo(Equal(0))
	numInstallNodes := 0
	for _, profile := range onpremProfiles {
		numInstallNodes = numInstallNodes + profile.Count
	}
	log.Infof("allocating %v nodes", numInstallNodes)
	provisioner := framework.Cluster.Provisioner()
	Expect(provisioner).NotTo(BeNil(), "expected valid provisioner for onprem installation")
	allocatedNodes, err := provisioner.NodePool().Allocate(numInstallNodes)
	Expect(err).NotTo(HaveOccurred(), "expected to allocate node(s)")
	Expect(allocatedNodes).To(HaveLen(numInstallNodes),
		fmt.Sprintf("expected to allocated %v nodes", numInstallNodes))
	log.Infof("executing the command on servers")
	index := 0
	for _, p := range onpremProfiles {
		nodesForProfile := allocatedNodes[index : index+p.Count]
		framework.RunAgentCommand(p.Command, nodesForProfile...)
		index = index + p.Count
	}
	log.Infof("waiting for agent report with the servers")
	for _, p := range onpremProfiles {
		Eventually(p.GetAgentServers, defaults.AgentServerTimeout).Should(
			HaveLen(p.Count))
	}
	log.Infof("configuring the servers with IPs")
	for _, p := range onpremProfiles {
		agentServers := p.GetAgentServers()
		for _, s := range agentServers {
			s.SetIPByInfra(provisioner)
			if s.NeedsDockerDevice() && dockerDevice != "" {
				s.SetDockerDevice(dockerDevice)
			}
		}
	}
}
func (i *Installer) GetOnPremProfiles() []OnPremProfile {
	log.Info("getting onprem profiles")
	elements, _ := i.page.All(".grv-installer-provision-reqs-item").Elements()
	var profiles = []OnPremProfile{}
	for index := range elements {
		profiles = append(profiles, createProfile(i.page, index))
	}
	return profiles
}
func (i *Installer) GetAWSProfiles() []AWSProfile {
	log.Info("getting AWS profiles")
	var profiles []AWSProfile
	elements, err := i.page.All(".grv-installer-provision-reqs-item").Elements()
	Expect(err).NotTo(HaveOccurred())
	for index := range elements {
		profiles = append(profiles, createAWSProfile(i.page, index))
	}
	return profiles
}
func (i *Installer) ProceedToSite() {
	log.Info("trying to proceed to site")
	Expect(i.page.Find(".grv-installer-progress-result .btn-primary").Click()).To(Succeed())
}
func (i *Installer) StartInstallation() {
	log.Info("clicking on start installation")
	button := i.page.Find(".grv-installer-footer .btn-primary")
	Expect(button).To(BeFound())
	Expect(button.Click()).To(Succeed())
	log.Info("checking if installation has started")
	Eventually(func() bool {
		return i.IsInProgressStep() || i.IsWarningVisible()
	}, defaults.InstallStartTimeout).Should(BeTrue())
	Expect(i.IsInProgressStep()).To(BeTrue(), "should successfully start an installation")
}
func (i *Installer) IsCreateSiteStep() bool {
	log.Infof("checking if on the create new cluster step")
	count, _ := i.page.FindByClass("grv-installer-fqdn").Count()
	return count != 0
}