0
複数のドライバーのParentdriverクラスを壊すのに役立ちます。私は疲れてnow.ThisコードがParendriver.javacucumber、selenium、maven、junitでTestNGを使用してクロスブラウザー(マルチブラウザー)テストを実行するにはヘルプが必要
package com.maxreqman.framework;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public abstract class ParentDriver {
public static WebDriver driver;
public WebDriver getDriver() {
if (driver == null) {
System.setProperty("webdriver.chrome.driver",
"ChromeDriver/chromedriver.exe");
ChromeOptions cOptions = new ChromeOptions();
cOptions.addArguments("--start-maximized");
cOptions.addArguments("--disable-web-security");
cOptions.addArguments("--disable-notifications");
cOptions.addArguments("--no-proxy-server");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
cOptions.setExperimentalOption("prefs", prefs);
cOptions.setExperimentalOption("excludeSwitches", Arrays.asList("enable-automation"));
driver = new ChromeDriver(cOptions);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
return driver;
}
}
ParenScenario.java
package com.maxreqman.framework;
import org.openqa.selenium.WebDriver;
import com.maxreqman.pageObject.LogIn;
public class ParentScenario extends ParentDriver {
protected WebDriver driver = getDriver();
public LogIn login;
public void startBrowser() {
login = new LogIn(driver);
}
public void navigateTo() {
driver.navigate().to("http://www.myurl.com");
}
}
を適切にJUnitのようクロームで実行され、
Mavenのです
LogIn_StepDefinition.java
package com.maxreqman.glue; import com.maxinvman.framework.ParentScenario; import cucumber.api.java.Before; import cucumber.api.java.en.And; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; public class LogIn_StepDefinitions extends ParentScenario { @Before public void beforeScenario() throws Throwable { startBrowser(); } @Given("^User is on LogIn page$") public void user_is_on_LogIn_page() throws Throwable { navigateTo(); } @When("^User enters \"([^\"]*)\" into Username field$") public void user_enters_into_Username_field(String UName) throws Throwable { Thread.sleep(2000); login.enterUsername(UName); } @And("^User enters \"([^\"]*)\" into Password field$") public void user_enters_into_Password_field(String Pass) throws Throwable { Thread.sleep(2000); login.enterPassword(Pass); } @And("^User Click LogIn button$") public void user_Click_LogIn_button() throws Throwable { Thread.sleep(2000); login.clickButton(); } }
LogIn.java(のPageObject)
package com.maxreqman.pageObject; import org.junit.Assert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import com.maxinvman.framework.ParentDriver; public class LogIn extends ParentDriver { WebDriver driver = getDriver(); public LogIn(WebDriver driver) { this.driver = driver; } public void enterUsername(String UName) { driver.findElement(By.xpath(".//*[@id='Username']")).sendKeys(UName); } public void enterPassword(String Pass) { driver.findElement(By.xpath(".//*[@id='password']")).sendKeys(Pass); } public void clickButton() { driver.findElement(By.xpath("//*[@id='login']/div[5]/button")).click(); } }
ランナー(JUnitの)
package com.maxreqman.runner; import java.io.File; import org.junit.AfterClass; import org.junit.runner.RunWith; import com.cucumber.listener.Reporter; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import cucumber.api.testng.AbstractTestNGCucumberTests; @RunWith(Cucumber.class) @CucumberOptions( features = "src/test/resources/Feature_All/1A_LoginValidationCheck/", glue = "com.maxreqman.glue", plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}, format = {"json:target/cucumber.json","html:target/A_Features"} ) public class Runner extends AbstractTestNGCucumberTests { @AfterClass public static void setup() { Reporter.loadXMLConfig(new File("src/test/resources/extentreports/extent-config.xml")); Reporter.setSystemInfo("user", System.getProperty("user.name")); Reporter.setSystemInfo("os", "Windows 10 Pro"); Reporter.setTestRunnerOutput("Max Requisition Managment Testing"); } }
のTestNG XML
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Test Suite"> <test name="Test Cases Suite"> <classes> <class name="com.maxreqman.runner.Runner"></class> </classes> </test> </suite>
のpom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cucumber</groupId> <artifactId>MAXRequisitionManagement</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>MaxReqManTesting</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <testFailureIgnore>true</testFailureIgnore> <suiteXmlFiles> <suiteXmlFile>src/test/resources/testng/testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> <plugin> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.7</version> </plugin> <plugin> <groupId>net.masterthought</groupId> <artifactId>maven-cucumber-reporting</artifactId> <version>3.7.0</version> <executions> <execution> <id>execution</id> <phase>verify</phase> <goals> <goal>generate</goal> </goals> <configuration> <projectName>MaxReqMan</projectName> <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory> <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.browserstack</groupId> <artifactId>browserstack-local-java</artifactId> <version>1.0.1</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.10</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-testng</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>3.0.5</version> </dependency> <dependency> <groupId>com.vimalselvam</groupId> <artifactId>cucumber-extentsreport</artifactId> <version>2.0.4</version> </dependency> </dependencies> </project>
1A_LoginValidationCheck.feature
著者:Md.BorhanウディンSarker、
キーワード概要:依頼テストフレームワーク
Feature: User Test LogIn Scenario: Unsuccessful Login with Invalid Username and Valid Password Given User is on LogIn page When User enters "[email protected]" into Username field And User enters "123" into Password field And User Click LogIn button And Login Denied With Alert Message "Invalid Email or Password" Scenario: Unsuccessful Login with Valid Username and Invalid Password Given User is on LogIn page When User enters "[email protected]" into Username field And User enters "123d34593234556" into Password field And User Click LogIn button And Login Denied With Alert Message "Invalid Email or Password" Scenario: Unsuccessful Login with Blank Username and Blank Password Given User is on LogIn page When User enters "" into Username field And User enters "" into Password field And User Click LogIn button And Login Denied With Alert Message "Please enter valid email address" Scenario: Unsuccessful Login with Blank Username and Valid Password Given User is on LogIn page When User enters "" into Username field And User enters "123" into Password field And User Click LogIn button And Login Denied With Alert Message "Please enter valid email address" Scenario: Unsuccessful Login with Valid Username and Blank Password Given User is on LogIn page When User enters "[email protected]" into Username field And User enters "" into Password field And User Click LogIn button And Login Denied With Alert Message "Please enter password" Scenario: Successful Login with Valid Username and Valid Password Given User is on LogIn page When User enters "[email protected]" into Username field And User enters "123" into Password field And User Click LogIn button And User Login Successfully
どこに正確に貼り付けられていますか?あなたが見ているエラーは何ですか?ありがとう – DebanjanB
このプロジェクトは完全に稼動していますが、私は一度に1つのドライバ(chrome/firefox)しか使用できません。私は複数のドライバと並列でこれを実行したい。 Pleaeeはparentdriver.javaクラスを参照してください....あなたは私をmultidriverで実行するように変換するのを助けてくれますか...ありがとう –