package io.blueocean.ath.pages.classic;

import io.blueocean.ath.WebDriverMixin;
import io.blueocean.ath.JenkinsUser;
import org.apache.log4j.Logger;
import org.junit.Assert;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class LoginPage implements WebDriverMixin {
    @Inject
    JenkinsUser admin;

    Logger logger = Logger.getLogger(LoginPage.class);

    public void open() {
        go("/login");
        Assert.assertEquals("/login", getRelativeUrl());
    }

    public void login() {
        open();
        find("#j_username").sendKeys(admin.username);
        find("input[name=j_password]").sendKeys(admin.password);
        find("//button[contains(text(), 'log')]").click();
        find("//a[contains(@href, 'logout')]").isDisplayed();
        logger.info("Logged in as " + admin.username);
    }
}

@@ -655,16 +655,463 @@
 sword);%0A
+        // JENKINS-50477 introduced a new login screen, which was released in core 2.128.%0A        // This allows us to log in with both login screens - starting with the new style.%0A        if (find(%22input%5Bname=Submit%5D%22).isPresent()) %7B%0A            logger.info(%22Logging in via post-2.128 style log in page%22);%0A            find(%22input%5Bname=Submit%5D%22).click();%0A        %7D else %7B%0A            logger.info(%22Logging in via pre-2.128 style log in page%22);%0A    
         
@@ -1153,32 +1153,43 @@
 g')%5D%22).click();%0A
+        %7D%0A%0A
         find(%22//

Modify LoginPage.login() to work with old and new login screens (#1843)