- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在一台机器上运行 ThreadLocal 测试。我使用 @BeforeMethod 中的代码来启动网页。我还尝试过将其单独编写为我的 Base Test 类中的方法,并在 @BeforeMethod 中调用它。
一切似乎都工作正常,除了错误的用户通过错误的测试登录。这很奇怪,因为 Login 方法不在 BaseTest 类中,它是从页面对象调用的(并且它工作正常,除了登录错误的用户进行测试之外)。
在这个例子中,我将问题代码包含在@BeforeMethod中,并且还注释掉了单独的“initialize”方法和方法调用,因此您可以看到我尝试过的两种方法。
public class StackExample {
protected String baseURL;
public String browser;
private static ThreadLocal<WebDriver> threadedDriver = new ThreadLocal<WebDriver>();
@BeforeMethod(alwaysRun = true)
@Parameters({ "browser", "loginType" })
public void setup(String browser, String loginType, Method caller)
throws MalformedURLException, InterruptedException {
WebDriver driver = null;
// Browsers
if (browser.equalsIgnoreCase("Internet Explorer")) {
System.setProperty("webdriver.ie.driver", "C:\\Users\\automation\\Selenium\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
} else if (browser.equalsIgnoreCase("Firefox")) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\automation\\Selenium\\geckodriver.exe");
ProfilesIni firProfiles = new ProfilesIni();
FirefoxProfile wbdrverprofile = firProfiles.getProfile("Webdriver2");
driver = new FirefoxDriver(wbdrverprofile);
} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\automation\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase("MicrosoftEdge")) {
System.setProperty("webdriver.edge.driver", "C:\\Users\\automation\\Selenium\\MicrosoftWebDriver.exe");
driver = new EdgeDriver();
}
setWebDriver(driver);
this.browser = browser;
System.out.println(browser);
// initialize(loginType);
System.out.println(loginType);
if (loginType.equalsIgnoreCase("client"))
ClientReportFactory
.getTest(StringUtils.join("Client Test"), ' ') + " ("
+ browser + ")", "This test is located in class: " + getClass().getName());
else if (loginType.equalsIgnoreCase("advisor"))
AdvisorReportFactory
.getTest(StringUtils.join("Advisor Test"), ' ') + " ("
+ browser + ")", "This test is located in class: " + getClass().getName());
if (loginType.equalsIgnoreCase("client"))
baseURL = "ClientWebsite.example";
else if (loginType.equalsIgnoreCase("advisor"))
baseURL = "AdvisorWebsite.example";
else {
System.out.println("Client or Advisor must be specified in TestNG XML");
}
driver.get(baseURL);
driver.manage().window().maximize();
}
// public void initialize(String loginType) throws InterruptedException {
// if (loginType.equalsIgnoreCase("client"))
// baseURL = "ClientWebsite.example";
// else if (loginType.equalsIgnoreCase("advisor"))
// baseURL = "AdvisorWebsite.example";
// else{
// System.out.println("Client or Advisor must be specified in TestNG XML");
// }
// driver.get(baseURL);
// driver.manage().window().maximize();
//
// }
public static WebDriver getDriver() {
return threadedDriver.get();
}
static void setWebDriver(WebDriver driver) {
threadedDriver.set(driver);
}
@AfterMethod // (alwaysRun = true)
@Parameters({ "loginType" })
public void afterMethod(Method caller, String loginType) {
// Here we are making sure we close the same test we opened.
System.out.println(loginType);
if (loginType.equalsIgnoreCase("client"))
ClientReportFactory
.closeTest(StringUtils.join("Client Test"), ' ') + " ("
+ browser + ")");
else if (loginType.equalsIgnoreCase("advisor"))
AdvisorReportFactory
.closeTest(StringUtils.join("Advisor Test"), ' ') + " ("
+ browser + ")");
getDriver().quit();
threadedDriver.set(null);
}
@AfterSuite
@Parameters({ "loginType" })
public void afterSuite(String loginType) {
if (loginType.equalsIgnoreCase("client"))
ClientReportFactory.closeReport();
else if (loginType.equalsIgnoreCase("advisor"))
AdvisorReportFactory.closeReport();
if (getDriver() != null) {
getDriver().quit();
} else {
System.out.println("Drivers already closed");
}
}
}
这是我的测试方法。他们从页面对象调用实际的 SignIn 方法。我知道这不是问题,因为从页面对象调用的所有其他方法都可以通过正确的测试正常工作。
public class StackExampleTests extends StackExample {
@Test(enabled = true, priority = 0)
public void ClientTest1() throws Exception {
ExtentTest t = ClientReportFactory.getTest();
t.log(LogStatus.INFO, "Client 1 Login for " + browser);
try {
Login objLogin = new Login(getDriver());
String username = "username1";
String password = "password1";
t.log(LogStatus.INFO, "Logging in as user: " + username);
objLogin.SignIn(username, password);
// perform First Client's tests here
} catch (Exception e) {
t.log(LogStatus.WARNING, "Exception found: " + e.getMessage().substring(0, 400)
+ t.addBase64ScreenShot(ClientReportFactory.CaptureScreen(getDriver())));
}
}
@Test(enabled = true, priority = 1)
public void ClientTest2 throws Exception{
ExtentTest t = ClientReportFactory.getTest();
t.log(LogStatus.INFO, "Client 2 Login for " + browser);
try {
Login objLogin = new Login(getDriver());
String username = "username2";
String password = "password2";
t.log(LogStatus.INFO, "Logging in as user: " + username);
objLogin.SignIn(username, password);
// perform Second Client's tests here
} catch (Exception e) {
t.log(LogStatus.WARNING, "Exception found: " + e.getMessage().substring(0, 400)
+ t.addBase64ScreenShot(ClientReportFactory.CaptureScreen(getDriver())));
}
}
}
我认为这个跟踪意味着它正在同一个线程中启动我的所有 3 个测试。但我还没有完全做到
Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 44694
Only local connections are allowed.
Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 12513
Only local connections are allowed.
Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 32651
Only local connections are allowed.
最佳答案
看来您的测试遇到了驾驶员身份危机,WebDriver
本地并行运行时属于它们。
设置ThreadLocal<WebDriver> threadedDriver
, getDriver()
,和setDriver()
不 static
应该可以解决问题。
关于java - 使用 ExtentReports 进行并行 TestNG 测试使用了错误的 @BeforeMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42674355/
我有一个 Selenium/Java 项目,我们正在其中使用 ExtentReports。我们使用 PageFactory 模型,并有一个 BasePageFactory 负责所有测试准备工作。 Be
我正在使用范围报告通过页面对象模型为我的 Selenium 测试生成日志,并且我有单独的页面和测试类。我能够生成范围报告日志,但我的登录页面日志正在重复。我怀疑这是因为所有其他测试都使用了登录名,但我
目前我正在使用 ExtentReport 生成自动化报告。 我使用 ExtentReport 的方式是使用 IReporter 实现在测试结束时生成报告,这很棒。 但是,现在我正在考虑创建一种在执行测
我需要将所有跳过的测试用例添加到我的 ExtentReports 中。我怎样才能实现这个目标? 我在我的BaseTest.java中尝试了以下代码: @AfterMethod public void
当我运行第一类时,结果会添加到报告中,但是当我运行第二类时,报告不会保留第一类的结果 //SimpleReportFactory { package Rapport; import com.relev
我是新来的范围报告。我正在使用 Selenium Webdriver,并希望使用它的范围报告。 但是我的代码无法创建 ExtentReport 对象。 package com.code.draft;
我在调整 ExtentReports 以提供所需的输出时遇到了一些困难。 我有一个带有 TestNG 的简单测试框架,使用 TestBase 类来完成繁重的工作以保持测试简单。我希望以一种简单的方式实
我正在尝试将屏幕截图添加到我的 ExtentReport HTML 文件中,但由于某种原因,图像不存在,即使它确实存在并且控制台显示它正在查看正确的位置(href 是正确的)。 这是最新的试用代码:
有人可以告诉我如何编写结合 Selenium 页面对象模式和 ExtentsReports ( http://extentreports.relevantcodes.com/ ) 的功能性应用程序测试
我正在使用集成在一起的 tesng、extent-report 和 cucumber 构建新的自动化基础设施。使用以下代码。 @CucumberOptions(strict= false,
我正在尝试使用范围报告打印数组列表。但它给了我错误“ExtentTest 类型中的方法 log(LogStatus, Throwable) 不适用于参数 (LogStatus, ArrayList)”
我正在使用 Cucumber 和 TestNG 在移动设备上并行运行测试。下面给出了我的 TestNG 运行器类。 @CucumberOptions( features="src/te
我正在使用放心的库和范围报告进行报告, ValidatableResponse reponseManualLead = given().header("Accept", "application/js
我正在尝试自定义 ExtentReports 4.0.9当我在测试失败后打开报告时,它将屏幕截图显示为非常小的缩略图。如何增加缩略图的大小。 我尝试过extent-config.xml
社区大家好:我在尝试在 Cucumber 中实现范围报告时遇到了一些问题。 执行后我收到此问题: java.lang.IncompatibleClassChangeError: Implementin
我是测试新手,需要使用extentreports报告测试结果, 下面是测试代码: public ExtentReports reports; public ExtentTest logger; pub
我正在一台机器上运行 ThreadLocal 测试。我使用 @BeforeMethod 中的代码来启动网页。我还尝试过将其单独编写为我的 Base Test 类中的方法,并在 @BeforeMetho
我正在尝试使用 TestNG 中的 ExtentReports 准备测试执行报告。下面是我的代码- import org.openqa.selenium.By; import org.openqa.s
我正在寻找一种方法来实现高级范围报告,其中包含基本设置之外的测试步骤和结果数据。 我目前有一个可用的 ExtentReports 报告,并且正在寻找一种使用 ExtentReports (Logger
我有几个字段,我从 HTML 页面解析并添加到我的 report 中: extentTest.log(Status.INFO, String.format( "Add
我是一名优秀的程序员,十分优秀!