【问题标题】:Selenium: how to set up selenium with web DriverSelenium:如何使用 web 驱动程序设置 selenium
【发布时间】:2019-08-22 18:52:11
【问题描述】:

我不擅长使用 web 驱动程序编写 selenium 测试用例。

请告诉我如何设置我的测试用例。

注意:我不想使用 Selenium IDE。

谢谢

【问题讨论】:

    标签: selenium selenium-webdriver


    【解决方案1】:

    您可以使用 selenium webdriver 从您的代码驱动浏览器。从 firefox 驱动程序开始,因为您不需要对其进行任何设置。对于其他浏览器,如 chrome,您需要设置驱动程序。您可以开始这里:

    http://seleniumhq.org/docs/03_webdriver.html#introducing-the-selenium-webdriver-api-by-example

    HTH

    【讨论】:

    • 是的,谢谢.. 但我不想在 main 方法中编写测试用例.. 我如何配置测试用例以使用 @Test 注释运行。感谢您的帮助
    【解决方案2】:

    自己完成了设置。。谢谢

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {"classpath:testContextWeb.xml"})
    public class SeleniumTest {
    
    WebDriver driver;
    
    @Before
    public void setUp() throws Exception {
        driver = new FirefoxDriver();
    }
    
    @After
    public void tearDown() throws Exception {
        driver.close();
    }
    
    @Test
    public void testCase() throws Exception {
        //open the event page
        driver.get("https://websiteAddress/Context");
    
    
        driver.findElement(By.xpath(".//*[@id='username']")).sendKeys("someUserName");
        driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("xxxx"); // "xxxx" means some password
    
     }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2017-08-15
      相关资源
      最近更新 更多