简体   繁体   English

在Selenium Java(CUCUMBER,JUnit)中按方案在Chrome和Firefox之间切换

[英]Change Between Chrome and Firefox per Scenario in Selenium Java ( CUCUMBER , JUnit)

How can i change between browsers when i run a specific scenario in Java? 在Java中运行特定方案时,如何在浏览器之间进行切换?

I already imported the 2 browsers so far i can only open both of them using the code 到目前为止,我已经导入了2个浏览器,我只能使用代码打开两个浏览器

public void accessURL() throws Throwable
{

    Registration_Steps_1.setUp();
    for(String browser : browserDriver)
    {

        driver=Registration_Steps_1.initiateBrowserDriver(browser);
        //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get(baseUrl);    
        super.driver = driver;

    }

}

after that i cannot run the other methods for each of the browsers 之后,我无法为每个浏览器运行其他方法

Do you want to run test on both browser if yes, user testng suite and pass browser parameter from testng suite. 如果要,是否要在两个浏览器上运行测试,请使用用户testng套件并从testng套件传递浏览器参数。

Second approach setup browser type in configuration file read from there and run test on browser as mention in configuration file. 第二种方法是在从配置文件中读取的配置文件中设置浏览器类型,然后在浏览器上运行测试。

the next methods might probably be running by the second browser coming from your browserDriver. 接下来的方法可能由来自browserDriver的第二个浏览器运行。

driver object will be a fresh instance of webdriver interface and will not have any session. 驱动程序对象将是webdriver接口的新实例,并且将没有任何会话。

so, if you want to run a flow involving login with two browsers, it will not be possible as the login session will recorded in the browser with which you logged in. 因此,如果您要运行一个涉及使用两个浏览器登录的流程,将无法进行,因为登录会话将记录在您登录所用的浏览器中。

if it is a general url traversing stuff you can do with two browsers by calling the second browser by instantiating the driver object again in the middle. 如果它是一般的url遍历内容,则可以通过在中间再次实例化驱动程序对象来调用第二个浏览器,从而对两个浏览器进行处理。

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

相关问题 将我的登录场景重用并连接到 Cucumber Java 和 Selenium 中的其他场景 - Reuse and concat my Login Scenario to other Scenarios in Cucumber Java with Selenium Java cucumber Selenium: NullPointerException for scenario.write for the first scenario on before tag - Java cucumber Selenium : NullPointerException for scenario.write for the first scenario on before tag Cucumber Scenario Outline 不适用于 Junit 4.11 和 Cucumber 1.2.5 - Cucumber Scenario Outline not working with Junit 4.11 and Cucumber 1.2.5 Selenium在Chrome和Firefox中均无法在Java中运行 - Selenium not working in Java, both Chrome and Firefox 在 java 中设置 firefox 和 selenium 的 chrome 驱动程序? - Set firefox and chrome driver for selenium in java? JUnit 5(JUnit Jupiter)中的 Cucumber BDD 场景示例功能的等效项是什么? - What is the equivalent of Cucumber BDD scenario examples feature in JUnit 5 (JUnit Jupiter)? 如何使用Cucumber / Selenium / Java比较“方案大纲示例”中的值与“实际”页面上的“实际值” - How to compare value in Examples on Scenario Outline versus the Actual value on the Actual page using Cucumber/Selenium/Java Cucumber 与 Java Selenium 框架 - Cucumber with Java Selenium framework 硒黄瓜爪哇 - Selenium cucumber Java Cucumber + Selenium Java:在测试用例之间保持浏览器打开 - Cucumber + Selenium Java : keep the browser open between test cases
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM