簡體   English   中英

使用Firefox和Firefox瀏覽器進行自動化測試

[英]Automated testing using selenium with firefox browser

我下載了以下代碼,並將其用於一些測試,而u =昨天運行了,但是從今天起,代碼停止工作。 我的測試現在失敗了,這是以前從未發生過的。 它拋出錯誤,提示org.openqa.selenium.ElementNotVisibleException:元素當前不可見,因此無法與element進行交互。

package org.openqa.selenium.example;

//import org.openqa.selenium.browserlaunchers.locators.GoogleChromeLocator;

//import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.junit.*;

import static org.junit.Assert.*;

//import org.openqa.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.chrome.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.Select;
//import org.openqa.selenium.net.UrlChecker;

import static org.junit.Assert.assertEquals;


import org.junit.Test;

public class KongaUrlTest 
{

      private WebDriver driver;
      private String baseUrl;
      //private boolean acceptNextAlert = true;
      private StringBuffer verificationErrors = new StringBuffer();

      @Before
      public void setUp() throws Exception 
      {
        driver = new FirefoxDriver();
        baseUrl = "http://www.konga.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }

      @Test
      public void testFirefoxWebdriver() throws Exception 
      {
        driver.get(baseUrl);
        driver.findElement(By.cssSelector("a.vertnavlink > span")).click();
        try 
        {
          assertEquals("Phones & Tablets | Konga Nigeria", driver.getTitle());
          System.out.println(driver.getTitle());
        } 
        catch (Error e) 
        {
          verificationErrors.append(e.toString());
        }
      }

      @After
      public void tearDown() throws Exception 
      {
        System.out.println(driver.getCurrentUrl());
        driver.quit();

      }



}

顯示一個阻止對話框。 Selenium每次打開新瀏覽器並導航到該站點時,都可能會顯示它。 首先關閉該對話框:

driver.get(baseUrl);
try
{
    driver.findElement(By.cssSelector(".fancybox-close")).click();
}
catch { }
driver.findElement(By.cssSelector("a.vertnavlink > span")).click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM