简体   繁体   English

在一个方法中调用多个方法-Selenium Webdriver跨浏览器测试

[英]calling multiple methods within a method - selenium webdriver cross browser testing

I have a question with regards to calling multiple method using JUNIT. 我有一个关于使用JUNIT调用多重方法的问题。 This is my test 这是我的考验

package com.example.tests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;

public class test {
private WebDriver _driver;

@Test
public void FFconfiguration() throws Exception {
System.out.println("Running FF");
_driver = new FirefoxDriver();
_driver.get("URL");
login();
setup();
_driver.quit();
}

public void login1() 
{
}


public void setup() 
{
}
}

My question is: Can I call both login() and setup() within the method FFConfiguration? 我的问题是:我可以在FFConfiguration方法中同时调用login()和setup()吗? If not what's the alternate solution............... 如果不是,有什么替代解决方案......

Yes, absolutely, you can do it. 是的,绝对可以。 You can have tests like this: 您可以进行如下测试:

 @Test
 public void testBuyingProcess(){
   ShoppingUI shoppingPage = new ShoppingUI();
   shoppingPage.login();
   Assert.assertEquals(shoppingPage.getTitle(),"Welcome");
   //....
 }

And fill in the methods elsewhere even in different class. 并在其他类别中甚至其他地方填写方法。 Few examples of methods used above: 上面使用的方法的几个例子:

public class ShoppingUI{
   private WebDriver driver

   public ShoppingUI(){
     driver = new FirefoxDriver();
     driver.get("http://my-test-site.com/buy-buy-buy.html");
   }

  public String getTitle(){
     return driver.getTitle();
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM