Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I cannot speak to doing things in C#, however Java is similar enough that from the examples below you should be able to get an idea of how to go about what you need to do.</p> <p>I have a browser class which looks like this:</p> <pre><code>public class Browser { public WebDriver getDriver(String driverName) { WebDriver driver = null; if(driverName == "firefox") { driver = new FirefoxDriver(); } else if(driverName == "chrome") { File chromeFile = new File ("C:/webdrivers/chromedriver.exe"); System.setProperty("webdriver.chrome.driver", chromeFile.getAbsolutePath()); driver = new ChromeDriver(); } else if(driverName == "ie") { File ieFile = new File("C:/webdrivers/IEDriverServer.exe"); System.setProperty("webdriver.ie.driver", ieFile.getAbsolutePath()); driver = new InternetExplorerDriver(); } else if(driverName == "iOS") { try { driver = new RemoteWebDriver(new URL("http://localhost:3001/wd/hub"), DesiredCapabilities.ipad()); } catch (MalformedURLException e) { e.printStackTrace(); } } return driver; } } </code></pre> <p>Then I have one method which calls the browser class. Then my test methods determine which browser I am going to use so it would look something like this:</p> <pre><code>public class EditMedications_Cancel { Browser browser = new Browser(); Random rand = new Random(); HighlightElement highlight = new HighlightElement(); WebDriver driver; private void cancelButton(String driverName) { int min = 1; //minimum random row int max = 5; //maximum random row driver = browser.getDriver(driverName); //get the Browser int rowNum = (rand.nextInt(max - min + 1) + min); //Random row JavascriptExecutor js = (JavascriptExecutor)driver; //Open Browser, navigate to Patient Facing driver.manage().window().maximize(); driver.get("http://someIP.com"); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //Get a random row from the table and click it WebElement randomRow = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum+"]/td")); randomRow.click(); //Get Settings button and Click it int rowNum2 = (rowNum + 1); WebElement medicationName1 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li/h1")); WebElement dosage1 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li[2]/h3")); WebElement howMuch1= driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li[3]/h3")); WebElement reason1 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li[4]/p")); WebElement settingsBtn = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/aside/div/button")); String medicationNameBefore = medicationName1.getText(); String dosageBefore = dosage1.getText(); String howMuchBefore = howMuch1.getText(); String reasonBefore = reason1.getText(); settingsBtn.click(); //Click Edit Button WebElement editBtn = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/aside/div/ul/li/a")); editBtn.click(); //Make Changes and click Cancel WebElement medicationName2 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/form/fieldset/h1")); Select dosage2 = new Select (driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/form/fieldset/label/select"))); WebElement howMuch2 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/form/fieldset/label[2]/input")); WebElement reason2 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/form/fieldset/label[4]/input")); medicationName2.sendKeys("TEST TEST TEST"); dosage2.selectByIndex(2); howMuch2.sendKeys("TEST TEST TEST"); reason2.sendKeys("TEST TEST TEST"); WebElement cancelBtn = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/form/fieldset/div/button[2]")); cancelBtn.click(); WebElement medicationName3 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li/h1")); WebElement dosage3 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li[2]/h3")); WebElement howMuch3= driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li[3]/h3")); WebElement reason3 = driver.findElement(By.xpath("/html/body/div/section/div[3]/div/table/tbody/tr["+rowNum2+"]/td/div/article/section/ul/li[4]/p")); String medicationNameAfter = medicationName3.getText(); String dosageAfter = dosage3.getText(); String howMuchAfter = howMuch3.getText(); String reasonAfter = reason3.getText(); Assert.assertEquals(medicationNameBefore, medicationNameAfter); Assert.assertEquals(dosageBefore, dosageAfter); Assert.assertEquals(howMuchBefore, howMuchAfter); Assert.assertEquals(reasonBefore, reasonAfter); } @Test(groups = {"functionalTests.FF"}) public void test_cancelButton_FF() { cancelButton("firefox"); } @Test(groups = {"functionalTests.iOS"}) public void test_cancelButton_iOS() { cancelButton("iOS"); } @AfterMethod(alwaysRun = true) public void tearDown() { driver.quit(); } } </code></pre> <p>My XML file which launches the tests looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;suite name="Suite" parallel="false"&gt; &lt;test name="Test"&gt; &lt;groups&gt; &lt;run&gt; &lt;include name="functionalTests.FF"/&gt; &lt;exclude name="functionalTests.iOS"/&gt; &lt;/run&gt; &lt;/groups&gt; &lt;classes&gt; &lt;class name="ui_Tests.AddPrescription" /&gt; &lt;class name="ui_Tests.ClickAddMedication"/&gt; &lt;class name="ui_Tests.EditMedications_ValidateItems"/&gt; &lt;class name="ui_Tests.EditMedications_MedicationNameReadOnly"/&gt; &lt;class name="ui_Tests.EditMedications_EditStrengthForm"/&gt; &lt;class name="ui_Tests.EditMedications_HowMuch"/&gt; &lt;class name="ui_Tests.EditMedications_HowOften"/&gt; &lt;class name="ui_Tests.EditMedications_Reason"/&gt; &lt;class name="ui_Tests.EditMedications_Cancel"/&gt; &lt;class name="ui_Tests.ExpandCollapseView"/&gt; &lt;/classes&gt; &lt;/test&gt; &lt;!-- Test --&gt; &lt;/suite&gt; &lt;!-- Suite --&gt; </code></pre> <p>So with the include/exclude I can tell it which browsers to run the tests on. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload