在VPN上运行的HTTPS Web应用程序上使用Selenium



首先,我需要声明我是硒的总初学者。我正在尝试使用硒在Firefox浏览器中测试应用程序。由于安全问题,应用程序仅在VPN上工作。

我的问题发生在以下步骤中;我创建WebDriver并导航到应用程序的启动(登录(页面。我得到了一个"授权请求"弹出窗口。如果我取消弹出窗口,则进入一个页面,该页面"连接不安全"(是HTTPS地址(。通过后,我将失去硒程序应填充用户名和密码的部分,并且仅在登录页面上。

我的问题,是否有一种方法可以在应用程序上启动硒测试,以便在浏览器中已经打开和准备(即登录(?我不满意用户名和密码在硒代码中进行了硬编码。

如果不可能,我如何跳过该授权弹出窗口和非安全连接的问题?如何以最安全的方式填充用户名和密码?谢谢!

public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver", "C:\Selenium-java-3.0.1\geckodriver.exe");
    // I tried also with this code bellow in comment, but it did not work, it did not even get to login page
    //WebDriverWait wait = new WebDriverWait(driver, 10);      
    //Alert alert = wait.until(ExpectedConditions.alertIsPresent());     
    //alert.authenticateUsing(new UserAndPassword("cfadmin", "20lipim18"));
    driver.get("https://Application_login_page.com");
    driver.findElement(By.xpath(".//*[@id='login']")).click();
    driver.findElement(By.xpath("[@id='login']")).sendKeys("Username");

}

如果可能的话,是否可以在浏览器中已经打开和准备(已记录(的应用程序上启动硒测试?

尝试使用Firefox配置文件。因为默认情况下,由于硒打开了浏览器的新鲜实例。您可以使用自己的Firefox果实。

这是实现配置文件的代码,该配置文件可以嵌入硒代码中。

ProfilesIni profile = new ProfilesIni();
// this will create an object for the Firefox profile
FirefoxProfile myprofile = profile.getProfile("default");
// this will Initialize the Firefox driver
WebDriver driver = new FirefoxDriver(myprofile)

它还将维护会话意味着您已经登录到firefox中的应用程序(默认配置文件(。然后,如果执行脚本,您将看到您已经登录到应用程序。

无法打开已经授权的页面,您必须必须通过Selenium脚本传递用户名和密码。

您可以使用以下代码进行身份验证

进行身份验证
WebDriverWait wait = new WebDriverWait(driver, 10);      
Alert alert = wait.until(ExpectedConditions.alertIsPresent());     
alert.authenticateUsing(new UserAndPassword(username, password));

相关内容

最新更新