求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Model Center   模型库  
会员   
 


MBSE从理论方法到工作实践
8月26-27日 北京+线上



大模型核心技术RAG、MCP与智能体实践
8月14-15日 厦门



图数据库与知识图谱
8月28-29日 北京+线上
 
 
  Selenium鏁欑▼
Selenium姒傝堪
Selenium IDE
Selenium IDE涓嬭浇
Selenium IDE 宸ュ叿鐗圭偣
Selenium IDE娴嬭瘯鍒涘缓
Selenium IDE娴嬭瘯
Selenium IDE楠岃瘉鐐
Selenium - IDE妯″紡鍖归厤
Selenium鐢ㄦ埛鎵╁睍
Selenium IDE- 涓嶅悓鐨勬祻瑙堝櫒
Selenium 鐜瀹夎璁剧疆
Selenium RC
Selenium - Selenese鍛戒护
Selenium Webdriver
Selenium瀹氫綅鍣
鏂囨湰妗嗙殑鐩镐簰浣滅敤
鍗曢夋寜閽簰鍔
澶嶉夋浜や簰
涓嬫媺妗嗕氦浜
Synchronization 鍚屾
鎷栨斁
閿洏鎿嶄綔
榧犳爣鎿嶄綔
澶氶夋嫨鎿嶄綔
鏌ユ壘鎵鏈夐摼鎺
Selenium娴嬭瘯璁捐鎶鏈
Selenium椤甸潰瀵硅薄妯″瀷
浣跨敤Excel鏁版嵁椹卞姩
log4j鏃ュ織
寮傚父澶勭悊
澶氭祻瑙堝櫒娴嬭瘯
鎹曟崏灞忓箷鎴浘
鎹曟崏瑙嗛
Selenium TestNG
Selenium缃戞牸
 
 

多浏览器测试
1379 次浏览
7次  

多浏览器测试

用户可以同时执行多个浏览器中的脚本。为了演示,我们将充分利用我们已经采取了Selenium 网格相同的场景。Selenium 网格的例子,我们已经在远程执行脚本,在这里将在本地执行脚本。

即使对于这一点,我们必须确保我们有适当的驱动程序下载。请参考Selenium 网格章下载IE和Chrome浏览器的驱动程序。

示例

我们将在所有浏览器中同时执行%的计算用于演示目的。

package TestNG;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.testng.annotations.*;

public class TestNGClass
{
private WebDriver driver;
private String URL = "http://www.calculator.net";

@Parameters("browser")
@BeforeTest
public void launchapp(String browser)
{

if (browser.equalsIgnoreCase("firefox"))
{
System.out.println(" Executing on FireFox");
driver = new FirefoxDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
else if (browser.equalsIgnoreCase("chrome"))
{
System.out.println(" Executing on CHROME");
System.out.println("Executing on IE");
System.setProperty("webdriver.chrome.driver", "D:chromedriver.exe");
driver = new ChromeDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
else if (browser.equalsIgnoreCase("ie"))
{
System.out.println("Executing on IE");
System.setProperty("webdriver.ie.driver", "D:IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
else
{
throw new IllegalArgumentException("The Browser Type is Undefined");
}
}


@Test
public void calculatepercent()
{
driver.findElement(By.xpath(".//*[@id='menu']/div[3]/a")).click(); // Click on Math Calculators
driver.findElement(By.xpath(".//*[@id='menu']/div[4]/div[3]/a")).click(); // Click on Percent Calculators
driver.findElement(By.id("cpar1")).sendKeys("10"); // Enter value 10 in the first number of the percent Calculator
driver.findElement(By.id("cpar2")).sendKeys("50"); // Enter value 50 in the second number of the percent Calculator
driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr/td[2]/input")).click(); // Click Calculate Button
String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/span/font/b")).getText(); // Get the Result Text based on its xpath
System.out.println(" The Result is " + result); //Print a Log In message to the screen

if(result.equals("5"))
{
System.out.println(" The Result is Pass");
}
else
{
System.out.println(" The Result is Fail");
}
}

@AfterTest
public void closeBrowser()
{
driver.close();
}
}

创建一个XML这将有助于我们在参数设置浏览器的名字,不要忘记提及 parallel="tests"为了同时在所有浏览器中执行。

通过对XML文件进行右键点击执行脚本,然后选择 'Run As' >> 'TestNG' 方式,如下图所示。

输出

所有的浏览器将平行展开,结果将被打印在控制台上。

注:对于我们在IE浏览器执行成功确保复选框“启用保护模式”下的“IE选项中的安全选项卡中选中或未在所有区域中未检查。

TestNG的结果以HTML格式来查看详细的分析。


您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码: 验证码,看不清楚?请点击刷新验证码 必填



1379 次浏览
7次
 捐助