Skip to content

Commit

Permalink
Updated for method uploadFile
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 committed Nov 11, 2023
1 parent 5fface1 commit 3e6a8eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.ndviet.library.TestObject.TestObject;
import org.ndviet.library.webui.driver.TargetFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -68,6 +71,9 @@ public static void scrollToElement(WebDriver driver, TestObject testObject) {
}

public static void uploadFile(WebDriver driver, TestObject testObject, String absolutePath) {
if (TargetFactory.isRemoteTarget()) {
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
}
WebElement element = Waiting.Element.PRESENCE_OF_ELEMENT_LOCATED.waitForElement(driver, testObject, true, -1);
element.sendKeys(absolutePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static WebDriver createInstance(String browser, String target) {
}
}

public static boolean isRemoteTarget() {
String target = ConfigurationManager.getInstance().getValue(SELENIUM_WEB_DRIVER_TARGET);
return Target.valueOf(target.toUpperCase()) == Target.REMOTE;
}

public enum Target {
LOCAL, REMOTE;
}
Expand Down

0 comments on commit 3e6a8eb

Please sign in to comment.